1SET_MEMPOLICY(2)           Linux Programmer's Manual          SET_MEMPOLICY(2)
2
3
4

NAME

6       set_mempolicy  -  set  default NUMA memory policy for a process and its
7       children
8

SYNOPSIS

10       #include <numaif.h>
11
12       int set_mempolicy(int mode, unsigned long *nodemask,
13                         unsigned long maxnode);
14
15       Link with -lnuma.
16

DESCRIPTION

18       set_mempolicy() sets the NUMA memory policy  of  the  calling  process,
19       which  consists  of a policy mode and zero or more nodes, to the values
20       specified by the mode, nodemask and maxnode arguments.
21
22       A NUMA machine has different memory  controllers  with  different  dis‐
23       tances  to  specific  CPUs.   The memory policy defines from which node
24       memory is allocated for the process.
25
26       This system call defines the  default  policy  for  the  process.   The
27       process  policy  governs  allocation  of pages in the process's address
28       space outside of memory ranges controlled by a more specific policy set
29       by  mbind(2).   The  process default policy also controls allocation of
30       any pages for memory mapped files mapped using the  mmap(2)  call  with
31       the  MAP_PRIVATE  flag  and  that  are  only  read [loaded] from by the
32       process and of memory mapped files mapped using the mmap(2)  call  with
33       the  MAP_SHARED  flag,  regardless  of  the access type.  The policy is
34       applied only when a new page is allocated for the process.  For  anony‐
35       mous memory this is when the page is first touched by the application.
36
37       The   mode  argument  must  specify  one  of  MPOL_DEFAULT,  MPOL_BIND,
38       MPOL_INTERLEAVE  or  MPOL_PREFERRED.   All  modes  except  MPOL_DEFAULT
39       require  the  caller  to  specify via the nodemask argument one or more
40       nodes.
41
42       The mode argument may also include an optional  mode  flag.   The  sup‐
43       ported mode flags are:
44
45       MPOL_F_STATIC_NODES (since Linux 2.6.26)
46              A  nonempty  nodemask  specifies  physical node ids.  Linux does
47              will not remap the nodemask when the process moves to a  differ‐
48              ent  cpuset  context,  nor  when the set of nodes allowed by the
49              process's current cpuset context changes.
50
51       MPOL_F_RELATIVE_NODES (since Linux 2.6.26)
52              A nonempty nodemask specifies node ids that are relative to  the
53              set of node ids allowed by the process's current cpuset.
54
55       nodemask  points  to a bit mask of node IDs that contains up to maxnode
56       bits.   The  bit  mask  size  is  rounded  to  the  next  multiple   of
57       sizeof(unsigned long), but the kernel will use bits only up to maxnode.
58       A NULL value of nodemask or a maxnode value of zero specifies the empty
59       set  of  nodes.  If the value of maxnode is zero, the nodemask argument
60       is ignored.
61
62       Where a nodemask is required, it must contain at least one node that is
63       on-line,  allowed  by the process's current cpuset context, [unless the
64       MPOL_F_STATIC_NODES mode flag is specified], and contains  memory.   If
65       the MPOL_F_STATIC_NODES is set in mode and a required nodemask contains
66       no nodes that are allowed by the process's current cpuset context,  the
67       memory  policy reverts to local allocation.  This effectively overrides
68       the specified policy until the process's cpuset context includes one or
69       more of the nodes specified by nodemask.
70
71       The MPOL_DEFAULT mode specifies that any nondefault process memory pol‐
72       icy be removed, so that the memory policy "falls back"  to  the  system
73       default  policy.   The  system  default  policy is "local allocation"--
74       i.e., allocate memory on the node of the CPU that triggered the alloca‐
75       tion.   nodemask  must  be specified as NULL.  If the "local node" con‐
76       tains no free memory, the system will attempt to allocate memory from a
77       "near by" node.
78
79       The  MPOL_BIND mode defines a strict policy that restricts memory allo‐
80       cation to the nodes specified in nodemask.  If nodemask specifies  more
81       than one node, page allocations will come from the node with the lowest
82       numeric node ID first, until that node contains no free memory.   Allo‐
83       cations  will  then  come  from  the node with the next highest node ID
84       specified in nodemask and so forth, until none of the  specified  nodes
85       contain  free  memory.   Pages  will not be allocated from any node not
86       specified in the nodemask.
87
88       MPOL_INTERLEAVE interleaves page allocations across the nodes specified
89       in  nodemask  in  numeric  node ID order.  This optimizes for bandwidth
90       instead of latency by spreading out pages and memory accesses to  those
91       pages  across  multiple nodes.  However, accesses to a single page will
92       still be limited to the memory bandwidth of a single node.
93
94       MPOL_PREFERRED sets the preferred node for allocation.  The kernel will
95       try  to  allocate pages from this node first and fall back to "near by"
96       nodes if the preferred node is low on free memory.  If nodemask  speci‐
97       fies more than one node ID, the first node in the mask will be selected
98       as the preferred node.  If the nodemask and maxnode  arguments  specify
99       the  empty  set, then the policy specifies "local allocation" (like the
100       system default policy discussed above).
101
102       The process memory policy is preserved  across  an  execve(2),  and  is
103       inherited by child processes created using fork(2) or clone(2).
104

RETURN VALUE

106       On  success,  set_mempolicy()  returns  0; on error, -1 is returned and
107       errno is set to indicate the error.
108

ERRORS

110       EFAULT Part of all of the memory range specified by nodemask and  maxn‐
111              ode points outside your accessible address space.
112
113       EINVAL mode  is  invalid.   Or,  mode  is  MPOL_DEFAULT and nodemask is
114              nonempty, or mode is MPOL_BIND or MPOL_INTERLEAVE  and  nodemask
115              is empty.  Or, maxnode specifies more than a page worth of bits.
116              Or, nodemask specifies one or more node  IDs  that  are  greater
117              than  the  maximum  supported node ID.  Or, none of the node IDs
118              specified by nodemask are on-line and allowed by  the  process's
119              current  cpuset  context, or none of the specified nodes contain
120              memory.     Or,    the    mode    argument    specified     both
121              MPOL_F_STATIC_NODES and MPOL_F_RELATIVE_NODES.
122
123       ENOMEM Insufficient kernel memory was available.
124

VERSIONS

126       The  set_mempolicy(), system call was added to the Linux kernel in ver‐
127       sion 2.6.7.
128

CONFORMING TO

130       This system call is Linux-specific.
131

NOTES

133       Process policy is not remembered if the page is swapped out.  When such
134       a  page is paged back in, it will use the policy of the process or mem‐
135       ory range that is in effect at the time the page is allocated.
136
137       For information on library support, see numa(7).
138

SEE ALSO

140       get_mempolicy(2), getcpu(2),  mbind(2),  mmap(2),  numa(3),  cpuset(7),
141       numa(7), numactl(8)
142

COLOPHON

144       This  page  is  part of release 3.53 of the Linux man-pages project.  A
145       description of the project, and information about reporting  bugs,  can
146       be found at http://www.kernel.org/doc/man-pages/.
147
148
149
150Linux                             2008-08-15                  SET_MEMPOLICY(2)
Impressum