NUMACTL(8)
๐ธ NUMACTL(8) ๐ธ
Linux Administrator's Manual, bestie, this is the one for numactl ๐
โจ NAME โจ
numactl - Control NUMA policy for processes or shared memory ๐ฆ
๐ SYNOPSIS ๐
numactl [ --all ] [ --balancing ] [ --interleave nodes ] [
--weighted-interleave nodes ] [ --preferred node ] [ --preferred-many
nodes ] [ --membind nodes ] [ --cpunodebind nodes ] [ --physcpubind cpus
] [ --localalloc ] [--] command {arguments ...}
numactl --show
numactl --hardware [--cpu-compress]
numactl --version
numactl [ --huge ] [ --offset offset ] [ --shmmode shmmode ] [ --length
length ] [ --strict ]
[ --shmid id ] --shm shmkeyfile | --file tmpfsfile
[ --touch ] [ --dump ] [ --dump-nodes ] memory policy
๐ DESCRIPTION ๐
Okay so numactl lets you run processes with a specific NUMA scheduling or memory placement policy ๐ง The policy gets set for command and every one of its children inherits it, no cap. It can also set a persistent policy for shared memory segments or files, which is so iconic.
Use -- before command if your command has options that could get mixed up with numactl options, bestie ๐
๐บ๏ธ Node and CPU Lists ๐บ๏ธ
Nodes can be written as N,N,N or N-N or N,N-N or N-N,N-N, and so on. Relative nodes work too, written as +N,N,N or +N-N or +N,N-N, and so on. That + means the node numbers are counted relative to the process' set of allowed nodes in its current cpuset ๐ A !N-N means the inverse of N-N, so all nodes except N-N. If you pair it with +, write it as !+N-N. When you write same, it reuses the previous nodemask you gave on the command line โจ And all means all nodes in the current cpuset.
Instead of a number, a node can also be one of these:
netdev:DEV- the node connected to network deviceDEV.file:PATH- the node the block device ofPATH.ip:HOST- the node of the network device ofHOST.block:PATH- the node of block devicePATH.pci:[seg:]bus:dev[:func]- the node of a PCI device.
๐จ Heads up, bestie:blockonly resolves the kernel block device names for udev names in/dev. For anything else, usefile:instead ๐
Policy settings are below. Iykyk ๐
๐ Policy Settings ๐
--all,-aโ Unsets the default cpuset awareness, so you can use all possible CPUs and nodes for the policy settings that follow ๐--interleave=nodes,-i nodesโ Sets a memory interleave policy ๐ง Memory gets allocated round robin across the nodes. When memory can't be allocated on the current interleave target, it falls back to other nodes. You can specify multiple nodes with--interleave,--membindand--cpunodebind.--weighted-interleave=nodes,-w nodesโ Sets a weighted memory interleave policy โ๏ธ Memory gets allocated using the weighted ratio for each node, which you can read from/sys/kernel/mm/mempolicy/weighted_interleave/node*. When memory can't be allocated on the current interleave target, it falls back to other nodes.--membind=nodes,-m nodesโ Only allocates memory fromnodes๐ Allocation will fail if there isn't enough memory on these nodes, so be careful, bestie ๐nodescan be written as noted above.--cpunodebind=nodes,-N nodesโ Only runscommandon the CPUs ofnodes๐ A node can have multiple CPUs.nodescan be written as noted above.--physcpubind=cpus,-C cpusโ Only runs the process oncpus๐ฆ This takes the CPU numbers you'd see in the processor fields of/proc/cpuinfo, or relative CPUs, which are relative to the current cpuset. You can say"all", which means all CPUs in the current cpuset. Physical CPUs can be written asN,N,NorN-NorN,N-NorN-N,N-N, and so on. Relative CPUs can be written as+N,N,Nor+N-Nor+N,N-N, and so on. The+means the CPU numbers are relative to the process' set of allowed CPUs in its current cpuset. A!N-Nmeans the inverse ofN-N, so all CPUs exceptN-N. If you use+, write it as!+N-N.--localalloc,-lโ Tries to allocate on the current node of the process, and if memory can't be allocated there, falls back to other nodes ๐--preferred=node,-p nodeโ Prefers to allocate memory onnode, but falls back to other nodes if it can't be allocated there ๐ This only takes a single node number. Relative notation is allowed.--balancing,-bโ Enables Linux kernel NUMA balancing for the process, if the kernel supports it โจ This should only be used with--membind,-monly. Otherwise it gets ignored, so don't stress ๐--preferred-many=nodes,-P nodesโ Prefers to allocate memory onnodes, and falls back to other nodes if needed ๐ This takes a mask of preferred nodes, where the node closest to local counts as the most preferred one. Relative notation is allowed.--show,-sโ Shows the NUMA policy settings of the current process ๐--hardware,-Hโ Shows an inventory of the available nodes on the system ๐งพ When--cpu-compressis set, it shows CPU ranges instead. This isn't the default, so it won't break any existing scripts, periodt ๐
Okay, numactl can also set up a policy for a SYSV shared memory segment or a file in shmfs/hugetlbfs ๐ซถ
--versionโ Prints the version of the numactl package and exits ๐
๐ง Persistent Shared Memory and File Settings ๐ง
These policy settings are persistent, and every mapping from that shared memory will use them. The order of the options matters here, so pay attention, bestie ๐ Your spec has to include at least one of --shm, --shmid or --file to pick the shared memory segment or file, plus a memory policy like the ones above (--interleave, --localalloc, --preferred, --preferred-many, --membind).
--hugeโ When creating a SYSV shared memory segment, use huge pages ๐ Only valid before--shmidor--shm.--offsetโ Specifies an offset into the shared memory segment ๐ The default is0. Valid units arem(for MB),g(for GB),k(for KB). Otherwise it's bytes.--strictโ Gives an error when a page in the policied area of the shared memory segment has already been faulted in with a conflicting policy ๐ญ By default it silently ignores this.--shmmode shmmodeโ Only valid before--shmidor--shm. When creating a shared memory segment, this sets it to the numeric modeshmmode๐--length lengthโ Applies the policy to alengthrange in the shared memory segment, or makes the segment that long ๐ By default it uses the remaining length. This is required when a shared memory segment is created, and it sets the length of the new segment. Valid units arem(for MB),g(for GB),k(for KB). Otherwise it's bytes.--shmid idโ Creates or uses a shared memory segment with the numeric IDid๐--shm shmkeyfileโ Creates or uses a shared memory segment, with the ID generated usingftok(3)fromshmkeyfile๐๏ธ--file tmpfsfileโ Sets the policy for a file in tmpfs or hugetlbfs ๐--touchโ Touches the pages to enforce the policy early ๐ By default they aren't touched. The policy gets applied when an application maps and accesses a page.--dumpโ Dumps the policy in the specified range ๐--dump-nodesโ Dumps all nodes of the specific range. This is very verbose, so brace yourself ๐ญ
๐ Valid Node Specifiers ๐
allโ All nodesnumberโ Node numbernumber1{,number2}โ Node number1 and Node number2number1-number2โ Nodes from number1 to number2! nodesโ Inverts the selection of the following specification
๐ EXAMPLES ๐
Here are some looks you can try, bestie ๐
Run myapplic on CPUs 0-4 and 8-12 of the current cpuset โจ
numactl --physcpubind=+0-4,8-12 myapplic arguments
Run the big database with its memory interleaved on all CPUs ๐ง
numactl --interleave=all bigdatabase arguments
Run the big database with its memory interleaved with a weighted ratio on all CPUs โ๏ธ
numactl --weighted-interleave=all bigdatabase arguments
Run process on node 0, with memory allocated on nodes 0 and 1 ๐ซถ
numactl --cpunodebind=0 --membind=0,1 process
Run process the same as above, but with an option (-l) that would get confused with a numactl option ๐
numactl --cpunodebind=0 --membind=0,1 -- process -l
Run process on node 0, with memory allocated on nodes 0 and 1. It also optimizes page placement with the Linux kernel NUMA balancing mechanism, if possible ๐
numactl --cpunodebind=0 --balancing --membind=0,1 process
Run network-server on the node of network device eth0, with its memory in the same node too ๐
numactl --cpunodebind=netdev:eth0 --membind=netdev:eth0 network-server
Set preferred node 1 and show the resulting state ๐
numactl --preferred=1 numactl --show
Set preferred nodes 1 and 2, and show the resulting state ๐
numactl --preferred-many=0x3 numactl --show
Interleave all of the SYSV shared memory region of size 1g specified by /tmp/shmkey over all nodes ๐ฆ
numactl --length 1g --shm /tmp/shmkey --interleave=all
Place a tmpfs file on 2 nodes ๐
numactl --membind=2 dd if=/dev/zero of=/dev/shm/A bs=1M count=1024
numactl --membind=3 dd if=/dev/zero of=/dev/shm/A seek=1024 bs=1M count=1024
Reset the policy for the shared memory file /dev/shm/file back to the default localalloc policy ๐งน
numactl --localalloc /dev/shm/file
๐ NOTES ๐
Requires a NUMA policy aware kernel, so check that first, bestie ๐ฅ
command doesn't get run using a shell ๐ If you want to use shell metacharacters in the child, wrap it with sh -c.
โ ๏ธ Setting policy for a hugetlbfs file currently doesn't work, because it can't be extended by truncate. Sad, but true ๐ญ
โ ๏ธ Shared memory segments larger than numactl's address space can't be completely policied. This could be a problem on 32-bit architectures. Changing it piece by piece may work ๐ฅบ
The old --cpubind option, which accepts node numbers rather than CPU numbers, is deprecated ๐
โโ๏ธ It's been replaced by the new --cpunodebind and --physcpubind options.
๐ FILES ๐
/proc/cpuinfoโ the listing of active CPUs. Seeproc(5)for details ๐/sys/devices/system/node/node*/numastatโ NUMA memory hit statistics ๐
โ๏ธ COPYRIGHT โ๏ธ
Copyright 2002,2004 Andi Kleen, SuSE Labs. numactl and the demo programs are under the GNU General Public License, v.2 ๐
๐ SEE ALSO ๐
set_mempolicy(2), get_mempolicy(2), mbind(2), sched_setaffinity(2), sched_getaffinity(2), proc(5), ftok(3), shmat(2), migratepages(8) ๐
Bestie, that's the whole tea on numactl ๐ Manual by SuSE Labs, last updated Mar 2004, and it's still giving ๐ฆ NUMACTL(8) forever โจ๐๐
๐ฆ where this page comes from
- alpine 3.24: numactl-doc 2.0.19-r0 ยท LGPL-2.1-only
- arch rolling: numactl 2.0.19-1 ยท GPL-2.0-only AND LGPL-2.1-only
- centos-stream 10: numactl 2.0.19-3.el10 ยท GPL-2.0-only
- centos-stream 9: numactl 2.0.19-3.el9 ยท LGPL-2.1-only and GPL-2.0-only
- debian trixie: numactl 2.0.19-1
- fedora 43: numactl 2.0.19-3.fc43 ยท GPL-2.0-only
- fedora 44: numactl 2.0.19-4.fc44 ยท GPL-2.0-only
- opensuse-leap 16.0: numactl 2.0.19.14.g690a72c-160000.2.2 ยท GPL-2.0-only
- opensuse-leap 16.0: numactl 2.0.19.14.g690a72c-160000.2.2 ยท GPL-2.0-only
- opensuse-leap 16.0: numactl 2.0.19.14.g690a72c-160000.2.2 ยท GPL-2.0-only
- opensuse-leap 16.0: numactl 2.0.19.14.g690a72c-160000.2.2 ยท GPL-2.0-only
- ubuntu questing: numactl 2.0.19-1
- ubuntu resolute: numactl 2.0.19-1build1
- ubuntu stonking: numactl 2.0.19-1build1
- Copyright 2003,2004 Andi Kleen, SuSE Labs
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms