mm/numa_memblks.c
Source file repositories/reference/linux-study-clean/mm/numa_memblks.c
File Facts
- System
- Linux kernel
- Corpus path
mm/numa_memblks.c- Extension
.c- Size
- 16647 bytes
- Lines
- 597
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/array_size.hlinux/sort.hlinux/printk.hlinux/memblock.hlinux/numa.hlinux/numa_memblks.hasm/numa.h
Detected Declarations
function numa_nodemask_from_meminfofunction numa_reset_distancefunction numa_alloc_distancefunction numa_reset_distancefunction __node_distancefunction numa_add_memblk_tofunction numa_remove_memblk_fromfunction numa_move_tail_memblkfunction numa_add_memblkfunction numa_add_reserved_memblkfunction numa_cleanup_meminfofunction numa_clear_kernel_node_hotplugfunction numa_register_meminfofunction numa_memblks_initfunction cmp_memblkfunction numa_fill_memblksfunction meminfo_to_nidfunction phys_to_target_nodefunction memory_add_physaddr_to_nidexport __node_distanceexport phys_to_target_nodeexport memory_add_physaddr_to_nid
Annotated Snippet
if (bi->end > high) {
numa_add_memblk_to(bi->nid, high, bi->end,
&numa_reserved_meminfo);
bi->end = high;
}
/* and there's no empty block */
if (bi->start >= bi->end)
numa_remove_memblk_from(i--, mi);
}
/* merge neighboring / overlapping entries */
for (i = 0; i < mi->nr_blks; i++) {
struct numa_memblk *bi = &mi->blk[i];
for (j = i + 1; j < mi->nr_blks; j++) {
struct numa_memblk *bj = &mi->blk[j];
u64 start, end;
/*
* See whether there are overlapping blocks. Whine
* about but allow overlaps of the same nid. They
* will be merged below.
*/
if (bi->end > bj->start && bi->start < bj->end) {
if (bi->nid != bj->nid) {
pr_err("node %d [mem %#010Lx-%#010Lx] overlaps with node %d [mem %#010Lx-%#010Lx]\n",
bi->nid, bi->start, bi->end - 1,
bj->nid, bj->start, bj->end - 1);
return -EINVAL;
}
pr_warn("Warning: node %d [mem %#010Lx-%#010Lx] overlaps with itself [mem %#010Lx-%#010Lx]\n",
bi->nid, bi->start, bi->end - 1,
bj->start, bj->end - 1);
}
/*
* Join together blocks on the same node, holes
* between which don't overlap with memory on other
* nodes.
*/
if (bi->nid != bj->nid)
continue;
start = min(bi->start, bj->start);
end = max(bi->end, bj->end);
for (k = 0; k < mi->nr_blks; k++) {
struct numa_memblk *bk = &mi->blk[k];
if (bi->nid == bk->nid)
continue;
if (start < bk->end && end > bk->start)
break;
}
if (k < mi->nr_blks)
continue;
pr_info("NUMA: Node %d [mem %#010Lx-%#010Lx] + [mem %#010Lx-%#010Lx] -> [mem %#010Lx-%#010Lx]\n",
bi->nid, bi->start, bi->end - 1, bj->start,
bj->end - 1, start, end - 1);
bi->start = start;
bi->end = end;
numa_remove_memblk_from(j--, mi);
}
}
/* clear unused ones */
for (i = mi->nr_blks; i < ARRAY_SIZE(mi->blk); i++) {
mi->blk[i].start = mi->blk[i].end = 0;
mi->blk[i].nid = NUMA_NO_NODE;
}
return 0;
}
/*
* Mark all currently memblock-reserved physical memory (which covers the
* kernel's own memory ranges) as hot-unswappable.
*/
static void __init numa_clear_kernel_node_hotplug(void)
{
nodemask_t reserved_nodemask = NODE_MASK_NONE;
struct memblock_region *mb_region;
int i;
/*
* We have to do some preprocessing of memblock regions, to
* make them suitable for reservation.
*
* At this time, all memory regions reserved by memblock are
* used by the kernel, but those regions are not split up
* along node boundaries yet, and don't necessarily have their
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/sort.h`, `linux/printk.h`, `linux/memblock.h`, `linux/numa.h`, `linux/numa_memblks.h`, `asm/numa.h`.
- Detected declarations: `function numa_nodemask_from_meminfo`, `function numa_reset_distance`, `function numa_alloc_distance`, `function numa_reset_distance`, `function __node_distance`, `function numa_add_memblk_to`, `function numa_remove_memblk_from`, `function numa_move_tail_memblk`, `function numa_add_memblk`, `function numa_add_reserved_memblk`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.