Expand description
numa-shim — dependency-free NUMA detection and binding.
Key selling point: zero C library dependencies.
- Linux:
mbind(2)via rawsyscall(2)(no libnuma, no hwloc). - Linux node detection: reads
/sys/devices/system/node/nodeN/cpumapdirectly viaopen/read/closefrom the C runtime (always present in glibc/musl). - Windows:
VirtualAllocExNumafor NUMA-preferred reservations;GetCurrentProcessorNumberEx+GetNumaProcessorNodeExfor detection. - macOS / miri: no-op (no public NUMA API on macOS; miri has no real OS topology).
This is rare in the Rust ecosystem — typical NUMA crates bind to libnuma or
hwloc, pulling in heavy C dependencies. numa-shim has zero non-system
dependencies in its default configuration.
§Usage
use numa_shim::{current_node, NO_NODE};
match current_node() {
Some(node) => println!("Running on NUMA node {node}"),
None => println!("NUMA unavailable or single-node host"),
}§Feature flags
| Flag | Effect |
|---|---|
vmem-integration | Enables [reserve_on_node], which uses [aligned-vmem] for the reservation step. Windows path uses VirtualAllocExNuma; Linux reserves then calls mbind. |
§Platform matrix
| Platform | current_node | bind_range | [reserve_on_node] (feature) |
|---|---|---|---|
| Linux x86_64/aarch64 (non-miri) | sched_getcpu + sysfs cpumap | mbind(2) via syscall | mmap then mbind |
| Linux other arch (non-miri) | sched_getcpu + sysfs cpumap | no-op | mmap (no mbind) |
| Windows (non-miri) | GetCurrentProcessorNumberEx | no-op (use reserve_on_node) | VirtualAllocExNuma (direct, via Reservation::from_raw_parts) |
| macOS | None | no-op | reserve_aligned (no binding) |
| miri | None | no-op | reserve_aligned (no binding) |
| other | None | no-op | reserve_aligned (no binding) |
Constants§
- NO_NODE
- Sentinel value meaning “no NUMA node / feature disabled / unsupported
platform”. This constant is useful when interfacing with APIs that return
a raw
u32node index and need a “not available” sentinel.
Functions§
- bind_
range ⚠ - Bind the virtual-memory range
[base, base + len)to NUMA nodenode. - current_
node - Return the NUMA node id of the calling thread, or
Noneif not determinable.