Skip to main content
Definition Website Computer and Technology

Slab Allocator

Subject: Computer and Technology noun /ˈslæb ˈæl.əˌkeɪ.tər/ 1 definition

  1. Definition (noun)

    Entry #350 · Updated

    A Slab Allocator is a memory management mechanism used primarily in operating system kernels and low-latency runtime systems to allocate and recycle frequently used objects efficiently. Rather than carving variable-sized blocks from a general heap or calling a coarse page allocator on every request, it organizes memory into type- or size-specific caches backed by slabs—groups of one or more contiguous memory pages divided into fixed-size object slots. Freed objects are returned directly to their slab's free list rather than unmapped, often preserving pre-initialized structural fields and locks so subsequent allocations complete in constant time with high CPU cache locality. Operating above an underlying page-frame allocator, a slab allocator eliminates external fragmentation and reduces internal fragmentation, though it is scoped to uniform-sized allocations rather than arbitrary, large variable-length buffers.

    Common Forms

    • Classic SLAB: Organizes slabs into explicit full, partial, and empty lists with per-CPU object queues and cache coloring, originating in Solaris and earlier Linux kernels to maximize CPU cache efficiency.

    • SLUB (Unqueued Slab): Eliminates per-CPU queue arrays and standalone slab headers by tracking slab metadata in kernel page descriptors and free pointers inside unallocated slots, serving as the modern Linux default for lower memory overhead and multicore scalability.

    • SLOB (Simple List Of Blocks): Replaces dedicated fixed-size slab caches behind the kernel allocator API with a compact linked-list block allocator across pages, prioritizing a minimal memory footprint for constrained embedded systems.

    • User-Space Slab Allocators: Adapts slab-style size classes and thread-local caches for application heaps—as seen in libumem, jemalloc, and tcmalloc—to reduce lock contention and fragmentation in multithreaded workloads.

    Example

    When a high-throughput Linux kernel module calls kmem_cache_create("pkt_meta", 128, 0, SLAB_HWCACHE_ALIGN, NULL), each incoming packet grabs a cache-aligned 128-byte descriptor from a pre-allocated 4 KiB slab via kmem_cache_alloc() in constant time. Once packet processing completes, kmem_cache_free() returns the 128-byte slot to the slab's free list—inspectable via /proc/slabinfo—avoiding repeated buddy allocator trips and preventing external fragmentation.