Pick a Free OS

User login

Navigation

For Kernel_Newbies By a Kernel_Newbie

which are used by kmalloc to allocate memory. The maximum order supported is

order 5,and hence the object size is limited to order 5.A cache is created by

calling

kmem_cache_create(\"your_cache\",your_cache_size,your_cache_offset,your_cache_flags,your_constructor,your_destructor).

You should have a look at kmem_cache_t structure to get a glimpse of the slab

cache.When a cache is created by calling, kmem_cache_create, kmem_cache_estimate

is called to compute the number of objects that can fit of the size requested,

starting from order 0.There are several constraints that are followed while

creating a cache.The order is restricted to max_gfporder which is 5,and cannot

exceed this limit. An OFF_SLAB limit needed for getting the bufctls of a slab,is

alternatively computed,which is half of the maximum cache_size.A slab which

contains many objects is represented by a slab_t structure.Each slab contains a

bufctl array,which keeps track of the free object slots per slab.On cache

creation,the cache gets linked in the cache_cache.In order to know the flags

that one can use,take a look at slab.c.One flag thats widely used while creating

a cache,is SLAB_HWCACHE_ALIGN,which aligns the objects on an L1_CACHE_BYTES

boundary.There are other options which can trap NULL references to the

cache,mainly SLAB_POISON,which fills up the POISON_BYTE, and POISON_END,by

leaving a 1 word gap before and after the end of the object.The object size,and

the number of objects estimated by kmem_cache_estimate,are stored in the cache

structure to be used by the slab,when it gets allocated. Per cache,there is a

list of partially free,fully free,and full slabs.The slab that gets selected

during allocation is the firstnotfull slab,which selects the slab to allocate an

object. When an object is allocated from the cache,using

kmem_cache_alloc(your_cache_p,your_flags), __kmem_cache_alloc gets called which

uses kmem_cache_alloc_one to allocate the object.kmem_cache_alloc_one is a

macro,which looks up the firstnotfull slab pointer to see,if there are any

available slabs.If there are available slabs,it calls kmem_cache_alloc_one_tail,

to get the object. If there are no slabs, then a call to kmem_cache_grow is

made,to fetch a single slab to accomodate an object. kmem_cache_grow, tries to

get memory by calling kmem_getpages, which calls

__get_free_pages(flags,cachep->gfp_order), to allocate memory. After the