Understanding and using the kernel slab allocator
As seen in the first section of this chapter, Introducing kernel memory allocators, the slab allocator or slab cache is layered above the page allocator (or BSA; refer back to Figure 8.1). The slab allocator justifies its very existence with two primary ideas or purposes:
- Object caching: Here, it serves as a cache of common “objects”; these are the frequently allocated data structures within the Linux kernel. This idea – which we’ll of course expand upon – has the slab cache allocate (and subsequently freeing) these objects on demand, resulting in higher performance.
- Mitigate the high wastage (internal fragmentation) of the page allocator by providing small, conveniently sized caches, of various sizes that are typically fragments of a page.
Let’s now examine these ideas in a more detailed manner.
The object caching idea
Okay, we begin with the first of these...