kfence_alloc(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ NAME ✨

kfence_alloc β€” allocate a KFENCE object with a low probability πŸ’–

okay so like welcome to the kfence_alloc(9) page of the Kernel API Manual, bestie 🫢 literally imagine you're just minding your business doing heap allocations and every once in a blue moon KFENCE is like "hey, let me take this one" β€” that's the whole vibe of this function. it allocates a KFENCE object, but with a low probability. slay. ✨


πŸŽ€ SYNOPSIS πŸŽ€

void * kfence_alloc (struct kmem_cache *s , size_t size , gfp_t flags );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • s β€” a struct kmem_cache with object requirements. it's giving "here's the cache energy I need" πŸ’…
  • size β€” the exact size of the object to allocate. and yes, it can be less than s->size, e.g. for kmalloc caches. exact. no cap. 🎯
  • flags β€” GFP flags. pass those flags through, king 🌸

πŸ”₯ RETURN πŸ”₯

  • NULL β€” must proceed with allocating as usual. like okay guess KFENCE didn't pick this one today, carry on bestie πŸ’€
  • non-NULL β€” pointer to a KFENCE object. ohhh we got one, iconic πŸ‘‘

🌈 DESCRIPTION 🌈

kfence_alloc should be inserted into the heap allocation fast path, allowing it to transparently return KFENCE-allocated objects with a low probability using a static branch. the probability is controlled by the kfence.sample_interval boot parameter. it's lowkey serving transparency, highkey doing it via a static branch, and the whole vibe is "you'll never even notice" ✨ the static branch is doing the heavy lifting so the fast path stays fast, and when it hits, boom, KFENCE object. obsessed. πŸ¦‹


πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./include/linux/kfence.h β€” and like the whole friend group is right there: is_kfence_address(9), kfence_alloc_pool_and_metadata(9), kfence_init(9), kfence_shutdown_cache(9), kfence_ksize(9), kfence_object_start(9), __kfence_free(9), kfence_free(9), kfence_handle_page_fault(9), __kfence_obj_info(9). go say hi to all of them fr fr 🫢


okay that's the whole page bestie πŸ’– just so you know, this manual page lives in ./include/linux and it's dated October 2026 β€” yes, we're from the future, and we're still slaying βœ¨πŸ’…πŸŽ€

πŸ“¦ where this page comes from