kmalloc_flex(9)
π kmalloc_flex(9) β from the Kernel API Manual, bestie π
okay so picture this: you're in the kernel, you have a struct with a flexible array member at the end, and you need exactly one of them β sized just right for however many FAM elements you want. that's the whole vibe of kmalloc_flex. it's giving one-stop-shop, no cap. β¨
πΈ SYNOPSIS πΈ
kmalloc_flex (VAR_OR_TYPE , FAM , COUNT , ... );
like, that's it. that's the call. four-ish things and you're done π«Ά
β¨ ARGUMENTS β¨
VAR_OR_TYPEβ the variable or the type you wanna allocate (flex array included, obviously π ). you can hand it a type or a var, either eats.FAMβ the name of the flexible array member on that struct. yes, the one doing all the work at the end of the struct. she's the main character π₯COUNTβ how many flexible-array-member elements you want, fr fr. just the number, bestie....β optional GFP flags for the allocation. and if you don't specify any? it defaults toGFP_KERNELlike a sweetie. no stress π
π RETURN π
on success you get a newly allocated pointer to VAR_OR_TYPE β iconic, slay, allocated. on failure you get NULL, and that's your cue to handle it (don't ignore her π).
β οΈ ngl there's a catch worth knowing: ifFAMhas been annotated with__counted_by, the allocation will immediately fail ifCOUNTis larger than what the type of the struct's counter variable can represent. like it just says no. no graceful degradation, no vibes β straight to fail town π
π¦ SEE ALSO π¦
okay the friend group is large, but they're all icons, so:
Kernel file ./include/linux/slab.h π« plus the whole crew:
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)__alloc_flex(9)kmalloc_obj(9)kmalloc_objs(9)kmalloc_array(9)krealloc_array(9)kcalloc(9)kzalloc(9)kvmalloc_node(9)kvrealloc_node_align(9)kmalloc_size_roundup(9)
and that's the page, bestie π this one comes from ./include/linux and it's dated October 2026 β go forth and allocate responsibly, mwah π
π
π¦ 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