STRUCT KMEM_CACHE_ARGS(9)
π struct kmem_cache_args(9) π
okay bestie, welcome to the Kernel API Manual β this page is all about struct kmem_cache_args, aka the less common arguments you can hand to kmem_cache_create(). it's giving "advanced settings panel" energy π
β¨ NAME β¨
struct kmem_cache_args β the less common arguments for kmem_cache_create() π«Ά
πΈ SYNOPSIS πΈ
struct kmem_cache_args {
unsigned int align;
unsigned int useroffset;
unsigned int usersize;
unsigned int freeptr_offset;
bool use_freeptr_offset;
void (*ctor)(void *);
unsigned int sheaf_capacity;
};
π¦ Members π¦
alignβ the required alignment for the objects β¨0means no specific alignment is requested, ngl very chill of it.useroffsetβ usercopy region offset π0is a totally valid offset, but only whenusersizeis non-0. iykyk.usersizeβ usercopy region size π0means no usercopy region is specified, periodt.freeptr_offsetβ a custom offset for the free pointer in caches that haveSLAB_TYPESAFE_BY_RCUor actorπ₯ so by default,SLAB_TYPESAFE_BY_RCUandctorcaches place the free pointer outside of the object. whichβ¦ can make the object grow in size π cache creators who have a reason to avoid that can specify a custom free pointer offset inside their own data structure, and that's where the free pointer gets placed. for caches withSLAB_TYPESAFE_BY_RCU, the caller must ensure that the free pointer does not overlay fields required to guard against object recycling (peepSLAB_TYPESAFE_BY_RCUfor the deets π). for caches withctor, the caller must ensure that the free pointer does not overlay fields initialized by the constructor. currently, only caches withSLAB_TYPESAFE_BY_RCUorctormay specifyfreeptr_offset. using0as a value forfreeptr_offsetis valid. iffreeptr_offsetis specified,use_freeptr_offsetmust be set true. no cap.use_freeptr_offsetβ whether afreeptr_offsetis used πctorβ a constructor for the objects π the constructor is invoked for each object in a newly allocated slab page. it is the cache user's responsibility to free an object in the same state as after calling the constructor, or to deal appropriately with any differences between a freshly constructed and a reallocated object. main character responsibility, fr fr.NULLmeans no constructor.sheaf_capacityβ enable sheaves of the given capacity for the cache πΎ with a non-zero value, allocations from the cache go through caching arrays called sheaves. each cpu has a main sheaf that's always present, plus a spare sheaf that may be not present. when both become empty, there's an attempt to replace an empty sheaf with a full sheaf from the per-node barn. it's giving organizational queen energy π when no full sheaf is available, and gfp flags allow blocking, a sheaf is allocated and filled from slab(s) using bulk allocation. otherwise the allocation falls back to the normal operation allocating a single object from a slab. analogically, when freeing and both percpu sheaves are full, the barn may replace it with an empty sheaf, unless it's over capacity. in that case a sheaf is bulk freed to slab pages. the sheaves do not enforce NUMA placement of objects, so allocations viakmem_cache_alloc_nodewith a node specified other thanNUMA_NO_NODEwill bypass them π bulk allocation and free operations also try to use the cpu sheaves and barn, but fallback to using slab pages directly. whenslub_debugis enabled for the cache, thesheaf_capacityargument is ignored π0means no sheaves will be created.
π Description π
any uninitialized fields of the structure are interpreted as unused β¨ the exception is freeptr_offset where 0 is a valid value, so use_freeptr_offset must also be set to true in order to interpret the field as used. for useroffset, 0 is also valid, but only with non-0 usersize.
when NULL args is passed to kmem_cache_create, it is equivalent to all fields unused π«Ά
π SEE ALSO π
kernel file ./include/linux/slab.h, plus all these icons: SLAB_HWCACHE_ALIGN(9), SLAB_TYPESAFE_BY_RCU(9), SLAB_ACCOUNT(9), SLAB_RECLAIM_ACCOUNT(9), kmem_cache_create_usercopy(9), kmem_cache_create(9), krealloc_node_align(9), kmem_cache_alloc(9), kmem_cache_charge(9), kmalloc(9), kmalloc_nolock(9), __alloc_objs(9), __alloc_flex(9), kmalloc_obj(9), kmalloc_objs(9), kmalloc_flex(9), kmalloc_array(9), krealloc_array(9), kcalloc(9), kzalloc(9), kvmalloc_node(9), kvrealloc_node_align(9), kmalloc_size_roundup(9) π
π that's the whole page bestie, go forth and cache responsibly π
okay so this came from ./include/linux and it's dated October 2026 β if you're reading struct kmem_cache_args(9) way later, bestie you're iconic for keeping up π§β¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms