Log inStart free
LESSON 1.16 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

CPU affinity and NUMA

Pin workers to CPUs, place their memory, and see which reads cross nodes.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 1.16 · NUMA BAY2 NODES · 4 CPUS · DISTANCE 10 / 21
01
Stage 1 of 5 · Two nodes
This machine has 2 NUMA nodes. Each node has 2 CPUs and its own memory.
Explain it simply

Big servers have two or more CPU sockets. Each socket has its own CPUs and its own memory, and together they make a node. A CPU reads its own node's memory fastest. A read from the other node crosses the link between them, so it takes about twice as long.

Node 0 holds CPU 0, CPU 1 and memory 0. Node 1 holds CPU 2, CPU 3 and memory 1. Main runs on CPU 0. The distance is 10 inside a node and 21 between the nodes.

page, page readaffinity mask, distanceremote read, extra timewaits for its CPUworker, run time
one machine · process 8698node 0memory 0 · 8 slots of 4 KiBnode 1memory 1 · 8 slots of 4 KiBinterconnectCPU 0CPU 1CPU 2CPU 3main10 → 1.0 µs21 → 2.1 µsnode distances (numactl --hardware)node 0from node 01021node 1from node 12110one machine · process 8698node 0memory 0 · 8 slots of 4 KiBnode 1memory 1 · 8 slots of 4 KiBinterconnectCPU 0CPU 1CPU 2CPU 3main10 → 1.0 µs21 → 2.1 µsnode distances (numactl --hardware)node 0from node 01021node 1from node 12110
Toy: 2 NUMA nodes × 2 CPUs · 8 pages of 4 KiB · a read takes distance × 0.1 µs (10 local, 21 remote)
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
tread=d×0.1 μs\sy{t}{data}{t_{\text{read}}} = \sy{d}{param}{d} \times 0.1\ \mu\text{s}
tlocal=10×0.1=1.0 μs,tremote=21×0.1=2.1 μst_{\text{local}} = 10 \times 0.1 = 1.0\ \mu\text{s},\quad t_{\text{remote}} = 21 \times 0.1 = 2.1\ \mu\text{s}

A page read takes the node distance times 0.1 µs.

Common mix-ups

MYTHPinning a worker to a node moves its pages there.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01If each worker writes its own pages first, how long do 2 workers take?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.