numactl
Run processes on specific NUMA nodes
TLDR
Run a command on node 0 with memory allocated on node 0 and 1
Run a command on CPUs (cores) 0-4 and 8-12 of the current cpuset
Run a command with its memory interleaved on all CPUs
SYNOPSIS
numactl [options] command [arguments]
PARAMETERS
--cpunodebind=nodes
Bind the process to the specified NUMA nodes for CPU execution. Comma-separated list or range of nodes.
--membind=nodes
Bind the process to the specified NUMA nodes for memory allocation. Comma-separated list or range of nodes.
--localalloc
Allocate memory only on the node where the process is running.
--preferred=node
Prefer memory allocation on the specified node.
--interleave=nodes
Interleave memory allocation across the specified NUMA nodes. Comma-separated list or range of nodes.
--physcpubind=cpus
Bind the process to the specified physical CPUs. Comma-separated list or range of CPUs.
--show
Display the current NUMA policy.
--length=size
Specify the size of memory to allocate or operate on (e.g., with --touch or --dump).
--offset=size
Specify the offset into the memory region for operations.
--touch
Touch pages in the specified memory region to force allocation.
--dump
Dump the contents of the specified memory region.
--hardware
Display NUMA hardware configuration.
--version
Display the version of numactl.
--help
Display help information.
--cpubind=nodes
DEPRECATED Equivalent to --cpunodebind.
--membind=nodes
Bind memory to a specific set of NUMA nodes. Takes a comma-separated list or range of node IDs. If no command is given, runs a shell.
--all
Use all available nodes for memory allocation or CPU binding.
--nodes=nodes
Specifies the nodes for various options. Uses a comma-separated list or range of node IDs.
--preferred=node
Prefer allocating memory from the specified node.
--interleave=nodes
Interleave memory allocations across specified nodes. Uses a comma-separated list or range of node IDs.
DESCRIPTION
The numactl command is a versatile tool used to manage the NUMA (Non-Uniform Memory Access) characteristics of processes and shared memory on Linux systems.
NUMA architectures have multiple nodes, each with its own local memory. Accessing local memory is significantly faster than accessing memory on a remote node. numactl allows you to control which NUMA nodes a process is allowed to run on (CPU affinity) and from which nodes memory is allocated.
This allows you to optimize application performance by ensuring that processes run on the nodes where their data resides, minimizing cross-node memory access. It can be used to bind processes to specific nodes, allocate memory from specific nodes, and display NUMA system information. Misuse can lead to performance degradation, so careful consideration is needed. It is particularly useful for applications that are memory-intensive and benefit from reduced memory latency.
CAVEATS
Incorrect usage of numactl can severely degrade performance. It is crucial to understand the memory access patterns of your application and the NUMA topology of your system before using this tool.
RUNNING COMMANDS
When a command is provided to numactl, it executes the command with the specified NUMA policy. If no command is given, numactl executes a shell. This allows you to easily set NUMA policies for interactive sessions.
COMMON USE CASES
Some common use cases include:
1. Running a database server on a specific NUMA node for improved local memory access.
2. Binding a compute-intensive process to a set of cores on a particular NUMA node.
3. Interleaving memory allocation across multiple nodes to increase aggregate memory bandwidth.
HISTORY
numactl was developed to provide userspace control over NUMA policies on Linux systems. Its initial development focused on allowing administrators and developers to optimize the performance of applications on NUMA hardware by controlling memory allocation and CPU affinity. Over time, new features and options have been added to support more complex NUMA configurations and usage scenarios. It remains a crucial tool for maximizing application performance on modern multi-node servers and workstations.