NUMA placement and remote memory
Connect thread placement, page allocation, and communication patterns without treating locality as a universal speed guarantee.
On this page
The question for today
What you’ll understand
- Distinguish execution affinity from physical page placement.
- Calculate a conditional local/remote latency mixture.
- Evaluate first-touch, interleaving, and replication against a workload's sharing pattern.
A shared address space does not imply that every core reaches every memory location at the same cost. In a nonuniform memory access system, physical memory is associated with nodes, and access paths depend on where work executes relative to those nodes. Placement is therefore a joint problem: binding a thread changes where instructions run, while allocation policy and actual page population determine where its data lives. Track both before diagnosing a remote-memory bottleneck.
Two maps, not one
A CPU-affinity mask restricts where a thread may execute. A memory policy influences eligible nodes and allocation choices for pages. Neither description alone proves the placement of an already populated array. A thread can move after initialization while its pages remain where they were, and an allocation request can reserve virtual addresses without immediately allocating every physical page. Inspect actual page distribution and execution placement rather than assuming the current worker owns nearby memory.
First-touch is a useful shorthand for placement influenced by the thread that first causes physical allocation under a particular policy. It is not an unconditional law. Read faults may map shared zero pages, policies can interleave or bind allocations, and automatic balancing or explicit migration can later change placement. Parallel initialization often helps align ownership with later computation, provided the same workers and partitioning remain relevant. Record the operating-system policy and initialization operations that make the claim true.
Locality and bandwidth can pull differently
Private partitions with frequent reuse may benefit from placing each partition near its owning worker. A shared read-mostly dataset can sometimes be replicated if the memory budget and update contract permit it. A broad streaming workload may instead benefit from distributing allocations across memory controllers, even though some individual accesses are remote. A single local-versus-remote latency number cannot decide these cases because aggregate bandwidth and contention depend on the full placement and access matrix.
Migration also has a cost: bytes must move, mappings may need updates, and caches or translations may be disrupted. For a short-lived task, spending time moving an array may exceed any later savings. Replication creates consistency and freshness questions for mutable data. Compare total job time, capacity use, and communication volume, including initialization and movement when they are part of the real workflow. A steady-state microbenchmark can hide costs that users actually pay.
Test a placement hypothesis
Begin with a topology description, worker affinity, allocation policy, and the observed node distribution of relevant pages. Compare local, remote, and interleaved arrangements with identical useful work and a stable problem size. Separate pointer-chasing latency tests from streaming bandwidth tests because they expose different bottlenecks. On a shared machine, external memory traffic can alter results; repeat and report variability rather than presenting one low sample as a property of the entire topology.
The vectors lab represents one two-dimensional vector using angle and magnitude, with x and y projections. Set a magnitude, predict how changing the angle redistributes the components, and verify their squared sum. This provides a limited accounting analogy for a workload divided between two categories, not a model of NUMA traffic: remote fractions are nonnegative counts, not signed vector components. It cannot infer page placement, latency, bandwidth, or the best policy for a real machine.
Work it through
When would migration repay its cost?
Assume a serialized dependent-load benchmark with local latency 90 ns and remote latency 150 ns. Initially 25% of measured accesses are remote. Moving a private hot region costs 300 microseconds and makes its future accesses local.
For the initial declared mix, calculate 0.75×90+0.25×150=105 ns per access. This weighted mean excludes cache hits and assumes the conditional latencies stay fixed.
For accesses to the moved region that would otherwise be remote, the modeled saving is 150−90=60 ns each. Convert 300 microseconds to 300,000 ns.
Divide 300,000/60=5,000 future formerly remote accesses to break even in this latency-sum model. This denominator applies to the moved region, not to every access in the original 25% mixture.
The arithmetic supports a conditional placement hypothesis. It does not predict the outcome for a bandwidth-bound or highly overlapped application.
The living notebook
Explore the model
Interactive lab · vectors
Two components are an accounting analogy
Adjust a vector's angle and magnitude and predict its x/y projections. This helps discuss decomposing a total, but signed geometric components are not NUMA access fractions and the lab does not model page placement or remote latency.
- x component
- 1.393
- y component
- 0.975
- Magnitude
- 1.7
Playback traces a fixed vector and its projections. Angle and magnitude set the geometry; the moving marker does not change them. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA decomposition is useful only when its quantities and constraints match the real measurement.
Pause & reason
Check your understanding
Your turn
Try it yourself
A serialized test has local accesses averaging 80 ns and remote accesses averaging 140 ns. Its remote fraction falls from one half to one quarter. Calculate the two weighted means and the modeled percentage reduction.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute each mixture before comparing the difference with the original mean.
Compare with the solution
The initial mean is 0.5×80+0.5×140=110 ns. The later mean is 0.75×80+0.25×140=95 ns. The modeled reduction is 15/110, approximately 13.64%. That percentage concerns these stable serialized latency mixtures; it is not a guaranteed application speedup when cache behavior, concurrency, or bandwidth also changes.
Keep the idea
Take it with you
- CPU affinity and physical memory placement need separate evidence.
- First-touch behavior depends on allocation policy and actual page population.
- Evaluate locality alongside bandwidth, migration cost, and data-sharing semantics.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.