memblock_alloc_internal(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– memblock_alloc_internal(9) β€” allocate boot memory block πŸ’–

okay so bestie, welcome to the Kernel API Manual, and buckle up because today we're learning about memblock_alloc_internal, which is genuinely one of those functions that does exactly what it says on the tin: it allocates a boot memory block. iconic behaviour, no notes, we love a self-explanatory name ✨


πŸŽ€ SYNOPSIS πŸŽ€

void * memblock_alloc_internal (phys_addr_t size , phys_addr_t align ,
phys_addr_t min_addr , phys_addr_t max_addr , int nid , bool exact_nid
);

like. look at all those parameters. she's got range πŸ’…


🌸 ARGUMENTS 🌸

  • size β€” the size of the memory block you wanna allocate, in bytes. yes bytes. yes it matters. don't @ me πŸ’–
  • align β€” the alignment of the region and of the block's size. both. at the same time. she's doing the most and honestly? slay.
  • min_addr β€” the lower bound of the memory region you're allocating from (a physical address, iykyk).
  • max_addr β€” the upper bound of the memory region you're allocating from (also a physical address, fr fr).
  • nid β€” the nid of the free area to look for. or like, if you literally don't care which node, you pass NUMA_NO_NODE and vibe 😌
  • exact_nid β€” controls whether the allocation is allowed to fall back to other nodes. so like, the "are we being picky or not" switch πŸ¦‹

✨ DESCRIPTION ✨

so basically here's the tea πŸ“: this function allocates a memory block using memblock_alloc_range_nid, and then it takes the physical address that comes back and converts it to a virtual one. glow-up transformation moment, honestly πŸ”₯

and now for the spicy part 🌢️ β€” the min_addr limit gets dropped if it can't be satisfied, and the allocation will just fall back to memory below min_addr. so like, she tried, she really did, but she's flexible πŸ’€

the other constraints though β€” stuff like node and mirrored memory β€” those get handled again inside memblock_alloc_range_nid. so nothing's slipping through the cracks, bestie. double-checked and everything πŸ‘‘


πŸ’œ RETURN πŸ’œ

  • On success? you get the virtual address of the allocated memory block. πŸ₯³
  • On failure? NULL. 😭 it's giving "we don't have the memory for this rn".

πŸ¦‹ SEE ALSO πŸ¦‹

okay this section is a whole friend group, so let's do roll call 🫢 starting with the source file and the big-picture overview:

that's the whole squad, every single one of them, no cap 🌈


ngl bestie, the min_addr fallback is the one thing to actually remember here β€” she will go below your lower bound if she has to. not a bug, just her being resourceful πŸ’…

and that's the page!! this one came out of ./mm in October 2026, brought to you by the Kernel API Manual β€” mwah, ilysm, go allocate something responsibly πŸ’–πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from