Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


The meanings of the first three list heads are clear from the explanations in the above sections.
free_objectsindicates the total number of free objects in all slabs ofslabs_partialandslabs_free.


free_touchedindicates whether the cache is active or not. When an object is taken from the cache, the
kernel sets the value of this variable to 1; when the cache is shrunk, the value is reset to 0. However, the
kernel only shrinks a cache iffree_touchedhas been set to 0beforehand, because the value 1 indicates that
another part of the kernel has just taken objects from the cache and thus it is not advisable to shrink it.


This variable applies for the whole cache unlike the per-CPUtouchedelement.

next_reapdefines a time interval that the kernel must allow to elapse between two attempts to shrink
the cache. The idea is to prevent degradation of system performance due to frequent cache shrinking
and growing operations as can happen in certain load situations. This technique is only used on NUMA
systems and will thus not concern us any further.


free_limitspecifies the maximum number of unused objects permitted on all slabs.


The structure is concluded by pointers toarray_cacheinstances that are either shared per node or origi-
nate from other nodes. This is of relevance on NUMA machines but, for the sake of simplicity, this won’t
be discussed in detail.


The third part ofkmem_cachecontains all variables neededto grow (and shrink) the cache.


❑ gfporderspecifies the slab size as a binary logarithm of the number of pages, or, expressed dif-
ferently, the slab comprises 2gfporderpages.
❑ The threecolourelements hold all relevant data for slab coloring.
colourspecifies the maximum number of colors andcolour_nextthe color to use for the
next slab created by the kernel. Note, however, that this value is specified as an element of
kmem_list3.colour_offis the basic offset multiplied by a color value to obtain the absolute
offset. This is again required for NUMA machines — UMA systems could keepcolour_nextin
struct kmem_cache. Placing the next color in a node-specific structure, however, allows coloring
slabs added on the same node sequentially, which is beneficial for the local caches.
Example: If there are five possible colors (0, 1, 2, 3, 4) and the offset unit is 8 bytes, the kernel can
use the following offset values: 0× 8 =0, 1× 8 =8, 2× 8 =16, 3× 8 =24 and 4× 8 =32 bytes.
Section 3.6.4 examines how the kernel determines the possible settings for slab colors. Besides,
note that the kernel sources, in contrast to this book, spellcolourproperly, at least from the British
point of view.
❑ If the slab head is stored outside the slab,slabp_cachepoints to the general cache from which
the required memory is taken. If the slab head is on-slab,slabp_cachecontains a null pointer.
❑ dflagsis a further set of flags that describe the ‘‘dynamic properties‘‘ of the slab, but currently
no flags are defined.
❑ ctoris a pointer to a constructor function that is invoked when objects are created. This method
is well known in object-oriented languages such as C++ and Java. Former kernel versions did
offer the ability to specify an additional destructor function, but since this opportunity was not
used, it has been dropped during the development of kernel 2.6.22.
Free download pdf