1 .\" SPDX-License-Identifier: Linux-man-pages-copyleft-var
3 .\" Copyright 2003,2004 Andi Kleen, SuSE Labs.
4 .\" and Copyright 2007 Lee Schermerhorn, Hewlett Packard
6 .\" 2006-02-03, mtk, substantial wording changes and other improvements
7 .\" 2007-08-27, Lee Schermerhorn <Lee.Schermerhorn@hp.com>
8 .\" more precise specification of behavior.
10 .TH set_mempolicy 2 (date) "Linux man-pages (unreleased)"
12 set_mempolicy \- set default NUMA memory policy for a thread and its children
14 NUMA (Non-Uniform Memory Access) policy library
15 .RI ( libnuma ", " \-lnuma )
18 .B "#include <numaif.h>"
20 .BI "long set_mempolicy(int " mode ", const unsigned long *" nodemask ,
21 .BI " unsigned long " maxnode );
25 sets the NUMA memory policy of the calling thread,
26 which consists of a policy mode and zero or more nodes,
27 to the values specified by the
34 A NUMA machine has different
35 memory controllers with different distances to specific CPUs.
36 The memory policy defines from which node memory is allocated for
39 This system call defines the default policy for the thread.
40 The thread policy governs allocation of pages in the process's
41 address space outside of memory ranges
42 controlled by a more specific policy set by
44 The thread default policy also controls allocation of any pages for
45 memory-mapped files mapped using the
49 flag and that are only read (loaded) from by the thread
50 and of memory-mapped files mapped using the
54 flag, regardless of the access type.
55 The policy is applied only when a new page is allocated
57 For anonymous memory this is when the page is first
58 touched by the thread.
62 argument must specify one of
69 (which are described in detail below).
72 require the caller to specify the node or nodes to which the mode applies,
79 argument may also include an optional
85 .BR MPOL_F_NUMA_BALANCING " (since Linux 5.12)"
86 .\" commit bda420b985054a3badafef23807c4b4fa38a3dff
91 enable the kernel NUMA balancing for the task if it is supported by the kernel.
92 If the flag isn't supported by the kernel, or is used with
101 .BR MPOL_F_RELATIVE_NODES " (since Linux 2.6.26)"
104 specifies node IDs that are relative to the
105 set of node IDs allowed by the process's current cpuset.
107 .BR MPOL_F_STATIC_NODES " (since Linux 2.6.26)"
110 specifies physical node IDs.
111 Linux will not remap the
113 when the process moves to a different cpuset context,
114 nor when the set of nodes allowed by the process's
115 current cpuset context changes.
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"\[em]that 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
189 This mode interleaves page allocations across the nodes specified in
191 in numeric node ID order.
192 This optimizes for bandwidth instead of latency
193 by spreading out pages and memory accesses to those pages across
195 However, accesses to a single page will still be limited to
196 the memory bandwidth of a single node.
197 .\" NOTE: the following sentence doesn't make sense in the context
198 .\" of set_mempolicy() -- no memory area specified.
199 .\" To be effective the memory area should be fairly large,
200 .\" at least 1 MB or bigger.
203 This mode sets the preferred node for allocation.
204 The kernel will try to allocate pages from this node first
205 and fall back to "near by" nodes if the preferred node is low on free
209 specifies more than one node ID, the first node in the
210 mask will be selected as the preferred node.
215 arguments specify the empty set, then the policy
216 specifies "local allocation"
217 (like the system default policy discussed above).
219 .BR MPOL_LOCAL " (since Linux 3.8)"
220 .\" commit 479e2802d09f1e18a97262c4c6f8f17ae5884bd8
221 .\" commit f2a07f40dbc603c15f8b06e6ec7f768af67b424f
222 This mode specifies "local allocation"; the memory is allocated on
223 the node of the CPU that triggered the allocation (the "local node").
228 arguments must specify the empty set.
229 If the "local node" is low on free memory,
230 the kernel will try to allocate memory from other nodes.
231 The kernel will allocate memory from the "local node"
232 whenever memory for this node is available.
233 If the "local node" is not allowed by the process's current cpuset context,
234 the kernel will try to allocate memory from other nodes.
235 The kernel will allocate memory from the "local node" whenever
236 it becomes allowed by the process's current cpuset context.
238 The thread memory policy is preserved across an
240 and is inherited by child threads created using
248 on error, \-1 is returned and
250 is set to indicate the error.
254 Part of all of the memory range specified by
258 points outside your accessible address space.
281 specifies more than a page worth of bits.
284 specifies one or more node IDs that are
285 greater than the maximum supported node ID.
286 Or, none of the node IDs specified by
288 are on-line and allowed by the process's current cpuset context,
289 or none of the specified nodes contain memory.
292 argument specified both
293 .B MPOL_F_STATIC_NODES
295 .BR MPOL_F_RELATIVE_NODES .
297 .B MPOL_F_NUMA_BALANCING
298 isn't supported by the kernel, or is used with
304 Insufficient kernel memory was available.
310 Memory policy is not remembered if the page is swapped out.
311 When such a page is paged back in, it will use the policy of
312 the thread or memory range that is in effect at the time the
315 For information on library support, see
318 .BR get_mempolicy (2),