paper

The Slab Allocator: An Object-Caching Kernel Memory Allocator

  • Authors:

📜 Abstract

This paper presents a comprehensive design overview of the SunOS 5.4 kernel memory allocator. This allocator is based on a set of object-caching primitives that reduce the cost of allocating complex objects by retaining their state between uses. These same primitives prove equally effective for managing stateless memory (e.g. data pages and temporary buffers) because they are space-efficient and fast. The allocator’s object caches respond dynamically to global memory pressure, and employ an object-coloring scheme that improves the system’s overall cache utilization and bus balance. The allocator also has several statistical and debugging features that can detect a wide range of problems throughout the system.

✨ Summary

The paper introduces the slab allocator, a kernel memory-allocation design organized around client-defined caches of reusable objects. Objects retain their initialized state between uses, avoiding repeated construction and destruction costs. The design combines per-cache locking, slab-based storage, freelists, dynamically reclaimed memory, cache coloring, and integrated statistics and debugging mechanisms. Slabs provide constant-time allocation and freeing in common cases, reduce fragmentation by segregating objects by size and lifetime, and simplify reclamation through slab-level reference counts. Measurements on SunOS 5.4 report substantial reductions in object-allocation costs, lower fragmentation than several contemporaneous allocators, and improvements in several system workloads. (jscarleton.github.io)

The work became a foundational reference for kernel object caching. A later USENIX paper by Bonwick and Adams states that the design was initially deployed in Solaris 2.4 and subsequently adopted, in whole or in part, by Linux, FreeBSD, NetBSD, OpenBSD, EROS, and Nemesis; it also describes extensions for per-CPU magazines, general resource allocation through vmem, and user-level allocation through libumem. (usenix.org) Linux documentation explicitly characterizes its slab implementation as heavily based on Bonwick’s original work, with later improvements modeled in part on the magazine-based extensions. (kernel.org) Solaris documentation continues to expose slab-derived object-cache interfaces such as kmem_cache_create() and kmem_cache_alloc(). (smartos.org)