sparse_mmap, membacking: add NUMA-aware memory allocation and mapping#3554
sparse_mmap, membacking: add NUMA-aware memory allocation and mapping#3554jstarks wants to merge 5 commits into
Conversation
Add cross-platform support for binding memory allocations and file mappings to specific host NUMA nodes. On Linux, this uses mbind(MPOL_BIND) after mmap to set the page allocation policy. On Windows, this passes MemExtendedParameterNumaNode to VirtualAlloc2 and MapViewOfFile3. The new SparseMapping methods (alloc_numa, map_file_numa) take Option<u32> for the NUMA node, falling through to the non-NUMA path when None. This avoids separate code paths at call sites. The NUMA node flows through the full membacking pipeline: RamBackingRequest -> RamBacking -> RegionMappingParams -> MappingParams -> VaMapper, so both private (anonymous) and file-backed (memfd/section) RAM backings get NUMA-bound at the point where pages are actually committed or mapped into the guest memory VA space.
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
There was a problem hiding this comment.
Pull request overview
Adds optional host-NUMA-node binding to sparse memory allocations and file mappings, and threads that parameter through the OpenVMM membacking pipeline so RAM can be committed/mapped with NUMA affinity on both Linux and Windows.
Changes:
- Extend
SparseMappingwith NUMA-aware APIs (alloc_numa,map_file_numa) implemented viambind(MPOL_BIND)on Linux andMEM_EXTENDED_PARAMETERon Windows. - Plumb
Option<u32>NUMA node selection through membacking request/backing/mapping parameters intoVaMapper. - Add basic cross-platform tests covering NUMA node 0 success and invalid-node failure.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| support/sparse_mmap/src/windows.rs | Adds Windows NUMA binding support via extended parameters for VirtualAlloc2 / MapViewOfFile3; adds NUMA-aware mapping/allocation methods. |
| support/sparse_mmap/src/unix.rs | Adds Linux NUMA binding via mbind and exposes NUMA-aware allocation/mapping APIs on Unix. |
| support/sparse_mmap/src/lib.rs | Adds tests for NUMA-aware allocation and file mapping. |
| openvmm/membacking/src/region_manager.rs | Carries NUMA node through region mapping parameters into mapping manager requests. |
| openvmm/membacking/src/memory_manager/mod.rs | Adds host_numa_node to RamBackingRequest/RamBacking and passes it down to mapping/allocation. |
| openvmm/membacking/src/memory_manager/device_memory.rs | Updates region mapping calls to provide the new NUMA field (currently None). |
| openvmm/membacking/src/mapping_manager/va_mapper.rs | Uses NUMA-aware file mapping and passes NUMA selection into private-range allocation. |
| openvmm/membacking/src/mapping_manager/manager.rs | Extends MappingParams with a NUMA node field and updates tests accordingly. |
mebersol
left a comment
There was a problem hiding this comment.
Overall the design is solid — the Option<u32> plumbing avoids forking call sites and the &mut [MEM_EXTENDED_PARAMETER] slice ergonomics on Windows are a nice cleanup. A few items below; I've skipped points the existing bot threads already cover (non-Linux Unix unused numa_node, tracelimit::*_ratelimited! for the page-fault-driven log paths, the 1 << bit literal width, vec! OOM on large node IDs, and the Incompatible with private_memory doc).
mebersol
left a comment
There was a problem hiding this comment.
Two more nits that I left in chat earlier — splitting them out as inline.
Add cross-platform support for binding memory allocations and file mappings to specific host NUMA nodes.
On Linux, this uses mbind(MPOL_BIND) after mmap to set the page allocation policy. On Windows, this passes MemExtendedParameterNumaNode to VirtualAlloc2 and MapViewOfFile3.
The new SparseMapping methods (alloc_numa, map_file_numa) take Option for the NUMA node, falling through to the non-NUMA path when None. This avoids separate code paths at call sites.
The NUMA node flows through the full membacking pipeline: RamBackingRequest -> RamBacking -> RegionMappingParams -> MappingParams -> VaMapper, so both private (anonymous) and file-backed (memfd/section) RAM backings get NUMA-bound at the point where pages are actually committed or mapped into the guest memory VA space.