kfence_alloc(9)
β¨ 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β astruct kmem_cachewith 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 thans->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
- 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