Skip to content
systemcoding.dev
Performance

Interleave a process's memory across nodes with numactl --interleave=all

Run a program under numactl --interleave=all so its pages spread round-robin over every NUMA node, and confirm the policy took effect.

1 min read
Summarize in AI

A large shared structure, such as an in-memory index read by threads on every socket, can overload one node's memory controller if first-touch placement puts all of it there. Interleaving spreads its pages round-robin across the nodes, so the bandwidth is shared out evenly.

Shell
numactl --interleave=all ./myserver

You can check that the policy applies by asking numactl to show what a child process inherits:

Shell
numactl --interleave=all numactl --show

On a two-node machine the first lines read:

Text
policy: interleave
preferred node: 0 (interleave next)
interleavemask: 0 1

The remaining lines list the allowed CPUs and memory nodes, and they depend on the machine.

The policy is inherited by child processes and applies to pages allocated after it is set, so wrap the program that allocates, not a launcher script that starts it later without the policy. Interleaving is the right default when access is spread across all threads. It is the wrong choice when each thread works on its own data: there the better placement is local, with --cpunodebind and --membind on one node, because interleaving makes half of the accesses remote.

The options are described in numactl(8). Under systemd, the same policy can be set in a unit with NUMAPolicy=interleave and NUMAMask=.

Also inKernels
Taggedlinuxnuma
Share

More snippets

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.