kmem_cache_create(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– kmem_cache_create(9) β€” a Kernel API Manual moment πŸ’–

okay bestie, listen up, because this is the kernel API manual page for kmem_cache_create, and honestly she's a little bit of a legend. grab your strawberry drink πŸ“ and let's get into it ✨


🌸 NAME 🌸

kmem_cache_create β€” Create a kmem cache.

like, literally that's the whole job. she makes caches. no cap. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

kmem_cache_create (__name , __object_size , __args , ... );

that's the shape of it, exactly as written, don't come for me about the spaces πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • __name β€” a string, and it's the string that gets used in /proc/slabinfo to identify this cache. so like, it's her name tag at the slab party 🫢
  • __object_size β€” the size of the objects that are gonna be created in this cache. size matters, and this is the size.
  • __args β€” optional arguments, see struct kmem_cache_args. and here's the vibe check: passing NULL means defaults will be used for all the arguments. slay, no config needed πŸ’–
  • ... β€” variable arguments. yes girl, the dots are real πŸŒ€

✨ DESCRIPTION ✨

so here's the tea πŸ”₯ β€” right now this is implemented as a macro using _Generic to call either the new variant of the function or a legacy one. two girlies, one macro, iykyk.

the new variant has 4 parameters:

kmem_cache_create(name, object_size, args, flags)

see __kmem_cache_create_args which implements this. she's the main character doing the actual work behind the scenes πŸ‘‘

the legacy variant has 5 parameters:

kmem_cache_create(name, object_size, align, flags, ctor)

and the align and ctor parameters map to the respective fields of struct kmem_cache_args. cute little mapping moment πŸŽ€


🧚 CONTEXT 🧚

cannot be called within a interrupt, but can be interrupted. okay so: not inside an interrupt, but yes she can get interrupted herself. it's giving "don't text me while i'm asleep but yes you can tap me on the shoulder" 😭


πŸ”₯ RETURN πŸ”₯

a pointer to the cache on success, NULL on failure. that's it, that's the whole mood. success = pointer 🫢, failure = NULL πŸ’€


🌈 SEE ALSO 🌈

kernel file ./include/linux/slab.h β€” go read the source bestie, it's all there πŸ¦‹

that's the whole friend group, go say hi to all of them πŸ’œ


and finally, the lil sign-off πŸŽ€ β€” this page lives over in ./include/linux, it's dated October 2026, and it's kmem_cache_create(9) all the way down. mwah, go build something iconic bestie πŸ’…βœ¨

πŸ“¦ where this page comes from