So, okay, we created a custom slab cache. To make use of it, you must issue the kmem_cache_alloc() API. Its job: given the pointer to a slab cache (which you just created), it allocates a single instance of an object on that slab cache (in fact, this is really how the k[m|z]alloc() APIs work under the hood). Its signature is as follows (of course, remember to always include the <linux/slab.h> header for all slab-based APIs):
void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags);
Let's look at its parameters:
- The first parameter to kmem_cache_alloc() is the pointer to the (custom) cache that we created in the previous step (the pointer being the return value from the kmem_cache_create()API).
- The second parameter is the usual GFP flags to pass along (remember the essential rule: use GFP_KERNEL for normal process-context allocations, else GFP_ATOMIC if in any...