Linux Internals

NUMA Architecture and Automatic NUMA Balancing in Linux

By NileVPS Team · Published · 4 min read

اقرأ المقال بالعربي

On a laptop, every CPU core reaches every byte of RAM at roughly the same speed. Large servers do not work that way. A dual-socket machine has memory attached to each processor, and a core reaching memory on the other socket pays a noticeable penalty. This design is called NUMA, Non-Uniform Memory Access. Linux has a lot of machinery to cope with it, including automatic NUMA balancing. This article explains the concepts, the tools to inspect them and what they mean when you run a VPS.

From UMA to NUMA

In older designs all processors shared one memory controller and one bus. As core counts grew, that shared path became a bottleneck. The fix was to give each processor, or each group of cores, its own memory controller and its own local RAM. The processors are connected by a fast interconnect so they can still read each other's memory, just more slowly.

Each processor and its local memory form a NUMA node. Accessing memory in your own node is local access. Accessing another node's memory is remote access, with higher latency and lower bandwidth. How large the gap is depends on the hardware generation and topology, so treat any single figure you read with caution and measure on your own system.

Modern processors with many chiplets can even expose several NUMA nodes within one socket, depending on firmware settings.

Inspecting NUMA topology

Start with lscpu:

lscpu | grep -i numa

Example output on a two-node server:

NUMA node(s):        2
NUMA node0 CPU(s):   0-15,32-47
NUMA node1 CPU(s):   16-31,48-63

For more detail install numactl:

sudo apt install numactl      # Debian/Ubuntu
sudo dnf install numactl      # RHEL family
numactl --hardware

This prints each node's CPUs, memory size, free memory and a distance table. The distance values are relative costs reported by firmware: 10 means local, larger numbers mean more expensive access.

To see how a process's memory is spread across nodes:

numastat -p mysqld
numastat -m

Controlling placement manually

numactl can launch a program with a specific policy:

# Run on node 0's CPUs and allocate only from node 0's memory
numactl --cpunodebind=0 --membind=0 ./myapp

# Spread allocations across all nodes (useful for large shared caches)
numactl --interleave=all ./myapp
PolicyEffectGood for
Default (local)Allocate on the node where the thread runsMost workloads
--membindAllocate only from given nodesStrict isolation, risks OOM on that node
--preferredPrefer a node, fall back if fullSoft placement
--interleaveRound-robin pages across nodesLarge shared memory, databases with big buffers

Some databases document NUMA recommendations; MongoDB, for example, has historically suggested interleaving. Follow your software's own guidance.

Automatic NUMA balancing

Manual placement does not scale to every process. Linux therefore includes automatic NUMA balancing. The kernel periodically unmaps small ranges of a task's memory so that the next access triggers a lightweight fault. From those faults it learns which node each task really uses, then migrates pages closer to the task or moves the task closer to its memory.

Check whether it is enabled:

cat /proc/sys/kernel/numa_balancing

A value of 1 means enabled. It is only active on systems with more than one node. Its activity shows up in /proc/vmstat:

grep -E 'numa_(hint_faults|pages_migrated|pte_updates)' /proc/vmstat

For most workloads the default is fine. Some latency-sensitive applications that are already carefully pinned turn it off, because the scanning and migrations add overhead:

sudo sysctl kernel.numa_balancing=0

Measure before and after; disabling it without manual placement can make things worse.

What this means on a VPS

A typical VPS runs as a KVM guest, and small and medium plans usually expose a single virtual NUMA node. Run lscpu and you will most likely see NUMA node(s): 1. In that case there is nothing to tune inside the guest; automatic NUMA balancing is inactive and numactl placement has no effect.

Placement still matters, but it happens on the host: the hypervisor decides where your vCPUs and memory physically live. That is outside your control and is the provider's job.

Large VMs can be given multiple virtual NUMA nodes so the guest kernel can make smart decisions. If your lscpu shows more than one node, the techniques above apply. For related tuning, see CPU pinning with taskset, and if you need more vCPUs and memory for a heavy workload, compare plans on the pricing page.

Quick checklist

  1. Run lscpu | grep -i numa to learn how many nodes you have.
  2. If there is one node, stop here; NUMA tuning does not apply.
  3. If there are several, check numastat -p <process> for heavy remote access.
  4. Keep automatic balancing on unless you pin processes manually and have measured.
  5. Follow your database's documented NUMA guidance.

FAQ

Why does my VPS show only one NUMA node?

Most virtual machines are presented with a single virtual node, especially when their size fits comfortably within one physical node. The host still handles physical placement; it is simply not exposed to the guest.

Should I disable automatic NUMA balancing?

Usually not. It helps unpinned workloads on multi-node systems. Consider disabling it only when processes are already pinned to nodes and you have measured overhead from page migrations.

Can NUMA cause problems even with free memory?

Yes. With a strict --membind policy, a process can run out of memory on its allowed node while other nodes still have free RAM. That is why preferred or interleaved policies are often safer.

Related guides