Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


the alignment factor as long as this is possible for the given object size. As a result, 2, 4,...objects fit into
a cache line instead of a single object.

mm/slab.c
/* 1) arch recommendation: */
if (flags & SLAB_HWCACHE_ALIGN) {
/* Default alignment: as specified by the arch code.
* Except if an object is really small, then squeeze multiple
* objects into one cacheline.
*/
ralign = cache_line_size();
while (size <= ralign/2)
ralign /= 2;
} else {
ralign = BYTES_PER_WORD;
}
...

Sanity checks

Calculate alignment

Allocate cache structure

Determine where to store slab head

Compute cache size iteratively with cache_estimate

Compute colors

Insert cache in cache_chain

kmem_cache_create

calculate_slab_order

enable_cpucache do_tune_cpucache

Figure 3-49: Code flow diagram forkmem_cache_create.

The kernel also takes account of the fact that some architectures require a minimum boundary for
the alignment of data as defined byARCH_SLAB_MINALIGN; the alignment required by users is also
accepted.

mm/slab.c
/* 2) arch mandated alignment */
if (ralign < ARCH_SLAB_MINALIGN) {
ralign = ARCH_SLAB_MINALIGN;
}
/* 3) caller mandated alignment */
if (ralign < align) {
Free download pdf