Every allocator is a compromise between speed, wasted space and the ability to return memory to the operating system. Two designs sit at opposite ends of that compromise. A buddy allocator manages physical pages in power-of-two blocks, splitting and merging them to satisfy arbitrary sizes. A slab allocator asks for a run of pages once, carves it into fixed-size objects and hands those out without further bookkeeping. One is general and predictable; the other is fast for the workload it was built for and quietly wasteful in ways that only show up after a long uptime.
A buddy allocator wastes up to half of each allocation in internal fragmentation but can coalesce blocks back into large pages, while a slab allocator wastes part of every cache in idle objects and gives the memory back only when the whole cache empties.
Part One: What is being compared
The buddy system starts with a large contiguous block, usually a page or a group of pages. To satisfy a request, it splits the block in half repeatedly until it reaches the smallest power-of-two block that fits. Freed blocks are put on a list by size and merged with their buddy when both halves are free. The algorithm is simple, bounded in time by the logarithm of the number of pages, and it guarantees that adjacent free memory can be reassembled into a large block.
A slab allocator works one level up. It obtains a page-sized or multi-page slab from a lower-level allocator, divides it into objects of a single size and maintains a per-cache free list. Allocating an object is a pointer pop; freeing is a pointer push, with no search and no splitting. Caches are typically per size class and often per CPU, so the common path takes no lock at all. General-purpose allocators layer this idea on top of a page allocator, with size classes spanning small objects and larger requests going straight to pages.
The two are not mutually exclusive: a slab allocator usually uses a buddy allocator underneath to obtain its pages. The comparison is about which layer owns the object and who pays for waste.
Part Two: The arithmetic of waste
Take a request for 70 bytes on a 64-bit system with 16-byte alignment. Size classes typically round this up to 80 bytes. The remaining 10 bytes are internal fragmentation, about 12.5 percent of the allocation. In a pure buddy system the same request would consume a 128-byte block, wasting 58 bytes or 45 percent. With a 1,000-byte request the buddy wastes 24 bytes, which is far better, so the penalty is worst just above a power of two.
In a buddy allocator a 70-byte object occupies a 128-byte block and wastes 45 percent of it, while a slab cache rounded to 80 bytes wastes about 12 percent, but the slab's per-cache residue — half-filled pages holding idle objects — can exceed both numbers after a burst of allocations.
That residue is the slab's hidden cost. Suppose a cache holds 64-byte objects in 4-kilobyte pages, about 62 objects per page. If traffic creates 1,000 objects at peak and then drops to 10 permanently, roughly 16 pages remain populated with 990 free slots. The allocator cannot return those pages because ten objects are still live. Memory that the operating system could use for file cache stays pinned until those ten objects disappear. This is why long-running services show a high-water-mark memory profile that never falls back to the baseline.
Per-CPU caches add another layer. To avoid locks, each core keeps a local supply of objects. On a 32-core machine with 64 size classes and a few dozen objects cached per class per core, the idle inventory can reach hundreds of thousands of objects before any of them are in use. That is a deliberate trade: memory is spent to remove contention from the hot path.
Splitting and merging in the buddy system has its own cost. A request for one page in a 4-megabyte block requires log2(1024) = 10 splits, each updating two list entries. That is cheap in absolute terms but shows up under a workload that frequently alternates between large and small allocations, because the tree of free blocks is constantly rearranged.
Part Three: Where the model breaks
The slab advantage assumes a stable size distribution. A service that creates objects of a fixed shape — network packets, file descriptors, parse nodes — benefits enormously because the cache stays full and the fast path never searches. A service with widely varying sizes pays for many caches, each with its own partially filled pages. The memory profile becomes a sawtooth that follows traffic history rather than current demand.
Fragmentation in the buddy system appears differently. External fragmentation occurs when free pages are scattered so that no sufficiently large contiguous block exists, even though total free memory is adequate. A driver needing a physically contiguous 2-megabyte region can fail after hours of small allocations and frees, while a slab allocator built on the same pages might have avoided the problem by never mixing size classes in the first place.
Large allocations expose the boundary. Requests beyond a page or two bypass small size classes and go to the page allocator directly. At that point the slab's speed advantage disappears and both designs face the same coalescing problem. Tuning the cutoff is a recurring source of performance regressions when an application's object sizes change after a dependency upgrade.
Memory accounting is harder than it looks. A slab page containing one live object and sixty-one free ones is reported as fully allocated by the operating system, so container memory limits and monitoring tools see usage that the application believes is free. Teams often misdiagnose this as a leak and restart processes, which temporarily fixes it by discarding the fragmented high-water state.
Part Four: The later cost
Choosing an allocator is usually not a direct decision. General-purpose allocators already combine size classes, per-CPU caches and a page-level backend, so most applications inherit a hybrid. The choice becomes relevant when writing a kernel module, a database buffer pool, a game engine or a high-frequency trading system, where the application knows its object lifetimes better than a general allocator can.
Instrumentation is the practical tool. Allocation tracers can show the distribution of live sizes, the number of partial slabs and the rate of page returns. Without that data, tuning is guesswork. A common finding is that a small number of size classes account for most of the pinned memory, which can be fixed by changing a data structure rather than an allocator flag.
The failure modes differ under pressure. Buddy systems fail by refusing a large contiguous request; the fix is often to reserve memory at boot or to use smaller mappings. Slab systems fail by growing steadily and never shrinking; the fix is periodic cache draining, shrinking interfaces or redesigning ownership so that objects do not outlive bursts. Both problems are invisible in a short benchmark and obvious after a week in production.
There is also a security dimension. Fixed-size caches make use-after-free exploitation easier because a freed object is immediately recycled into the same slot, which is why hardened allocators add quarantine lists and randomisation. That protection costs memory and speed, and it is another reason the theoretical fast path rarely survives into a shipping system.
Part Five: Outside the team
For the user, allocator behaviour appears as memory creep: an application that starts at 200 megabytes and reaches 1.5 gigabytes after a day of ordinary use, without an obvious leak. Response time may stay fine until the machine starts swapping, at which point the whole experience collapses at once.
For operations, the metric to watch is resident memory at low traffic after a peak, not peak memory itself. A service that returns close to its baseline is healthy; one that holds the peak indefinitely will eventually hit its container limit. Restart policies mask the symptom but not the cause.
A fair comparison fixes the object size distribution, the lifetime pattern and the core count, then measures allocation latency at the ninety-ninth percentile alongside memory returned to the operating system after load drops. Throughput alone hides both failure modes.
Market sizing check
If memory-heavy services keep growing and efficiency pressure pushes teams toward custom allocation strategies, the segment covering runtime tooling, memory profiling and specialised allocators is plausibly $4B to $10B a year by 2030. The swing factor is how much memory cost remains a line item once cloud pricing continues to fall, because cheap memory reduces the incentive to tune it.
These figures are a synthesis of published market ranges and a stated model, not a forecast of any specific vendor.
The comparison that matters
The choice is between an allocator that can always give memory back and one that almost never needs to ask for it. Buddy systems trade internal waste for reclaimability; slab caches trade pinned pages for a hot path that is little more than a pointer pop.
The ranking assumes the lifetime pattern holds. Stable object shapes and steady churn favour slabs; mixed sizes and bursty demand with long idle periods favour a coalescing design.
Choose by the object lifetime you actually have, not the allocation speed you measured in a microbenchmark, because fragmentation is paid after the benchmark ends.
SOL: HCqPmPJM3NVtS6YrmVaTZYnuP8XZ2PFgQZKT94VK1LkS
Creating this takes real effort — thank you for the support.
