Skip to main content

Crate numa_shim

Crate numa_shim 

Source
Expand description

numa-shim — dependency-free NUMA detection and binding.

Key selling point: zero C library dependencies.

  • Linux: mbind(2) via raw syscall(2) (no libnuma, no hwloc).
  • Linux node detection: reads /sys/devices/system/node/nodeN/cpumap directly via open/read/close from the C runtime (always present in glibc/musl).
  • Windows: VirtualAllocExNuma for NUMA-preferred reservations; GetCurrentProcessorNumberEx + GetNumaProcessorNodeEx for 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

FlagEffect
vmem-integrationEnables [reserve_on_node], which uses [aligned-vmem] for the reservation step. Windows path uses VirtualAllocExNuma; Linux reserves then calls mbind.

§Platform matrix

Platformcurrent_nodebind_range[reserve_on_node] (feature)
Linux x86_64/aarch64 (non-miri)sched_getcpu + sysfs cpumapmbind(2) via syscallmmap then mbind
Linux other arch (non-miri)sched_getcpu + sysfs cpumapno-opmmap (no mbind)
Windows (non-miri)GetCurrentProcessorNumberExno-op (use reserve_on_node)VirtualAllocExNuma (direct, via Reservation::from_raw_parts)
macOSNoneno-opreserve_aligned (no binding)
miriNoneno-opreserve_aligned (no binding)
otherNoneno-opreserve_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 u32 node index and need a “not available” sentinel.

Functions§

bind_range
Bind the virtual-memory range [base, base + len) to NUMA node node.
current_node
Return the NUMA node id of the calling thread, or None if not determinable.