set_mempolicy(2) System Calls Manual set_mempolicy(2) set_mempolicy - NUMA LIBRARY 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 ( ). . , . mode : MPOL_DEFAULT, MPOL_BIND, MPOL_INTERLEAVE, MPOL_PREFERRED MPOL_LOCAL ( ). , MPOL_DEFAULT, , nodemask , . 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_PREFERRED . , <<>> . nodemask , . nodemask maxnode , << >> ( , ). 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 ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . set_mempolicy(2)