[webkit-help] What is the purpose of WTF::OSAllocator and WTF::fastMalloc in Webkit?

Konstantin Tokarev annulen at yandex.ru
Fri Dec 9 06:09:53 PST 2016

09.12.2016, 16:40, "Bono Damodi" <probablynotthebestone at gmail.com>:
> Thanks for the answer. So what was the reason that two allocators are used? I see OSAllocator getting memory from the system for some parts of Webkit using mmap, and the same time I see fastmalloc using tcmalloc to get memory by mmap for other parts of Webkit. What are advantages of one allocator over another in these specific cases?

This question boils down to question why people use anonymous mmap when they have malloc, where OSAllocator is counterpart to mmap. This doesn't have much to do with WebKit. There are 3 major reasons to use mmap:

1) JIT-compiled code must be in executable memory pages in order to be runnable, and you cannot assign execution priviledges with malloc-like API as they are set per page;
2) large continuous memory areas, like JS stack, can be implemented  more efficiently with mmap - you never ever need to copy data when growing, in contrast to realloc
3) sometimes general-purpose allocator just does not work good enough for particular allocation pattern in terms of speed and/or memor fragmentation, e.g. this may be the case for large numbers of same-sized objects, or for huge allocations. Improvement of generic allocator may negate the need for custom allocator, this is the reason why some code is getting ported from OSAllocator to fast(Aligned)Malloc over time

> On Fri, Dec 9, 2016 at 10:31 AM, Konstantin Tokarev <annulen at yandex.ru> wrote:
>> 09.12.2016, 12:28, "fdgfd gfdgfdg" <probablynotthebestone at gmail.com>:
>>> There are two ways webkit gets memory using mmap from the operating system, one is WTF::OSAllocator and the second one is WTF::fastMalloc which seems to rely on tcmalloc to get memory from os. I'm using qt bindings. What is the purpose of each of them ?
>> OSAllocator has Usage enum in the beginning of its declaration, it lists primary cases where OSAllocator is used. Generally speaking, OSAllocator is used for large-sized allocations with sizes comparable to OS memory pages (typically 4K)
>> On the contrary, fastMalloc is used for smaller allocations, it's most common usage is WTF_MAKE_FAST_ALLOCATED macro which declares new and delete operators in a large number of classes, e.g. WebCore::Node.
>>> I'm using qt bindings.
>> You should better switch to [1], it's much closer to the modern WebKit, see [2] for more details.
>> In particular, tcmalloc is not used for a long time, it was superceeded by bmalloc. Since then, some usages of OSAllocator were replaced with bmalloc/fastMalloc
>> [1] https://github.com/annulen/webkit
>> [2] http://qtwebkit.blogspot.com/2016/08/qtwebkit-im-back.html
>>> ,
>>> _______________________________________________
>>> webkit-help mailing list
>>> webkit-help at lists.webkit.org
>>> https://lists.webkit.org/mailman/listinfo/webkit-help
>> --
>> Regards,
>> Konstantin


More information about the webkit-help mailing list