tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man2 / set_mempolicy.2
blob844fa08393d8c6df7d2e66ef558a27c44e6fb74b
1 .\" Copyright 2003,2004 Andi Kleen, SuSE Labs.
2 .\" and Copyright 2007 Lee Schermerhorn, Hewlett Packard
3 .\"
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.
8 .\"
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.
13 .\"
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.
18 .\"
19 .\" Formatted or processed versions of this manual, if unaccompanied by
20 .\" the source, must acknowledge the copyright and authors of this work.
21 .\" %%%LICENSE_END
22 .\"
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.
26 .\"
27 .TH set_mempolicy 2 (date) "Linux man-pages (unreleased)"
28 .SH NAME
29 set_mempolicy \- set default NUMA memory policy for a thread and its children
30 .SH LIBRARY
31 NUMA (Non-Uniform Memory Access) policy library
32 .RI ( libnuma ", " \-lnuma )
33 .SH SYNOPSIS
34 .nf
35 .B "#include <numaif.h>"
36 .PP
37 .BI "long set_mempolicy(int " mode ", const unsigned long *" nodemask ,
38 .BI "                   unsigned long " maxnode );
39 .fi
40 .SH DESCRIPTION
41 .BR set_mempolicy ()
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
45 .IR mode ,
46 .IR nodemask ,
47 and
48 .I maxnode
49 arguments.
50 .PP
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
54 the thread.
55 .PP
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
60 .BR mbind (2).
61 The thread default policy also controls allocation of any pages for
62 memory-mapped files mapped using the
63 .BR mmap (2)
64 call with the
65 .B MAP_PRIVATE
66 flag and that are only read (loaded) from by the thread
67 and of memory-mapped files mapped using the
68 .BR mmap (2)
69 call with the
70 .B MAP_SHARED
71 flag, regardless of the access type.
72 The policy is applied only when a new page is allocated
73 for the thread.
74 For anonymous memory this is when the page is first
75 touched by the thread.
76 .PP
77 The
78 .I mode
79 argument must specify one of
80 .BR MPOL_DEFAULT ,
81 .BR MPOL_BIND ,
82 .BR MPOL_INTERLEAVE ,
83 .BR MPOL_PREFERRED ,
85 .B MPOL_LOCAL
86 (which are described in detail below).
87 All modes except
88 .B MPOL_DEFAULT
89 require the caller to specify the node or nodes to which the mode applies,
90 via the
91 .I nodemask
92 argument.
93 .PP
94 The
95 .I mode
96 argument may also include an optional
97 .IR "mode flag" .
98 The supported
99 .I "mode flags"
100 are:
102 .BR MPOL_F_NUMA_BALANCING " (since Linux 5.12)"
103 .\" commit bda420b985054a3badafef23807c4b4fa38a3dff
104 When
105 .I mode
107 .BR MPOL_BIND ,
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
110 .I mode
111 other than
112 .BR MPOL_BIND ,
113 \-1 is returned and
114 .I errno
115 is set to
116 .BR EINVAL .
118 .BR MPOL_F_RELATIVE_NODES " (since Linux 2.6.26)"
119 A nonempty
120 .I nodemask
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)"
125 A nonempty
126 .I nodemask
127 specifies physical node IDs.
128 Linux will not remap the
129 .I nodemask
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.
134 .I nodemask
135 points to a bit mask of node IDs that contains up to
136 .I maxnode
137 bits.
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
141 .IR maxnode .
142 A NULL value of
143 .I nodemask
144 or a
145 .I maxnode
146 value of zero specifies the empty set of nodes.
147 If the value of
148 .I maxnode
149 is zero,
151 .I nodemask
152 argument is ignored.
154 Where a
155 .I nodemask
156 is required, it must contain at least one node that is on-line,
157 allowed by the process's current cpuset context,
158 (unless the
159 .B MPOL_F_STATIC_NODES
160 mode flag is specified),
161 and contains memory.
162 If the
163 .B MPOL_F_STATIC_NODES
164 is set in
165 .I mode
166 and a required
167 .I nodemask
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
173 .IR nodemask .
176 .I mode
177 argument must include one of the following values:
179 .B MPOL_DEFAULT
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"\[em]that is,
183 allocate memory on the node of the CPU that triggered the allocation.
184 .I nodemask
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.
189 .B MPOL_BIND
190 This mode defines a strict policy that restricts memory allocation to the
191 nodes specified in
192 .IR nodemask .
194 .I nodemask
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
199 node ID specified in
200 .I nodemask
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
203 .IR nodemask .
205 .B MPOL_INTERLEAVE
206 This mode interleaves page allocations across the nodes specified in
207 .I nodemask
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
211 multiple nodes.
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.
219 .B MPOL_PREFERRED
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
223 memory.
225 .I nodemask
226 specifies more than one node ID, the first node in the
227 mask will be selected as the preferred node.
228 If the
229 .I nodemask
231 .I maxnode
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").
242 .I nodemask
244 .I maxnode
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
256 .BR execve (2),
257 and is inherited by child threads created using
258 .BR fork (2)
260 .BR clone (2).
261 .SH RETURN VALUE
262 On success,
263 .BR set_mempolicy ()
264 returns 0;
265 on error, \-1 is returned and
266 .I errno
267 is set to indicate the error.
268 .SH ERRORS
270 .B EFAULT
271 Part of all of the memory range specified by
272 .I nodemask
274 .I maxnode
275 points outside your accessible address space.
277 .B EINVAL
278 .I mode
279 is invalid.
281 .I mode
283 .B MPOL_DEFAULT
285 .I nodemask
286 is nonempty,
288 .I mode
290 .B MPOL_BIND
292 .B MPOL_INTERLEAVE
294 .I nodemask
295 is empty.
297 .I maxnode
298 specifies more than a page worth of bits.
300 .I nodemask
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
304 .I nodemask
305 are on-line and allowed by the process's current cpuset context,
306 or none of the specified nodes contain memory.
307 Or, the
308 .I mode
309 argument specified both
310 .B MPOL_F_STATIC_NODES
312 .BR MPOL_F_RELATIVE_NODES .
313 Or, the
314 .B MPOL_F_NUMA_BALANCING
315 isn't supported by the kernel, or is used with
316 .I mode
317 other than
318 .BR MPOL_BIND .
320 .B ENOMEM
321 Insufficient kernel memory was available.
322 .SH VERSIONS
324 .BR set_mempolicy ()
325 system call was added in Linux 2.6.7.
326 .SH STANDARDS
327 This system call is Linux-specific.
328 .SH NOTES
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
332 page is allocated.
334 For information on library support, see
335 .BR numa (7).
336 .SH SEE ALSO
337 .BR get_mempolicy (2),
338 .BR getcpu (2),
339 .BR mbind (2),
340 .BR mmap (2),
341 .BR numa (3),
342 .BR cpuset (7),
343 .BR numa (7),
344 .BR numactl (8)