memblock_alloc_range_nid(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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_NODE for 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