kvmalloc_node(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

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 β€” gfp mask for the allocation β€” must be compatible (superset) with GFP_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


xoxo, your kernel bestie πŸ’œ β€” source/version: ./include/linux, date: October 2026. periodt βœ¨πŸŽ€

πŸ“¦ where this page comes from