mbind(2) System Calls Manual mbind(2) mbind - LIBRARY NUMA (Non-Uniform Memory Access) policy library (libnuma, -lnuma) #include long mbind(void addr[.len], unsigned long len, int mode, const unsigned long nodemask[(.maxnode + ULONG_WIDTH - 1) / ULONG_WIDTH], unsigned long maxnode, unsigned int flags); mbind() NUMA, , , addr len . . If the memory range specified by the addr and len arguments includes an "anonymous" region of memory--that is a region of memory created using the mmap(2) system call with the MAP_ANONYMOUS--or a memory-mapped file, mapped using the mmap(2) system call with the MAP_PRIVATE flag, pages will be allocated only according to the specified policy when the application writes (stores) to the page. For anonymous regions, an initial read access will use a shared page in the kernel containing all zeros. For a file mapped with MAP_PRIVATE, an initial read access will allocate pages according to the memory policy of the thread that causes the page to be allocated. This may not be the thread that called mbind(). MAP_SHARED. , , . , , mbind(). , shmget(2) shmat(2), , , , , , . , SHM_HUGETLB, , - , mbind() . , mbind() ; , . MPOL_MF_MOVE MPOL_MF_MOVE_ALL, . mode : MPOL_DEFAULT, MPOL_BIND, MPOL_INTERLEAVE, MPOL_PREFERRED MPOL_LOCAL ( ). , MPOL_DEFAULT, , nodemask , . mode . : MPOL_F_NUMA_BALANCING (since Linux 5.15) 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_STATIC_NODES ( Linux-2.6.26) nodemask . Linux nodemask, , . MPOL_F_RELATIVE_NODES ( Linux-2.6.26) nodemask , . nodemask , maxnode . sizeof(unsigned long), maxnode . NULL nodemask maxnode 0 . maxnode 0, nodemask . , nodemask, , , , ( MPOL_F_STATIC_NODES) . mode : MPOL_DEFAULT . mbind(), , set_mempolicy(2). MPOL_DEFAULT, . , . MPOL_DEFAULT nodemask maxnode . MPOL_BIND , , nodemask. nodemask , , , . , IR nodemask( Linux 2.6.26 , , . , nodemask, .. , ). MPOL_INTERLEAVE , , nodemask. , , . , , 1 , . . MPOL_PREFERRED . , . nodemask , . nodemask maxnode , , . MPOL_LOCAL ( Linux 3.8) << >>; , (<< >>). nodemask maxnode . << >> , . << >> . << >> , . << >> , . , MPOL_DEFAULT ( set_mempolicy(2)); , << >>. flags MPOL_MF_STRICT mode MPOL_DEFAULT, EIO, . If MPOL_MF_MOVE is specified in flags, then the kernel will attempt to move all the existing pages in the memory range so that they follow the policy. Pages that are shared with other processes will not be moved. If MPOL_MF_STRICT is also specified, then the call fails with the error EIO if some pages could not be moved. If the MPOL_INTERLEAVE policy was specified, pages already residing on the specified nodes will not be moved such that they are interleaved. If MPOL_MF_MOVE_ALL is passed in flags, then the kernel will attempt to move all existing pages in the memory range regardless of whether other processes use the pages. The calling thread must be privileged (CAP_SYS_NICE) to use this flag. If MPOL_MF_STRICT is also specified, then the call fails with the error EIO if some pages could not be moved. If the MPOL_INTERLEAVE policy was specified, pages already residing on the specified nodes will not be moved such that they are interleaved. mbind() 0. -1, errno . EFAULT , nodemask maxnode, . , addr len, (hole). EINVAL flags mode ; addr + len addr; addr . mode MPOL_DEFAULT nodemask ; mode MPOL_BIND MPOL_INTERLEAVE nodemask . maxnode . nodemask , . nodemask , , . mode MPOL_F_STATIC_NODES MPOL_F_RELATIVE_NODES. EIO MPOL_MF_STRICT , ; MPOL_MF_MOVE MPOL_MF_MOVE_ALL . ENOMEM . EPERM flags MPOL_MF_MOVE_ALL CAP_SYS_NICE. Linux. Linux 2.6.7. Support for huge page policy was added with Linux 2.6.16. For interleave policy to be effective on huge page mappings the policied memory needs to be tens of megabytes or larger. Before Linux 5.7. MPOL_MF_STRICT was ignored on huge page mappings. MPOL_MF_MOVE MPOL_MF_MOVE_ALL Linux 2.6.16 . numa(7). NUMA , MAP_SHARED. MPOL_DEFAULT mbind() set_mempolicy(2). MPOL_DEFAULT set_mempolicy(2), . MPOL_DEFAULT , mbind(), , , , set_mempolicy(2). , <<>> . << >> , mode MPOL_LOCAL MPOL_PREFERRED . set_mempolicy(2). . get_mempolicy(2), getcpu(2), mmap(2), set_mempolicy(2), shmat(2), shmget(2), numa(3), cpuset(7), numa(7), numactl(8) aereiae , Alexey , Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , ITriskTI , Max Is , Yuri Kozlov , ; GNU 3 , . . , , . Linux man-pages 6.06 9 2023 . mbind(2)