Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


Cache Cache Cache

Slab Slab Slab

Cache Object

Figure 3-44: Components of the slab allocator.

struct
kmem_cache

free

array_
cache

array_
cache

Arrays with pointers
to Slab objects

Slab
Head

Slab
Head

Slab
Head

Page Frames

on- or
off-Slab

full

partial

Figure 3-45: Fine structure of a slab cache.

Besides management data (such as the number of used and free objects or flag registers), the cache struc-
ture includes two elements of special significance:

❑ A pointer to an array in which the last freed objects can be kept for each specific CPU.
❑ Three list heads per memory node under which slabs can be listed. The first list containsfull
slabs, the secondpartially freeslabs, and the thirdfreeslabs.

The cache structure points to an array that contains as many entries as there are CPUs in the system.
Each element is a pointer to a further structure known as anarray cache, which contains the management
data for the particular system CPU (and not for the cache as a whole). The memory area immediately
following the management data contains an array with pointers to as-yet-unused objects in the slabs.

The per-CPU pointers are important to best exploit the CPU caches. The LIFO principle (last in, first out)
is applied when objects are allocated and returned. Thekernel assumes that an object just returned is still
Free download pdf