1mbind(2)                      System Calls Manual                     mbind(2)
2
3
4

NAME

6       mbind - set memory policy for a memory range
7

LIBRARY

9       NUMA (Non-Uniform Memory Access) policy library (libnuma, -lnuma)
10

SYNOPSIS

12       #include <numaif.h>
13
14       long mbind(void addr[.len], unsigned long len, int mode,
15                  const unsigned long nodemask[(.maxnode + ULONG_WIDTH - 1)
16                                               / ULONG_WIDTH],
17                  unsigned long maxnode, unsigned int flags);
18

DESCRIPTION

20       mbind()  sets  the  NUMA memory policy, which consists of a policy mode
21       and zero or more nodes, for the memory range  starting  with  addr  and
22       continuing  for  len  bytes.  The memory policy defines from which node
23       memory is allocated.
24
25       If the memory range specified by the addr and len arguments includes an
26       "anonymous"  region  of memory—that is a region of memory created using
27       the mmap(2) system call with the MAP_ANONYMOUS—or a memory-mapped file,
28       mapped  using  the mmap(2) system call with the MAP_PRIVATE flag, pages
29       will be allocated only according to the specified policy when  the  ap‐
30       plication  writes (stores) to the page.  For anonymous regions, an ini‐
31       tial read access will use a shared page in the  kernel  containing  all
32       zeros.  For a file mapped with MAP_PRIVATE, an initial read access will
33       allocate pages according to the memory policy of the thread that causes
34       the  page  to  be  allocated.   This  may not be the thread that called
35       mbind().
36
37       The specified policy will be ignored for any MAP_SHARED mappings in the
38       specified  memory  range.  Rather the pages will be allocated according
39       to the memory policy of the thread that caused the  page  to  be  allo‐
40       cated.  Again, this may not be the thread that called mbind().
41
42       If  the  specified memory range includes a shared memory region created
43       using the shmget(2) system call and attached using the shmat(2)  system
44       call, pages allocated for the anonymous or shared memory region will be
45       allocated according  to  the  policy  specified,  regardless  of  which
46       process  attached  to  the shared memory segment causes the allocation.
47       If, however, the shared memory region was created with the  SHM_HUGETLB
48       flag,  the  huge pages will be allocated according to the policy speci‐
49       fied only if the page allocation is caused by the  process  that  calls
50       mbind() for that region.
51
52       By  default,  mbind()  has  an  effect only for new allocations; if the
53       pages inside the range have been already  touched  before  setting  the
54       policy,  then  the  policy has no effect.  This default behavior may be
55       overridden by the MPOL_MF_MOVE and MPOL_MF_MOVE_ALL flags described be‐
56       low.
57
58       The mode argument must specify one of MPOL_DEFAULT, MPOL_BIND, MPOL_IN‐
59       TERLEAVE, MPOL_PREFERRED, or MPOL_LOCAL (which are described in  detail
60       below).   All  policy  modes  except MPOL_DEFAULT require the caller to
61       specify the node or nodes to which the mode applies, via  the  nodemask
62       argument.
63
64       The  mode  argument