In this section, we very briefly summarize things you have already learned by now. This is intended as a way for you to quickly look up and recollect these key points!
The pros of using the slab allocator (or slab cache) APIs to allocate and free kernel memory are as follows:
- (Very) fast (as it uses pre-cached memory objects).
- A physically contiguous memory chunk is guaranteed.
- Hardware (CPU) cacheline-aligned memory is guaranteed when the SLAB_HWCACHE_ALIGN flag is used when creating the cache. This is the case for kmalloc(), kzalloc(), and so on.
- You can create your own custom slab cache for particular (frequently alloc-ed/freed) objects.
The cons of using the slab allocator (or slab cache) APIs are the following:
- A limited amount of memory can be allocated at a time; typically, just 8 KB directly via the slab interfaces, or up to 4 MB indirectly via the page allocator on most current platforms...