In this section, we're about to create, use, and subsequently destroy a custom slab cache. At a broad level, we'll be performing the following steps:
- Creating a custom slab cache of a given size with the kmem_cache_create() API. This is often done as part of the init code path of the kernel module (or within the probe method when in a driver).
- Using the slab cache. Here we will do the following:
- Issue the kmem_cache_alloc() API to allocate a single instance of the custom object(s) within your slab cache.
- Use the object.
- Free it back to the cache with the kmem_cache_free() API.
- Destroying the custom slab cache when done with kmem_cache_destroy(). This is often done as part of the cleanup code path of the kernel module (or within the remove/detach/disconnect method when in a driver).
Let's explore each of these APIs in a bit of detail. We start...