__alloc_flex(9)
πΈ __alloc_flex β Kernel API Manual β¨
Hiii bestie, welcome to the page for __alloc_flex from the Linux Kernel API Manual π This one's a macro (iykyk) and it's lowkey iconic β it's gonna hand you a struct with a little extra room at the end for your flexible array member. Let's get into it π«Ά
β¨ NAME β¨
__alloc_flex β allocate an object that has a trailing flexible array π
π SYNOPSIS π
__alloc_flex (KMALLOC , GFP , TYPE , FAM , COUNT );
That's the whole vibe. Five things go in, one pointer comes out π
π¦ ARGUMENTS π¦
KMALLOCβ thekmallocwrapper function you wanna use for the allocation, bestie. Pick your fave π«GFPβ the GFP flags for the allocation π± (yes they matter, no you can't skip them)TYPEβ the type of structure you're allocating space for, like the actual struct name ποΈFAMβ the name of the flexible array member inside theTYPEstruct π (the trailing bit, the main character of the tail end)COUNTβ how manyFAMelements you want space for π’ like, how many lil guys are riding along at the end
β RETURN β
You get back a newly allocated pointer to TYPE with COUNT-many trailing FAM elements π
OR you get NULL π β and that happens in two cases, no cap:
- the allocation failed, or
COUNTcannot be represented by the member ofTYPEthat counts theFAMelements (the one annotated via__counted_by) π
So fr fr, always check for NULL. It's giving "trust me bro" if you don't π¨
π₯ SEE ALSO π₯
Kernel file ./include/linux/slab.h β and honestly the whole slab/allocator friend group π«Ά:
SLAB_HWCACHE_ALIGN(9)SLAB_TYPESAFE_BY_RCU(9)SLAB_ACCOUNT(9)SLAB_RECLAIM_ACCOUNT(9)struct kmem_cache_args(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)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)
Okay that's the whole page, you ate that π
β¨ This lil masterpiece lives over in ./include/linux and it's dated October 2026, filed under __alloc_flex(9). Go forth and allocate responsibly, bestie π§π
π¦ 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