mm/numa_emulation.c
Source file repositories/reference/linux-study-clean/mm/numa_emulation.c
File Facts
- System
- Linux kernel
- Corpus path
mm/numa_emulation.c- Extension
.c- Size
- 16219 bytes
- Lines
- 612
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/errno.hlinux/topology.hlinux/memblock.hlinux/numa_memblks.hasm/numa.hacpi/acpi_numa.h
Detected Declarations
function numa_emu_cmdlinefunction emu_find_memblk_by_nidfunction mem_hole_sizefunction emu_setup_memblkfunction split_nodes_interleavefunction for_each_node_maskfunction find_end_of_nodefunction uniform_sizefunction split_nodes_size_interleave_uniformfunction for_each_node_maskfunction split_nodes_size_interleavefunction setup_emu2phys_nidfunction numa_emulationfunction for_each_node_maskfunction numa_add_cpufunction numa_remove_cpufunction numa_set_cpumaskfunction for_each_online_nodefunction numa_add_cpufunction numa_remove_cpu
Annotated Snippet
for_each_node_mask(i, physnode_mask) {
u64 dma32_end = numa_emu_dma_end();
u64 start, limit, end;
int phys_blk;
phys_blk = emu_find_memblk_by_nid(i, pi);
if (phys_blk < 0) {
node_clear(i, physnode_mask);
continue;
}
start = pi->blk[phys_blk].start;
limit = pi->blk[phys_blk].end;
end = start + size;
if (nid < big)
end += FAKE_NODE_MIN_SIZE;
/*
* Continue to add memory to this fake node if its
* non-reserved memory is less than the per-node size.
*/
while (end - start - mem_hole_size(start, end) < size) {
end += FAKE_NODE_MIN_SIZE;
if (end > limit) {
end = limit;
break;
}
}
/*
* If there won't be at least FAKE_NODE_MIN_SIZE of
* non-reserved memory in ZONE_DMA32 for the next node,
* this one must extend to the boundary.
*/
if (end < dma32_end && dma32_end - end -
mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
end = dma32_end;
/*
* If there won't be enough non-reserved memory for the
* next node, this one must extend to the end of the
* physical node.
*/
if (limit - end - mem_hole_size(end, limit) < size)
end = limit;
ret = emu_setup_memblk(ei, pi, nid++ % nr_nodes,
phys_blk,
min(end, limit) - start);
if (ret < 0)
return ret;
}
}
return 0;
}
/*
* Returns the end address of a node so that there is at least `size' amount of
* non-reserved memory or `max_addr' is reached.
*/
static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size)
{
u64 end = start + size;
while (end - start - mem_hole_size(start, end) < size) {
end += FAKE_NODE_MIN_SIZE;
if (end > max_addr) {
end = max_addr;
break;
}
}
return end;
}
static u64 uniform_size(u64 max_addr, u64 base, u64 hole, int nr_nodes)
{
unsigned long max_pfn = PHYS_PFN(max_addr);
unsigned long base_pfn = PHYS_PFN(base);
unsigned long hole_pfns = PHYS_PFN(hole);
return PFN_PHYS((max_pfn - base_pfn - hole_pfns) / nr_nodes);
}
/*
* Sets up fake nodes of `size' interleaved over physical nodes ranging from
* `addr' to `max_addr'.
*
* Returns node ID of the next node on success or negative error code.
*/
static int __init split_nodes_size_interleave_uniform(struct numa_meminfo *ei,
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/topology.h`, `linux/memblock.h`, `linux/numa_memblks.h`, `asm/numa.h`, `acpi/acpi_numa.h`.
- Detected declarations: `function numa_emu_cmdline`, `function emu_find_memblk_by_nid`, `function mem_hole_size`, `function emu_setup_memblk`, `function split_nodes_interleave`, `function for_each_node_mask`, `function find_end_of_node`, `function uniform_size`, `function split_nodes_size_interleave_uniform`, `function for_each_node_mask`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: source 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.