1 .\" Copyright 2003,2004 Andi Kleen, SuSE Labs.
2 .\" and Copyright 2007 Lee Schermerhorn, Hewlett Packard
4 .\" %%%LICENSE_START(VERBATIM_PROF)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.
19 .\" Formatted or processed versions of this manual, if unaccompanied by
20 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" 2006-02-03, mtk, substantial wording changes and other improvements
24 .\" 2007-08-27, Lee Schermerhorn <Lee.Schermerhorn@hp.com>
25 .\" more precise specification of behavior.
27 .TH SET_MEMPOLICY 2 2017-09-15 Linux "Linux Programmer's Manual"
29 set_mempolicy \- set default NUMA memory policy for a thread and its children
32 .B "#include <numaif.h>"
34 .BI "long set_mempolicy(int " mode ", const unsigned long *" nodemask ,
35 .BI " unsigned long " maxnode );
37 Link with \fI\-lnuma\fP.
41 sets the NUMA memory policy of the calling thread,
42 which consists of a policy mode and zero or more nodes,
43 to the values specified by the
50 A NUMA machine has different
51 memory controllers with different distances to specific CPUs.
52 The memory policy defines from which node memory is allocated for
55 This system call defines the default policy for the thread.
56 The thread policy governs allocation of pages in the process's
57 address space outside of memory ranges
58 controlled by a more specific policy set by
60 The thread default policy also controls allocation of any pages for
61 memory-mapped files mapped using the
65 flag and that are only read (loaded) from by the thread
66 and of memory-mapped files mapped using the
70 flag, regardless of the access type.
71 The policy is applied only when a new page is allocated
73 For anonymous memory this is when the page is first
74 touched by the thread.
78 argument must specify one of
85 (which are described in detail below).
88 require the caller to specify the node or nodes to which the mode applies,
95 argument may also include an optional
101 .BR MPOL_F_STATIC_NODES " (since Linux 2.6.26)"
104 specifies physical node IDs.
105 Linux will not remap the
107 when the process moves to a different cpuset context,
108 nor when the set of nodes allowed by the process's
109 current cpuset context changes.
111 .BR MPOL_F_RELATIVE_NODES " (since Linux 2.6.26)"
114 specifies node IDs that are relative to the set of
115 node IDs allowed by the process's current cpuset.
118 points to a bit mask of node IDs that contains up to
121 The bit mask size is rounded to the next multiple of
122 .IR "sizeof(unsigned long)" ,
123 but the kernel will use bits only up to
129 value of zero specifies the empty set of nodes.
139 is required, it must contain at least one node that is on-line,
140 allowed by the process's current cpuset context,
142 .B MPOL_F_STATIC_NODES
143 mode flag is specified),
146 .B MPOL_F_STATIC_NODES
151 contains no nodes that are allowed by the process's current cpuset context,
152 the memory policy reverts to
153 .IR "local allocation" .
154 This effectively overrides the specified policy until the process's
155 cpuset context includes one or more of the nodes specified by
160 argument must include one of the following values:
163 This mode specifies that any nondefault thread memory policy be removed,
164 so that the memory policy "falls back" to the system default policy.
165 The system default policy is "local allocation"\(emthat is,
166 allocate memory on the node of the CPU that triggered the allocation.
168 must be specified as NULL.
169 If the "local node" contains no free memory, the system will
170 attempt to allocate memory from a "near by" node.
173 This mode defines a strict policy that restricts memory allocation to the
178 specifies more than one node, page allocations will come from
179 the node with the lowest numeric node ID first, until that node
180 contains no free memory.
181 Allocations will then come from the node with the next highest
184 and so forth, until none of the specified nodes contain free memory.
185 Pages will not be allocated from any node not specified in the
190 This mode interleaves page allocations across the nodes specified in
192 in numeric node ID order.
193 This optimizes for bandwidth instead of latency
194 by spreading out pages and memory accesses to those pages across
196 However, accesses to a single page will still be limited to
197 the memory bandwidth of a single node.
198 .\" NOTE: the following sentence doesn't make sense in the context
199 .\" of set_mempolicy() -- no memory area specified.
200 .\" To be effective the memory area should be fairly large,
201 .\" at least 1 MB or bigger.
204 This mode sets the preferred node for allocation.
205 The kernel will try to allocate pages from this node first
206 and fall back to "near by" nodes if the preferred node is low on free
210 specifies more than one node ID, the first node in the
211 mask will be selected as the preferred node.
216 arguments specify the empty set, then the policy
217 specifies "local allocation"
218 (like the system default policy discussed above).
220 .BR MPOL_LOCAL " (since Linux 3.8)"
221 .\" commit 479e2802d09f1e18a97262c4c6f8f17ae5884bd8
222 .\" commit f2a07f40dbc603c15f8b06e6ec7f768af67b424f
223 This mode specifies "local allocation"; the memory is allocated on
224 the node of the CPU that triggered the allocation (the "local node").
229 arguments must specify the empty set.
230 If the "local node" is low on free memory,
231 the kernel will try to allocate memory from other nodes.
232 The kernel will allocate memory from the "local node"
233 whenever memory for this node is available.
234 If the "local node" is not allowed by the process's current cpuset context,
235 the kernel will try to allocate memory from other nodes.
236 The kernel will allocate memory from the "local node" whenever
237 it becomes allowed by the process's current cpuset context.
239 The thread memory policy is preserved across an
241 and is inherited by child threads created using
249 on error, \-1 is returned and
251 is set to indicate the error.
255 Part of all of the memory range specified by
259 points outside your accessible address space.
282 specifies more than a page worth of bits.
285 specifies one or more node IDs that are
286 greater than the maximum supported node ID.
287 Or, none of the node IDs specified by
289 are on-line and allowed by the process's current cpuset context,
290 or none of the specified nodes contain memory.
293 argument specified both
294 .B MPOL_F_STATIC_NODES
296 .BR MPOL_F_RELATIVE_NODES .
299 Insufficient kernel memory was available.
303 system call was added to the Linux kernel in version 2.6.7.
305 This system call is Linux-specific.
307 Memory policy is not remembered if the page is swapped out.
308 When such a page is paged back in, it will use the policy of
309 the thread or memory range that is in effect at the time the
312 For information on library support, see
315 .BR get_mempolicy (2),