Skip to content

Instantly share code, notes, and snippets.

View sam4k's full-sized avatar

sam4k

View GitHub Profile
@sam4k
sam4k / kmem_cache_alignment.md
Last active January 11, 2023 13:42
Kmem Cache Alignment

Kmem Cache Alignment

Understanding alignment, object size and objects per cache for special purposes caches in the SLUB allocator.

Overview

Let's take a look a filp, the special purpose cache for struct file, as an example.

Note: I'm using a 5.4 kernel as that's what I had on hand (newer kernels have like struct slab overlay and stuff)

Additional edit: I've simplified things here, focusing on filp, e.g. additional alignment on size and stuff can happen in calculate_sizes(), typically this is just aligning the size to word boundary (??)