Pick a Free OS

User login

Navigation

For Kernel_Newbies By a Kernel_Newbie

memory is allocated,kmem_cache_grow gets the slab management object by calling

kmem_slab_mgmt,and then initialises the objects by calling

kmem_cache_init_objs.Then the pages allocated are linked up in the struct

page.(SET_PAGE_SLAB,SET_PAGE_CACHE variants.) The slab gets added in the cache

list of slabs,and kmem_cache_grow returns.kmem_cache_alloc_one_tail allocates

the object,updates the slabs free object number slot,and adjusts the slabs

bufctl limit. If the slabs bufctl limit hits a peak (BUFCTL_END),then the

firstnotfull pointer is adjusted to point to the next slab, before returning a

pointer to the object. An object is freed from the slab_cache by calling

kmem_cache_free. kmem_cache_free calls kmem_cache_free_one which makes the

objects slot available for reuse,by modifying the slabs free slot.

(slab->free) It is to be noted that kfree and kmalloc call kmem_cache_alloc

and kmem_cache_free respectively to free up the object.In case of kmalloc,a

search is made for the cache pointer corresponding to the size requested, by

looking up the cache_sizes structure. kfree locates the cache pointer from the

Object pointer by looking up the struct page.(GET_PAGE_CACHE),before calling

kmem_cache_free to free up the object.kmem_cache_free apart from freeing up the

object,does some readjustments to the firstnotfull pointer based on whether the

slab was full before the object was freed, or the slab is free after the object

was freed. (Lookout for goto moveslab_partial,moveslab_free.) There is also a

reaper function for the slab cache called when to free up memory,when the memory

gets overburdened. The reaper starts at clock_searchp cache pointer and tries to

find a cache,with the maximum number of free_pages, with an upper limit of

REAP_PERFECT. It examines the slabs of each of the caches, looping till slab in

use (slab->inuse) is found.It optimises out certain conditions based on the

caches with gfp_order > 0,and with a cache_contructor to about 80 percent of

the actual free count.If a cache is found that can be reaped,kmem_slab_destroy

is called on the slabs after reducing the reaping limit to 80 percent of the

slabs, and removing the best_len number of slabs from the caches list of slabs.

kmem_slab_destroy frees up the pages by calling kmem_freepages,thus freeing up

the memory.Have a look at slab.c, as there are many other factors,like a per_cpu