6.1.7 · D4Parallelism & Multicore

Exercises — NUMA architectures

2,044 words9 min readBack to topic

Prerequisites you may want open: 6.1.05-memory-consistencymodels, 6.1.06-multicore-synchronization, 6.2.03-thread-scheduling, 6.3.01-parallel-algorithms.


Level 1 — Recognition

Exercise 1.1

Match each phrase to the correct term: (a) memory access time never depends on location, (b) memory access time depends on location, (c) NUMA with hardware coherence across nodes. Options: UMA / SMP, NUMA, ccNUMA.

Recall Solution
  • (a) → UMA / SMPUniform means one flat cost.
  • (b) → NUMANon-uniform: local fast, remote slow.
  • (c) → ccNUMA — the "cc" is cache-coherent: caches stay in sync automatically across nodes.

Why: the whole subject splits on one question — does distance change the cost? UMA says no, NUMA says yes, ccNUMA says yes and keeps caches honest for you.

Exercise 1.2

A 4-node NUMA machine reports these latencies from node 0: local 85 ns, remote 140 ns. State the NUMA factor for that remote node.

Recall Solution

The NUMA factor is by definition the ratio . A factor of 1.0 would mean "no penalty" (pure UMA). Anything above 1.0 is the cost of walking to a farther shelf.


Level 2 — Application

Exercise 2.1

An application makes 80% of its accesses locally. Local latency is 85 ns, remote is 140 ns. Find the average access time.

Recall Solution

80% local means the remote fraction is . (The formula is written in terms of remote fraction — mix these up and every later problem drifts.) Directly: ns. Both routes agree — the bracket form is just the direct sum factored by .

Exercise 2.2

Using the interleaved mapping , with cache line size bytes and , which node owns byte address ?

Recall Solution

Step 1 — which cache line is this byte in? Divide by the line size and drop the remainder: Step 2 — which node holds line 130? Take it modulo the node count (interleaving cycles across lines): So address 8320 lives on node 2.

Why floor then mod: the floor collapses all 64 bytes of a line to one line number (a whole line lives on one node), and the mod spreads consecutive lines round-robin across nodes for bandwidth.


Level 3 — Analysis

Exercise 3.1

For , compute the speedup over an all-remote baseline at and at . Interpret the gap.

Figure — NUMA architectures
Recall Solution

measures how much faster your mixed workload is compared to the disaster case where every access is remote. At : At : Interpretation: going from 80% local to 95% local only buys more. Look at the curve (figure): it flattens hard near . The final few percent of remote traffic are expensive to remove and give little extra — this is the "last 5%" cost the parent note flagged.

Exercise 3.2

Two threads on different nodes repeatedly write different 4-byte words that happen to sit in the same 64-byte cache line. A local L3 miss costs 30 ns; a 3-hop coherence bounce costs 300 ns. If, once tuned to avoid this, each write would have been a 30 ns local hit, what is the per-write slowdown caused by this false sharing?

Recall Solution

False sharing means the two words are logically independent but share a coherence unit (the line). Every write invalidates the other node's copy, forcing a 3-hop bounce: Why it happens: coherence tracks whole lines, not words. The hardware can't tell the two threads never touch the same bytes — it only sees the same line ping-ponging. Fix: pad each thread's word onto its own cache line (align to 64 bytes) so they land in different coherence units.


Level 4 — Synthesis

Exercise 4.1

You have a workload with ns and . Your budget lets you drive down to at most 100 ns. What is the maximum remote fraction you can tolerate?

Recall Solution

Set the average-time law equal to the budget and solve for : So you may allow up to ≈17.6% remote accesses (≈82.4% local). Any looser and you blow the 100 ns budget.

Why solve for : the design question is inverted — not "given a mix, what's the time?" but "given a time target, what mix is allowed?" Same equation, rearranged. This tells the OS scheduler how aggressive its NUMA placement must be.

Exercise 4.2

In the matrix-multiply example, a NUMA-unaware run gets 12 GB/s; after first-touch + thread pinning it hits 45 GB/s. (a) What is the bandwidth speedup? (b) If the compute needs 90 GB of traffic, how much wall-clock time does each version take, and how much did NUMA tuning save?

Recall Solution

(a) Speedup . (b) Time = data ÷ bandwidth (bandwidth is bytes per second, so dividing gives seconds):

  • Unaware: s
  • Tuned: s
  • Saved: s.

Why first-touch fixed it: the OS allocates a page on the node whose thread first writes it. By making each thread zero its own rows first, we force to live on thread 's node — so every later write is local, and the interconnect stops being the bottleneck.


Level 5 — Mastery

Exercise 5.1

Design target: a 4-node ccNUMA server must keep for its flagship app. Measured . (a) What locality (as a percentage of local accesses) must the software achieve? (b) If profiling shows the app naturally hits only 70% local, name two concrete mechanisms from the parent note that could push it over the line, and argue why each helps.

Recall Solution

(a) Require , i.e. the bracket : So remote fraction must be at most 12.5%, i.e. ≥87.5% local.

(b) From 70% local () we must reach :

  1. First-touch allocation — pages land on the node of the thread that first writes them, so a thread's working set becomes local. Directly converts remote accesses to local ones.
  2. Thread pinning via numactl --cpunodebind --membind — stops the scheduler from migrating a thread away from its data mid-run, which would silently turn local pages remote. Locks in the affinity that first-touch established.

Optionally, range-based address mapping (not interleaved) is what makes first-touch possible, since it lets the OS hand a thread a contiguous local block.

Exercise 5.2

Prove that the speedup formula has a hard ceiling of , and state the value of that attains it. Then, for , give the best possible speedup.

Recall Solution

is largest when its denominator is smallest. The denominator is a straight line in ; since , increasing never decreases it. So the minimum denominator occurs at the smallest , namely (all local): Thus cannot exceed , and equality holds exactly at (perfect locality). For the best possible speedup is .

Why this is the ceiling: the baseline is "all remote." The absolute best you can do is "all local," which is times faster — no tuning can beat physics.


Recall Self-test cloze

The two knobs in the average-time law are ::: the remote fraction and the NUMA factor The maximum possible speedup over all-remote equals ::: , attained at First-touch allocation places a page on the node that ::: first writes to it False sharing ping-pongs because coherence tracks ::: whole cache lines, not individual words