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 2021-06-20 Linux "Linux Programmer's Manual"
29 set_mempolicy \- set default NUMA memory policy for a thread and its children
31 NUMA (Non-Uniform Memory Access) policy library
32 .RI ( libnuma ", " \-lnuma )
35 .B "#include <numaif.h>"
37 .BI "long set_mempolicy(int " mode ", const unsigned long *" nodemask ,
38 .BI " unsigned long " maxnode );
42 sets the NUMA memory policy of the calling thread,
43 which consists of a policy mode and zero or more nodes,
44 to the values specified by the
51 A NUMA machine has different
52 memory controllers with different distances to specific CPUs.
53 The memory policy defines from which node memory is allocated for
56 This system call defines the default policy for the thread.
57 The thread policy governs allocation of pages in the process's
58 address space outside of memory ranges
59 controlled by a more specific policy set by
61 The thread default policy also controls allocation of any pages for
62 memory-mapped files mapped using the
66 flag and that are only read (loaded) from by the thread
67 and of memory-mapped files mapped using the
71 flag, regardless of the access type.
72 The policy is applied only when a new page is allocated
74 For anonymous memory this is when the page is first
75 touched by the thread.
79 argument must specify one of
86 (which are described in detail below).
89 require the caller to specify the node or nodes to which the mode applies,
96 argument may also include an optional
102 .BR MPOL_F_NUMA_BALANCING " (since Linux 5.12)"
103 .\" commit bda420b985054a3badafef23807c4b4fa38a3dff
108 enable the kernel NUMA balancing for the task if it is supported by the kernel.
109 If the flag isn't supported by the kernel, or is used with
118 .BR MPOL_F_RELATIVE_NODES " (since Linux 2.6.26)"
121 specifies node IDs that are relative to the
122 set of node IDs allowed by the process's current cpuset.
124 .BR MPOL_F_STATIC_NODES " (since Linux 2.6.26)"
127 specifies physical node IDs.
128 Linux will not remap the
130 when the process moves to a different cpuset context,
131 nor when the set of nodes allowed by the process's
132 current cpuset context changes.
135 points to a bit mask of node IDs that contains up to
138 The bit mask size is rounded to the next multiple of
139 .IR "sizeof(unsigned long)" ,
140 but the kernel will use bits only up to
146 value of zero specifies the empty set of nodes.
156 is required, it must contain at least one node that is on-line,
157 allowed by the process's current cpuset context,
159 .B MPOL_F_STATIC_NODES
160 mode flag is specified),
163 .B MPOL_F_STATIC_NODES
168 contains no nodes that are allowed by the process's current cpuset context,
169 the memory policy reverts to
170 .IR "local allocation" .
171 This effectively overrides the specified policy until the process's
172 cpuset context includes one or more of the nodes specified by
177 argument must include one of the following values:
180 This mode specifies that any nondefault thread memory policy be removed,
181 so that the memory policy "falls back" to the system default policy.
182 The system default policy is "local allocation"\(emthat is,
183 allocate memory on the node of the CPU that triggered the allocation.
185 must be specified as NULL.
186 If the "local node" contains no free memory, the system will
187 attempt to allocate memory from a "near by" node.
190 This mode defines a strict policy that restricts memory allocation to the
195 specifies more than one node, page allocations will come from
196 the node with the lowest numeric node ID first, until that node
197 contains no free memory.
198 Allocations will then come from the node with the next highest
201 and so forth, until none of the specified nodes contain free memory.
202 Pages will not be allocated from any node not specified in the
206 This mode interleaves page allocations across the nodes specified in
208 in numeric node ID order.
209 This optimizes for bandwidth instead of latency
210 by spreading out pages and memory accesses to those pages across
212 However, accesses to a single page will still be limited to
213 the memory bandwidth of a single node.
214 .\" NOTE: the following sentence doesn't make sense in the context
215 .\" of set_mempolicy() -- no memory area specified.
216 .\" To be effective the memory area should be fairly large,
217 .\" at least 1 MB or bigger.
220 This mode sets the preferred node for allocation.
221 The kernel will try to allocate pages from this node first
222 and fall back to "near by" nodes if the preferred node is low on free
226 specifies more than one node ID, the first node in the
227 mask will be selected as the preferred node.
232 arguments specify the empty set, then the policy
233 specifies "local allocation"
234 (like the system default policy discussed above).
236 .BR MPOL_LOCAL " (since Linux 3.8)"
237 .\" commit 479e2802d09f1e18a97262c4c6f8f17ae5884bd8
238 .\" commit f2a07f40dbc603c15f8b06e6ec7f768af67b424f
239 This mode specifies "local allocation"; the memory is allocated on
240 the node of the CPU that triggered the allocation (the "local node").
245 arguments must specify the empty set.
246 If the "local node" is low on free memory,
247 the kernel will try to allocate memory from other nodes.
248 The kernel will allocate memory from the "local node"
249 whenever memory for this node is available.
250 If the "local node" is not allowed by the process's current cpuset context,
251 the kernel will try to allocate memory from other nodes.
252 The kernel will allocate memory from the "local node" whenever
253 it becomes allowed by the process's current cpuset context.
255 The thread memory policy is preserved across an
257 and is inherited by child threads created using
265 on error, \-1 is returned and
267 is set to indicate the error.
271 Part of all of the memory range specified by
275 points outside your accessible address space.
298 specifies more than a page worth of bits.
301 specifies one or more node IDs that are
302 greater than the maximum supported node ID.
303 Or, none of the node IDs specified by
305 are on-line and allowed by the process's current cpuset context,
306 or none of the specified nodes contain memory.
309 argument specified both
310 .B MPOL_F_STATIC_NODES
312 .BR MPOL_F_RELATIVE_NODES .
314 .B MPOL_F_NUMA_BALANCING
315 isn't supported by the kernel, or is used with
321 Insufficient kernel memory was available.
325 system call was added to the Linux kernel in version 2.6.7.
327 This system call is Linux-specific.
329 Memory policy is not remembered if the page is swapped out.
330 When such a page is paged back in, it will use the policy of
331 the thread or memory range that is in effect at the time the
334 For information on library support, see
337 .BR get_mempolicy (2),