Master the fundamental concepts of memory management through this focused micro-challenge.
Slab allocation caches same-sized kernel objects (dentries, inodes) to avoid repeated buddy splits. Linux keeps per-type slabs with embedded free lists carved from contiguous pages.
Each slab tracks:
For example, allocating 128 byte struct file objects from a 4 KB page yields 32 slots per slab with one page fault instead of 32 buddy round trips.
Bonwick's 1994 slab allocator design became Linux's SLAB and SLUB subsystems, where kmem_cache pools serve task_struct, inode, and dentry objects on every fork() and file open across a running kernel. Because slabs reuse memory without re-zeroing it, slab corruption bugs are also a favorite target for kernel exploit writers chaining a single stray write into arbitrary code execution.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will build slab creation, alloc, and free with cache reuse. The task requires demonstrating that repeated alloc/free hits the hot cache without touching the buddy layer after warmup.
Implement slab allocator for fixed-size kernel objects.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github