NUMA: memory that is near and far
Video 044 of 140 in Virtualization Foundations, in the unit “Memory: RAM, addresses and virtual memory”. 4:18, with English and Hindi audio.
On a large server, memory is not always equally close to every processor. The design that handles this is called NUMA, which stands for non-uniform memory access. A program can run quickly on one processor and slowly on another if its memory sits on the far side. This article explains local and remote memory, how Linux chooses where a new page of memory lands, and how to see the NUMA layout of an Ubuntu server, so you can keep work close to its memory.
What you will learn
- NUMA means a processor reaches its local memory faster than remote memory.
- Each socket has memory of its own, joined to the others by an interconnect.
- By default, Linux places a new page on the node of the processor that first uses it.
- Keep a program's threads and memory on one socket, when it fits.
Why memory speed depends on which processor asks
Many processors that share one path to memory slow each other down. The answer is to give each processor memory of its own, attached directly to it. That memory is much faster for that processor.
A processor can still reach the memory of another processor. But that access goes through a link between them, which is slower. This is the idea behind NUMA.
Local memory and remote memory
Picture a server with two processor sockets. A socket is the place on the main board where one processor sits. Each socket has its own cores and its own memory channels, with local RAM attached. The two sockets are joined by a fast link, called the interconnect.
- Local memory sits on the same socket as the program that runs. The path is short, so it is faster.
- Remote memory sits on the other socket. Every access crosses the interconnect, which adds delay.
The gap is real, and busy links make it worse.
Where a new page of memory lands
A thread uses a new page of memory for the first time. By default, Linux picks the node of that thread's processor for the page, so the page is local to that processor, and the program is fast while it stays there.
But the scheduler, which decides where each thread runs, may move the thread to the other socket. Then every access crosses the interconnect. The fix is to keep a program's threads and memory on one socket, for example by pinning the program there.
What goes wrong, and how you notice it
- Threads and memory apart: the threads run on one socket while their memory sits on the other, so every access crosses the link.
- A virtual machine larger than one socket: it spreads across both sockets, so part of its memory is remote.
You notice slower work on a big server, and numastat showing many allocations on the wrong node.
How to see the NUMA layout on Ubuntu
On Ubuntu, lscpu, filtered for NUMA, lists the nodes and the processors that belong to each one.
lscpu | grep -i numaThe numactl tool, with its hardware option, adds each node's memory and the distance between nodes. It may need to be installed first.
numactl --hardwareThe numastat tool counts memory allocations on each node. A high count of allocations that landed on the wrong node is a sign of remote memory.
numastatTry it yourself
You need an Ubuntu machine with two or more NUMA nodes. numactl may need to be installed first. You will see the nodes and their processors, each node's memory and distances, and the allocation counts per node.
List the NUMA nodes, and the processors that belong to each. The grep keeps only the NUMA lines.
lscpu | grep -i numaWhat you should see: Lists the NUMA nodes, and which processors belong to each.
Show each node's CPUs and memory, and the distance between nodes. Install numactl first if the command is missing.
numactl --hardwareWhat you should see: Shows each node's CPUs and memory, and the distance between nodes.
Count the memory allocations on each node, including any that were placed on the wrong node.
numastatWhat you should see: Counts allocations per node, including those placed on the wrong node.
Terms
- NUMA
- Non-uniform memory access, a design in which each processor reaches its own memory faster than memory on another socket.
- Socket
- The place on a server's main board where one processor chip sits.
- Interconnect
- The fast link that joins the processors of a server, which remote memory accesses must cross.
- Remote memory
- Memory attached to another socket, which takes longer to reach than local memory.
Check yourself
What does NUMA mean for memory speed?
A processor reaches memory attached to its own socket faster than memory attached to the other socket.
Why can a thread become slower after it moves to the other socket?
Its memory may still sit on the first socket, so every access now crosses the interconnect.
Which command counts memory allocations on each NUMA node?
numastat. It counts allocations per node, including those placed on the wrong node.
Previous: The page cache: spare RAM that is not wasted. Next: How a hard disk works.