Lookaside Caches
A device driver often ends up allocating many objects of the same size, over and over. Given that the kernel already maintains a set of memory pools of objects that are all the same size, why not add some special pools for these high-volume objects? In fact, the kernel does implement this sort of lookaside cache. Device drivers normally do not exhibit the sort of memory behavior that justifies using a lookaside cache, but there can be exceptions; the USB and ISDN drivers in Linux 2.4 use caches.
Linux memory caches have a type of kmem_cache_t and
are created with a call to kmem_cache_create:
kmem_cache_t * kmem_cache_create(const char *name, size_t size,
size_t offset, unsigned long flags,
void (*constructor)(void *, kmem_cache_t *,
unsigned long flags),
void (*destructor)(void *, kmem_cache_t *,
unsigned long flags) );
The function creates a new cache object that can host any number of
memory areas all of the same size, specified by the
size argument. The name
argument is associated with this cache and functions as housekeeping
information usable in tracking problems; usually, it is set to the
name of the type of structure that will be cached. The maximum length
for the name is 20 characters, including the trailing terminator.
The offset is the offset of the first object in the
page; it can be used to ensure a particular alignment for the
allocated objects, but you most likely will use 0 to request the
default value. flags controls how allocation is ...