Memory Allocators 101
jamesgolick.com
jamesgolick.com
http://www.akkadia.org/drepper/cpumemory.pdf
The serialized version is at http://lwn.net/Articles/250967/
* There were compiler flags to generate a version of the stdlib with user-provided mutex functions for an RTOS. I did so, then confirmed (by reading the stdlib's malloc's disassembly) that it never called them!
http://www.cs.cmu.edu/afs/cs/academic/class/15213-f98/doc/ds...
[1] http://dtrace.org/blogs/rm/2012/07/16/per-thread-caching-in-...
Edit: reading more of the linked articles, these benchmarks seem to be running on V8? Which seems to be the only platform that node.js runs on...facepalm. Still confused why V8 would be using standard malloc/free calls.
(Still, thanks for posting the paper - the reaps concept is very nice. I did expect regions to win by more than they did, though. Oh well.)
http://people.freebsd.org/~jasone/jemalloc/bsdcan2006/jemall...
It is not sufficient to measure the time consumed by the allocator code in isolation. Memory layout can have a significant impact on how quickly the rest of the application runs, due to the effects of CPU cache, RAM, and virtual memory paging.
The only definitive measures of allocator performance are attained by measuring the execution time and memory usage of real applications. This poses challenges when qualifying the performance characteristics of allocators. Consider that an allocator might perform very poorly for certain allocation patterns, but if none of the benchmarked applications manifest any such patterns, then the allocator may appear to perform well, despite pathological performance for some work loads. This makes testing with a wide variety of applications important. It also motivates an approach to allocator design that minimizes the number and severity of degenerate edge cases.
I think the problem of memory allocation becomes much more interesting in the context of multithreaded applications. I really like the streamflow paper[0]. For similar implementations that are more widely used nowadays, see hoard[1], jemalloc[2] and tcmalloc[3].
Edit: it turns out one of the authors of streamflow was posting in this tread: https://news.ycombinator.com/item?id=5722049
[0] http://haiocl.googlecode.com/svn-history/r21/trunk/doc/paper...
[2] http://people.freebsd.org/~jasone/jemalloc/bsdcan2006/jemall...
https://en.wikipedia.org/wiki/Buddy_memory_allocation
Unfortunately, the article is not a very good explanation, I remember having seen a drawing of the data structure, but cannot recall from where...
edit:
It turns out that the mentioned jemalloc internally uses buddy lists as well.
The free-list was for small object allocations; it maintained free-lists of different sizes. (Say, the 8 byte free list, the 16 byte free list, the 32 byte free list, etc.) However, I obtained the memory for these lists from a page manager, and that page manager used the buddy system. The relationship here is that the small-object part of the allocation obtained its memory from the page allocator; the page allocator obtained its memory from the operating system. This system allowed me to have the benefits of a free-list (good cache behavior for small objects allocated and used together), but low overall fragmentation and good reuse of the free lists.
Full details are in our paper: http://www.scott-a-s.com/files/ismm06.pdf I have portions of a draft of a more detailed explanation that I never got around to finishing and publishing.
http://channel9.msdn.com/Shows/Going+Deep/Inside-Windows-8-G...