First, of course, let's learn how to create the custom slab cache. The signature of the kmem_cache_create() kernel API is as follows:
#include <linux/slab.h>
struct kmem_cache *kmem_cache_create(const char *name, unsigned int size,
unsigned int align, slab_flags_t flags, void (*ctor)(void *));
The first parameter is the name of the cache - as will be revealed by proc (and hence by other wrapper utilities over proc, such as vmstat(8), slabtop(1), and so on). It usually matches the name of the data structure or object being cached (but does not have to).
The second parameter, size, is really the key one – it's the size in bytes for each object within the new cache. Based on this object size (using a best-fit algorithm), the kernel's slab layer constructs a cache of objects. The actual size of each object within the cache will be (slightly) larger than what's requested, due to three reasons...