kvmalloc_node(9)
okay so bestie, this is kvmalloc_node(9) from the Kernel API Manual, and it's basically the "try the cute contiguous thing first, then have a backup plan" allocator π
β¨
π NAME π
kvmalloc_node β attempt to allocate physically contiguous memory, but upon failure, fall back to non-contiguous (vmalloc) allocation. It's giving "main character tries plan A, then slays with plan B" energy π¦
β¨ SYNOPSIS β¨
void * kvmalloc_node (size_t size , gfp_t flags , int node );
π ARGUMENTS π
sizeβ size of the request. i.e. how much memory you're asking for, bestie.flagsβgfpmask for the allocation β must be compatible (superset) withGFP_KERNEL.nodeβ numa node to allocate from.
πΈ DESCRIPTION πΈ
Okay so important vibe check first: only alignments up to those guaranteed by kmalloc will be honored. Please see Documentation/core-api/memory-allocation.rst for more details. No cap, that doc is the place for the extra lore π
It uses kmalloc to get the memory, but if the allocation fails, then it falls back to the vmalloc allocator. Use kvfree for freeing the memory β that's the matching cleanup bestie, don't forget it π«Ά
GFP_NOWAIT and GFP_ATOMIC are supported. The __GFP_NORETRY modifier is not supported. __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc is preferable to the vmalloc fallback, due to visible performance drawbacks. So likeβ¦ use it with intention, not just because it looked cute in the flag menu ππ₯
β RETURN β
Pointer to the allocated memory, or NULL in case of failure. If you get NULL, that's the allocation saying "not today" π
π SEE ALSO π
Kernel file: ./include/linux/slab.h
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_flex(9)kmalloc_array(9)krealloc_array(9)kcalloc(9)kzalloc(9)kvrealloc_node_align(9)kmalloc_size_roundup(9)
xoxo, your kernel bestie π β source/version: ./include/linux, date: October 2026. periodt β¨π
π¦ 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