Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


if (cachep->colour_off < align)
cachep->colour_off = align;
cachep->colour = left_over/cachep->colour_off;
...

The kernel uses the size of an L1 cache that can be determined using the architecture-specific
cache_line_sizefunction as an offset. It must also be ensured that the offset is a multiple of the
alignment used — otherwise, the alignment effect would be lost.


Table 3-9: Examplary Calculations of theAlignment on 4- and 8-Byte Boundaries


Object sizex Alignmenty ALIGN(x,y)

148


448


588


888


91216


12 12 16


13 16 16


16 16 16


17 20 24


19 20 24


The color of the slab (i.e., the number of potential offset values) is calculated by dividing the
free space on the slab (known as theleft_over) by the color offset (colour_off)withouta
remainder.


For example, on an older IA-32 machine, the kernel produces the following results for
a cache that manages 256-byte objects aligned on the hardware cache withSLABHWCACHE
ALIGN:


❑ 15 objects are managed on a slab (num = 15).
❑ Onepageisused(gfp_order = 0).
❑ There are five possible colors (colour = 5),andanoffsetof32bytesisusedforeachcolor
(colour_off = 32).
❑ Theslabheadisstoredon-slab.
Free download pdf