memblock_alloc_range_nid(9)
π memblock_alloc_range_nid(9) π
okay bestie, so this is a page from the Kernel API Manual β yes, the kernel, we're doing kernel stuff today, put your hair up β and it's about memblock_alloc_range_nid, which allocates a boot memory block. boot memory is the early stuff, before the fancy allocators wake up, so like... the pre-coffee era of memory management ββ¨
πΈ NAME πΈ
memblock_alloc_range_nid β allocate boot memory block π
β¨ SYNOPSIS β¨
phys_addr_t memblock_alloc_range_nid (phys_addr_t size , phys_addr_t
align , phys_addr_t start , phys_addr_t end , int nid , bool exact_nid
);
like, that's the whole signature, no cap. returns a phys_addr_t and takes six things π
π«Ά ARGUMENTS π«Ά
sizeβ size of memory block to be allocated in bytes. yes bytes. the unit of choice πalignβ alignment of the region and the block's size. both. it's giving "alignment of the region and block's size," literally what it says β¨startβ the lower bound of the memory region to allocate (phys address). the floor π¦endβ the upper bound of the memory region to allocate (phys address). the ceiling πnidβ nid of the free area to find,NUMA_NO_NODEfor any node. "idk just put it anywhere" energy πexact_nidβ control the allocation fall back to other nodes. it's the switch that decides whether we're being picky or not π
π DESCRIPTION π
The allocation is performed from memory region limited by memblock.current_limit if end == MEMBLOCK_ALLOC_ACCESSIBLE. so like, that's the special value, don't forget it π
If the specified node can not hold the requested memory and exact_nid is false, the allocation falls back to any node in the system. flexible. accommodating. a queen who knows when to compromise π
For systems with memory mirroring, the allocation is attempted first from the regions with mirroring enabled and then retried from any memory region. mirror first, then whatever, iykyk πͺβ¨
In addition, function using kmemleak_alloc_phys for allocated boot memory block, it is never reported as leaks. so the memory leak detector just... minds its business? iconic behaviour honestly π₯
β RETURN β
Physical address of allocated memory block on success, 0 on failure. that's it, that's the return. zero means nope π
π¦ SEE ALSO π¦
the whole friend group, ok buckle up π«Ά:
Kernel file ./mm/memblock.c memblock 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_phys_alloc_range(9), memblock_phys_alloc_try_nid(9), memblock_alloc_internal(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).
like. that's 40-something cross-references. we read them all. we don't skip. periodt ππ
ngl bestie, this lives in ./mm and it's dated October 2026, so write that in your notes and go slay your memory allocation ππ
β¨
ok bye ily, go allocate 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