Chapter3:MemoryManagement
The meanings ofbatchcountandlimitare as given above. The values ofkmem_cache_s
are applied (normally unchanged) as defaults for the per-CPU values used for cache refill or
emptying.
availholds the number of elements currently available.touchedis set to 1 when an element is removed
from the cache, whereas cache shrinking causestouchedto be set to 0. This enables the kernel to establish
whether a cache has been accessed since it was last shrunk and is an indicator of the importance of the
cache. The last element is a dummy array without an entry to facilitate access to the cache elements
following eacharray_cacheinstance in memory.
The third and fourth parts ofkmem_cachecontain all the variables needed to manage the slabs and are
required when the per-CPU caches are filled or emptied.
❑ nodelistsis an array that contains an entry for each possible node in the system. Each entry
holds an instance ofstruct kmem_list3that groups the three slab lists (full, free, partially free)
together in a separate structure discussed below.
The element must be placed at the end of the structure. While it formally always has
MAX_NUMNODESentries, it is possible that fewer nodes are usable on NUMA machines. The array
thus requires fewer entries, and the kernel can achieve this at run time by simply allocating less
memory than the array formally requires. This would not be possible ifnodelistswere placed
in the middle of the structure.
On UMA machines, this is not much of a concern because only a single node will ever be
available.
❑ flagsis a flag register to define the global properties of the cache. Currently, there is only one
flag bit.CFLGS_OFF_SLABis set when the management structure is stored outside the slab.
❑ objsizeis the size of the objects in the cache, including all fill bytes added for alignment
purposes.
❑ numholds the maximum number of objects that fit into a slab.
❑ free_limitspecifies the upper limit of free objects in a cache after it has been shrunk (if there is
no reason to shrink the cache during normal operation, the number of free objects may exceed
this value).
The list heads to manage the slab lists are kept in a separate data structure defined as follows:
mm/slab.c
struct kmem_list3 {
struct list_head slabs_partial; /* partial list first, better asm code */
struct list_head slabs_full;
struct list_head slabs_free;
unsigned long free_objects;
unsigned int free_limit;
unsigned int colour_next; /* Per-node cache coloring */
spinlock_t list_lock;
struct array_cache *shared; /* shared per node */
struct array_cache **alien; /* on other nodes */
unsigned long next_reap; /* updated without locking */
int free_touched; /* updated without locking */
};