set_mempolicy(2) System Calls Manual set_mempolicy(2) set_mempolicy - NUMA NUMA (Non-Uniform Memory Access) policy library (libnuma, -lnuma) #include long set_mempolicy(int mode, const unsigned long *nodemask, unsigned long maxnode); set_mempolicy() NUMA , ( mode, nodemask maxnode). NUMA . , . . , , mbind(2). mmap(2) MAP_PRIVATE ( () ) mmap(2) MAP_SHARED ( ). . , . The mode argument must specify one of MPOL_DEFAULT, MPOL_BIND, MPOL_INTERLEAVE, MPOL_WEIGHTED_INTERLEAVE, MPOL_PREFERRED, MPOL_PREFERRED_MANY, or MPOL_LOCAL (which are described in detail below). All modes except MPOL_DEFAULT require the caller to specify the node or nodes to which the mode applies, via the nodemask argument. mode . : MPOL_F_NUMA_BALANCING ( Linux 5.12) When mode is MPOL_BIND, enable the kernel NUMA balancing for the task if it is supported by the kernel. If the flag isn't supported by the kernel, or is used with mode other than MPOL_BIND, -1 is returned and errno is set to EINVAL. MPOL_F_RELATIVE_NODES ( Linux 2.6.26) nodemask , . MPOL_F_STATIC_NODES ( Linux 2.6.26) nodemask . Linux nodemask, , . nodemask , maxnode . sizeof(unsigned long), maxnode. NULL nodemask maxnode . maxnode , nodemask . nodemask, , ( MPOL_F_STATIC_NODES) . mode MPOL_F_STATIC_NODES nodemask , , . , , nodemask. mode : MPOL_DEFAULT This mode specifies that any nondefault thread memory policy be removed, so that the memory policy "falls back" to the system default policy. The system default policy is "local allocation"--that is, allocate memory on the node of the CPU that triggered the allocation. nodemask must be specified as NULL. If the "local node" contains no free memory, the system will attempt to allocate memory from a "near by" node. MPOL_BIND , , nodemask. nodemask , , . , nodemask, .. , . , nodemask. MPOL_INTERLEAVE , nodemask, . , , , . . MPOL_WEIGHTED_INTERLEAVE ( Linux 6.9) This mode interleaves page allocations across the nodes specified in nodemask according to the weights in /sys/kernel/mm/mempolicy/weighted_interleave. For example, if bits 0, 2, and 5 are set in nodemask, and the contents of /sys/kernel/mm/mempolicy/weighted_interleave/node0, /sys/.../node2, and /sys/.../node5 are 4, 7, and 9, respectively, then pages in this region will be allocated on nodes 0, 2, and 5 in a 4:7:9 ratio. MPOL_PREFERRED . , <<>> . nodemask , . nodemask maxnode , << >> ( , ). MPOL_PREFERRED_MANY (since Linux 5.15) This mode specifies a preference for nodes from which the kernel will try to allocate from. This differs from MPOL_PREFERRED in that it accepts a set of nodes versus a single node. This policy is intended to benefit page allocations where specific memory types (i.e. non-volatile, high-bandwidth, or accelerator memory) are of greater importance than node location. MPOL_LOCAL ( Linux 3.8) << >> (local allocation); , , (<< >>). nodemask maxnode . << >> , . << >> , . << >> , . << >> , . execve(2) , fork(2) clone(2). set_mempolicy() 0; -1, errno . EFAULT , nodemask maxnode, . EINVAL mode is invalid. Or, mode is MPOL_DEFAULT and nodemask is nonempty, or mode is MPOL_BIND or MPOL_INTERLEAVE and nodemask is empty. Or, maxnode specifies more than a page worth of bits. Or, nodemask specifies one or more node IDs that are greater than the maximum supported node ID. Or, none of the node IDs specified by nodemask are on-line and allowed by the process's current cpuset context, or none of the specified nodes contain memory. Or, the mode argument specified both MPOL_F_STATIC_NODES and MPOL_F_RELATIVE_NODES. Or, the MPOL_F_NUMA_BALANCING isn't supported by the kernel, or is used with mode other than MPOL_BIND. ENOMEM . Linux. Linux 2.6.7. , . , , . numa(7). get_mempolicy(2), getcpu(2), mbind(2), mmap(2), numa(3), cpuset(7), numa(7), numactl(8) () Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov , Kirill Rekhov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux man-pages 6.12 21 2025 . set_mempolicy(2)