Inspect NUMA Topology With numactl --hardware and lstopo
Read a machine's NUMA nodes, per-node memory and distance matrix with numactl --hardware, then see caches and devices with lstopo from hwloc on Linux.

Tuning for NUMA starts with a map. Before binding a process or placing memory you need to know how many nodes the machine has, which CPUs belong to each, how much memory sits on each, and how far apart the nodes are. Two tools answer that on Linux. numactl --hardware prints the node list and distance matrix from the kernel. lstopo, from the hwloc project, draws the full tree down to caches, cores, PCI devices and which node a network card hangs off. This post shows both, explains every field, and ends with a small C check that scripts can run. It supports the guide to memory bandwidth, NUMA and huge pages, and the commands here are from numactl 2.0.19 and hwloc 2.12 on a recent Linux kernel.
Install the tools
Both are packaged by every major distribution. On Debian or Ubuntu the packages are numactl and hwloc, and on Fedora they are numactl and hwloc. lstopo needs a graphical build for pictures, and the text mode lstopo-no-graphics ships with the base package.
sudo apt install numactl hwlocRead numactl --hardware
The --hardware option, also spelled -H, prints the nodes the kernel knows. This is output from a two-socket server. The CPU numbers, sizes and distances are illustrative, and yours will be different.
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
node 0 size: 128733 MB
node 0 free: 96412 MB
node 1 cpus: 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
node 1 size: 129019 MB
node 1 free: 101278 MB
node distances:
node 0 1
0: 10 21
1: 21 10The first line is the count of nodes. Each node N cpus line lists the logical CPUs local to that node, and with hyper-threading the second hardware thread of each core usually appears as a higher number, which is why the list has two ranges. size is the memory attached to the node and free is what the kernel can still allocate there. The two sizes differ slightly because firmware and the kernel reserve different amounts on each side.
The distance matrix is the relative cost the firmware reports, with 10 for local access. Row 0, column 1 is the distance from node 0 to node 1. A symmetric matrix is common, and an asymmetric one is possible on machines with uneven links. The values are relative, so 21 against 10 says remote is farther, not that it is exactly twice as slow.
On a single-socket desktop the output is one node and a one-by-one matrix. A node can also have memory and no CPUs, or CPUs and no memory. Machines with CXL-attached memory or persistent memory show up as CPU-less nodes, the subject of CXL memory expansion and tiered memory.
See what policy applies right now
numactl --show prints the policy and allowed nodes of the current shell, which is what a child process inherits.
policy: default
preferred node: current
physcpubind: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
cpubind: 0 1
nodebind: 0 1
membind: 0 1policy: default means local allocation. If a container runtime or a cgroup limits CPUs or memory nodes, physcpubind and membind shrink, which is the first thing to check when a containerized process refuses to use all the memory you expect. The kernel's NUMA memory policy documentation defines each policy name.
Draw the full tree with lstopo
numactl knows nodes and CPUs. It does not know caches, cores, sockets or PCI devices. lstopo builds the hardware tree from sysfs and CPUID. The text form needs no display:
lstopo-no-graphics --no-ioA trimmed result for the same machine reads:
Machine (251GB total)
Package L#0
NUMANode L#0 (P#0 126GB)
L3 L#0 (32MB)
L2 L#0 (1024KB) + L1d L#0 (48KB) + L1i L#0 (32KB) + Core L#0
PU L#0 (P#0)
PU L#1 (P#32)
L2 L#1 (1024KB) + L1d L#1 (48KB) + L1i L#1 (32KB) + Core L#1
PU L#2 (P#1)
PU L#3 (P#33)
Package L#1
NUMANode L#1 (P#1 126GB)
L3 L#1 (32MB)The indentation is containment. A Package is a socket. A NUMANode is a memory node attached to that package. Under the L3 cache sit cores, each with its own L2 and L1 caches, and each core holds two PU entries, the hardware threads. L# is hwloc's logical index, which is stable and sequential, and P# is the operating system's physical index, which is the number numactl and taskset use. Mixing them up is the commonest mistake: to pin a process to the first core you pass P#0, not L#0, and both hardware threads of that core are P#0 and P#32.
Drop --no-io and the tree adds PCI devices, network interfaces and GPUs, each placed under the package it is wired to. That tells you which NUMA node a 100 Gb network card or NVMe drive is local to, so you can run the networking thread on the same node as the NIC. For a picture, run lstopo topology.png, or lstopo topology.svg, with a graphical build installed.
Script the check in C
Tools print for humans. A program or a startup script usually wants a number. libnuma gives one with numa_num_configured_nodes(), declared in numa.h, and numa_available() reports whether NUMA is supported at all.
#include <numa.h>
#include <stdio.h>
int main(void) {
if (numa_available() < 0) {
puts("NUMA is not available");
return 1;
}
printf("nodes: %d\n", numa_num_configured_nodes());
printf("cpus: %d\n", numa_num_configured_cpus());
printf("max node: %d\n", numa_max_node());
return 0;
}Build it with gcc nodecount.c -lnuma -o nodecount. On the machine above it prints:
nodes: 2
cpus: 64
max node: 1numa_max_node() returns the highest node number, which is one less than the count only when nodes are numbered contiguously. A machine with a CPU-less CXL node can have gaps or a high-numbered memory-only node, so loop over 0 through numa_max_node() and test each with numa_bitmask_isbitset(numa_all_nodes_ptr, n) rather than assuming 0 .. count-1.
What to look for before tuning
Check four things. Whether the node count matches the socket count, since more nodes than sockets means sub-NUMA clustering or NPS is enabled in firmware. Whether free memory is balanced, because one node full and the other empty means allocations will spill remote. Whether the distance matrix has more than two distinct values, which signals a multi-hop topology. And which node the busiest I/O devices belong to. Those four facts decide the binding choices in the post on binding processes to NUMA nodes.
Reading the output in a real investigation
Three short habits turn these tools into a diagnosis. First, compare node N free with node N size for every node before you start a job. A node that is nearly full will make a bound process fall back or fail, and a node that is nearly empty while its neighbor is full suggests that earlier work allocated unevenly, perhaps through the first-touch effect covered in the post on initialization order. Second, always map devices to nodes. A network card or an NVMe drive that hangs off node 1 is served best by threads on node 1, and lstopo without the --no-io option shows the attachment directly, while cat /sys/class/net/<name>/device/numa_node prints the node number for one interface. A value of -1 means the platform did not report one. Third, write the topology down when you tune. Record the node count, the CPUs per node and the distance matrix next to the benchmark results, because a result without its topology cannot be reproduced on a machine with a different firmware setting.


