Caveats when using the slab allocator
We will split up this discussion into three parts. We will first re-examine some necessary background (which we covered earlier), then actually flesh out the problem that we’re getting at with two use cases – the first being very simple; the second being a more real-world case of the issue at hand.
Background details and conclusions
So far, you have learned some key points:
- The page (or buddy system) allocator allocates pages to the caller in powers of 2 pages; in other words, the granularity of an allocation request is a page (typically 4K). The power to raise 2 is called the order; it typically ranges from
0
to10
(on both x86[_64] and ARM[_64], assuming a page size of 4K andMAX_ORDER
of 11). - This is fine, except when it’s not. When the amount of memory requested is very small, or just over a certain threshold, the wastage (or internal fragmentation) can be huge.
- In the day-to-day operation...