This compares malloc implementations and arena-based allocator architecture, arguing that heap allocation is a common scalability bottleneck in multithreaded programs and should be minimized when possible. It traces frontend evolution from simple free lists and size-class bucket heaps through owner encoding, core-local and thread-local allocation buffers (CLABs/TLABs), epoch encoding, large-object mmap, and hazard pointers, and then describes backend strategies that return memory to the OS: buddy/binary-buddy, span/BIPOP tables, segment and multi-core distributed queues, and k-FIFO. The arena concept (per-CPU/core or NUMA-tied pools) is presented as a key advancement to reduce cross-thread contention and manage different memory types and NUMA domains. Practical notes include avoiding per-packet malloc, using in-driver buffering like PF_RING, and using OS madvise/early return to control RSS.
A head-to-head comparison summarizes thread-safety, per-thread caches, multi-arena support, lock-free fast paths, NUMA awareness, fragmentation control, atomic/CAS costs, and benchmarked throughput/latency. jemalloc, mimalloc, tcmalloc, and snmalloc stand out for different workloads: jemalloc for highly contended multithreaded and mixed-size allocations, mimalloc for low-latency and small-object predictability, tcmalloc for tiny-object throughput, and snmalloc for NUMA-first, security- and scalability-focused servers. glibc/ptmalloc remain safe defaults but suffer arena-lock contention; dlmalloc suits single-threaded/embedded use. A decision supertree and concrete workload-driven recommendations guide allocator selection.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.