memblock_alloc_internal(9)
π 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β thenidof the free area to look for. or like, if you literally don't care which node, you passNUMA_NO_NODEand 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:
- Kernel file
./mm/memblock.cmemblock overview(9) __memblock_find_range_bottom_up(9)__memblock_find_range_top_down(9)memblock_find_in_range_node(9)memblock_find_in_range(9)memblock_discard(9)memblock_double_array(9)memblock_merge_regions(9)memblock_insert_region(9)memblock_add_range(9)memblock_add_node(9)memblock_add(9)memblock_validate_numa_coverage(9)memblock_isolate_range(9)memblock_free(9)memblock_phys_free(9)memblock_setclr_flag(9)memblock_mark_hotplug(9)memblock_clear_hotplug(9)memblock_mark_mirror(9)memblock_mark_nomap(9)memblock_clear_nomap(9)memblock_reserved_mark_noinit(9)memblock_reserved_mark_kern(9)memblock_mark_kho_scratch(9)memblock_clear_kho_scratch(9)__next_mem_range(9)__next_mem_range_rev(9)memblock_set_node(9)memblock_alloc_range_nid(9)memblock_phys_alloc_range(9)memblock_phys_alloc_try_nid(9)memblock_alloc_exact_nid_raw(9)memblock_alloc_try_nid_raw(9)memblock_alloc_hugetlb(9)memblock_alloc_try_nid(9)__memblock_alloc_or_panic(9)memblock_estimated_nr_free_pages(9)memblock_is_region_memory(9)memblock_is_region_reserved(9)memblock_free_all(9)reserve_mem_find_by_name(9)reserve_mem_release_by_name(9)
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
- 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