Figure 345 Fine structure of a slab cache

Besides management data (such as the number of used and free objects or flag registers), the cache structure 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 contains full slabs, the second partially free slabs, and the third free slabs.

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 an array 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. The kernel assumes that an object just returned is still in the cache and allocates it again as quickly as possible (in response to the next request). Only when the per-CPU caches are empty are free objects from the slabs used to refill them.

This results in a three-level hierarchy for object allocation within which both the allocation cost and the negative impact of the operation on caches and TLBs rise from level to level:

1. Per-CPU objects in the CPU cache.

2. Unused objects from an existing slab.

3. Unused objects from a new slab just reserved using the buddy system.

Continue reading here: Fine Structure of Slabs

Was this article helpful?

0 0