seccomp_unotify.2: tfix
[man-pages.git] / man2 / mbind.2
blobba1b81ae9ee11c6c8ed78511de56d8eba01acf87
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 .\" FIXME
28 .\" Linux 3.8 added MPOL_MF_LAZY, which needs to be documented.
29 .\" Does it also apply for move_pages()?
30 .\"
31 .\"                commit b24f53a0bea38b266d219ee651b22dba727c44ae
32 .\"                Author: Lee Schermerhorn <lee.schermerhorn@hp.com>
33 .\"                Date:   Thu Oct 25 14:16:32 2012 +0200
34 .\"
35 .TH MBIND 2 2021-03-22 Linux "Linux Programmer's Manual"
36 .SH NAME
37 mbind \- set memory policy for a memory range
38 .SH SYNOPSIS
39 .nf
40 .B "#include <numaif.h>"
41 .PP
42 .BI "long mbind(void *" addr ", unsigned long " len  ", int " mode ,
43 .BI "           const unsigned long *" nodemask  ", unsigned long " maxnode ,
44 .BI "           unsigned int " flags );
45 .PP
46 Link with \fI\-lnuma\fP.
47 .fi
48 .PP
49 .IR Note :
50 There is no glibc wrapper for this system call; see NOTES.
51 .SH DESCRIPTION
52 .BR mbind ()
53 sets the NUMA memory policy,
54 which consists of a policy mode and zero or more nodes,
55 for the memory range starting with
56 .I addr
57 and continuing for
58 .I len
59 bytes.
60 The memory policy defines from which node memory is allocated.
61 .PP
62 If the memory range specified by the
63 .IR addr " and " len
64 arguments includes an "anonymous" region of memory\(emthat is
65 a region of memory created using the
66 .BR mmap (2)
67 system call with the
68 .BR MAP_ANONYMOUS \(emor
69 a memory-mapped file, mapped using the
70 .BR mmap (2)
71 system call with the
72 .B MAP_PRIVATE
73 flag, pages will be allocated only according to the specified
74 policy when the application writes (stores) to the page.
75 For anonymous regions, an initial read access will use a shared
76 page in the kernel containing all zeros.
77 For a file mapped with
78 .BR MAP_PRIVATE ,
79 an initial read access will allocate pages according to the
80 memory policy of the thread that causes the page to be allocated.
81 This may not be the thread that called
82 .BR mbind ().
83 .PP
84 The specified policy will be ignored for any
85 .B MAP_SHARED
86 mappings in the specified memory range.
87 Rather the pages will be allocated according to the memory policy
88 of the thread that caused the page to be allocated.
89 Again, this may not be the thread that called
90 .BR mbind ().
91 .PP
92 If the specified memory range includes a shared memory region
93 created using the
94 .BR shmget (2)
95 system call and attached using the
96 .BR shmat (2)
97 system call,
98 pages allocated for the anonymous or shared memory region will
99 be allocated according to the policy specified, regardless of which
100 process attached to the shared memory segment causes the allocation.
101 If, however, the shared memory region was created with the
102 .B SHM_HUGETLB
103 flag,
104 the huge pages will be allocated according to the policy specified
105 only if the page allocation is caused by the process that calls
106 .BR mbind ()
107 for that region.
109 By default,
110 .BR mbind ()
111 has an effect only for new allocations; if the pages inside
112 the range have been already touched before setting the policy,
113 then the policy has no effect.
114 This default behavior may be overridden by the
115 .B MPOL_MF_MOVE
117 .B MPOL_MF_MOVE_ALL
118 flags described below.
121 .I mode
122 argument must specify one of
123 .BR MPOL_DEFAULT ,
124 .BR MPOL_BIND ,
125 .BR MPOL_INTERLEAVE ,
126 .BR MPOL_PREFERRED ,
128 .BR MPOL_LOCAL
129 (which are described in detail below).
130 All policy modes except
131 .B MPOL_DEFAULT
132 require the caller to specify the node or nodes to which the mode applies,
133 via the
134 .I nodemask
135 argument.
138 .I mode
139 argument may also include an optional
140 .IR "mode flag" .
141 The supported
142 .I "mode flags"
143 are:
145 .BR MPOL_F_STATIC_NODES " (since Linux-2.6.26)"
146 A nonempty
147 .I nodemask
148 specifies physical node IDs.
149 Linux does not remap the
150 .I nodemask
151 when the thread moves to a different cpuset context,
152 nor when the set of nodes allowed by the thread's
153 current cpuset context changes.
155 .BR MPOL_F_RELATIVE_NODES " (since Linux-2.6.26)"
156 A nonempty
157 .I nodemask
158 specifies node IDs that are relative to the set of
159 node IDs allowed by the thread's current cpuset.
161 .I nodemask
162 points to a bit mask of nodes containing up to
163 .I maxnode
164 bits.
165 The bit mask size is rounded to the next multiple of
166 .IR "sizeof(unsigned long)" ,
167 but the kernel will use bits only up to
168 .IR maxnode .
169 A NULL value of
170 .I nodemask
171 or a
172 .I maxnode
173 value of zero specifies the empty set of nodes.
174 If the value of
175 .I maxnode
176 is zero,
178 .I nodemask
179 argument is ignored.
180 Where a
181 .I nodemask
182 is required, it must contain at least one node that is on-line,
183 allowed by the thread's current cpuset context
184 (unless the
185 .B MPOL_F_STATIC_NODES
186 mode flag is specified),
187 and contains memory.
190 .I mode
191 argument must include one of the following values:
193 .B MPOL_DEFAULT
194 This mode requests that any nondefault policy be removed,
195 restoring default behavior.
196 When applied to a range of memory via
197 .BR mbind (),
198 this means to use the thread memory policy,
199 which may have been set with
200 .BR set_mempolicy (2).
201 If the mode of the thread memory policy is also
202 .BR MPOL_DEFAULT ,
203 the system-wide default policy will be used.
204 The system-wide default policy allocates
205 pages on the node of the CPU that triggers the allocation.
207 .BR MPOL_DEFAULT ,
209 .I nodemask
211 .I maxnode
212 arguments must be specify the empty set of nodes.
214 .B MPOL_BIND
215 This mode specifies a strict policy that restricts memory allocation to
216 the nodes specified in
217 .IR nodemask .
219 .I nodemask
220 specifies more than one node, page allocations will come from
221 the node with sufficient free memory that is closest to
222 the node where the allocation takes place.
223 Pages will not be allocated from any node not specified in the
224 IR nodemask .
225 (Before Linux 2.6.26,
226 .\" commit 19770b32609b6bf97a3dece2529089494cbfc549
227 page allocations came from
228 the node with the lowest numeric node ID first, until that node
229 contained no free memory.
230 Allocations then came from the node with the next highest
231 node ID specified in
232 .I nodemask
233 and so forth, until none of the specified nodes contained free memory.)
235 .B MPOL_INTERLEAVE
236 This mode specifies that page allocations be interleaved across the
237 set of nodes specified in
238 .IR nodemask .
239 This optimizes for bandwidth instead of latency
240 by spreading out pages and memory accesses to those pages across
241 multiple nodes.
242 To be effective the memory area should be fairly large,
243 at least 1\ MB or bigger with a fairly uniform access pattern.
244 Accesses to a single page of the area will still be limited to
245 the memory bandwidth of a single node.
247 .B MPOL_PREFERRED
248 This mode sets the preferred node for allocation.
249 The kernel will try to allocate pages from this
250 node first and fall back to other nodes if the
251 preferred nodes is low on free memory.
253 .I nodemask
254 specifies more than one node ID, the first node in the
255 mask will be selected as the preferred node.
256 If the
257 .I nodemask
259 .I maxnode
260 arguments specify the empty set, then the memory is allocated on
261 the node of the CPU that triggered the allocation.
263 .BR MPOL_LOCAL " (since Linux 3.8)"
264 .\" commit 479e2802d09f1e18a97262c4c6f8f17ae5884bd8
265 .\" commit f2a07f40dbc603c15f8b06e6ec7f768af67b424f
266 This mode specifies "local allocation"; the memory is allocated on
267 the node of the CPU that triggered the allocation (the "local node").
269 .I nodemask
271 .I maxnode
272 arguments must specify the empty set.
273 If the "local node" is low on free memory,
274 the kernel will try to allocate memory from other nodes.
275 The kernel will allocate memory from the "local node"
276 whenever memory for this node is available.
277 If the "local node" is not allowed by the thread's current cpuset context,
278 the kernel will try to allocate memory from other nodes.
279 The kernel will allocate memory from the "local node" whenever
280 it becomes allowed by the thread's current cpuset context.
281 By contrast,
282 .B MPOL_DEFAULT
283 reverts to the memory policy of the thread (which may be set via
284 .BR set_mempolicy (2));
285 that policy may be something other than "local allocation".
288 .B MPOL_MF_STRICT
289 is passed in
290 .I flags
292 .I mode
293 is not
294 .BR MPOL_DEFAULT ,
295 then the call fails with the error
296 .B EIO
297 if the existing pages in the memory range don't follow the policy.
298 .\" According to the kernel code, the following is not true
299 .\" --Lee Schermerhorn
300 .\" In 2.6.16 or later the kernel will also try to move pages
301 .\" to the requested node with this flag.
304 .B MPOL_MF_MOVE
305 is specified in
306 .IR flags ,
307 then the kernel will attempt to move all the existing pages
308 in the memory range so that they follow the policy.
309 Pages that are shared with other processes will not be moved.
311 .B MPOL_MF_STRICT
312 is also specified, then the call fails with the error
313 .B EIO
314 if some pages could not be moved.
317 .B MPOL_MF_MOVE_ALL
318 is passed in
319 .IR flags ,
320 then the kernel will attempt to move all existing pages in the memory range
321 regardless of whether other processes use the pages.
322 The calling thread must be privileged
323 .RB ( CAP_SYS_NICE )
324 to use this flag.
326 .B MPOL_MF_STRICT
327 is also specified, then the call fails with the error
328 .B EIO
329 if some pages could not be moved.
330 .\" ---------------------------------------------------------------
331 .SH RETURN VALUE
332 On success,
333 .BR mbind ()
334 returns 0;
335 on error, \-1 is returned and
336 .I errno
337 is set to indicate the error.
338 .\" ---------------------------------------------------------------
339 .SH ERRORS
340 .\"  I think I got all of the error returns.  --Lee Schermerhorn
342 .B EFAULT
343 Part or all of the memory range specified by
344 .I nodemask
346 .I maxnode
347 points outside your accessible address space.
348 Or, there was an unmapped hole in the specified memory range specified by
349 .IR addr
351 .IR len .
353 .B EINVAL
354 An invalid value was specified for
355 .I flags
357 .IR mode ;
359 .I addr + len
360 was less than
361 .IR addr ;
363 .I addr
364 is not a multiple of the system page size.
366 .I mode
368 .B MPOL_DEFAULT
370 .I nodemask
371 specified a nonempty set;
373 .I mode
375 .B MPOL_BIND
377 .B MPOL_INTERLEAVE
379 .I nodemask
380 is empty.
382 .I maxnode
383 exceeds a kernel-imposed limit.
384 .\" As at 2.6.23, this limit is "a page worth of bits", e.g.,
385 .\" 8 * 4096 bits, assuming a 4kB page size.
387 .I nodemask
388 specifies one or more node IDs that are
389 greater than the maximum supported node ID.
390 Or, none of the node IDs specified by
391 .I nodemask
392 are on-line and allowed by the thread's current cpuset context,
393 or none of the specified nodes contain memory.
394 Or, the
395 .I mode
396 argument specified both
397 .B MPOL_F_STATIC_NODES
399 .BR MPOL_F_RELATIVE_NODES .
401 .B EIO
402 .B MPOL_MF_STRICT
403 was specified and an existing page was already on a node
404 that does not follow the policy;
406 .B MPOL_MF_MOVE
408 .B MPOL_MF_MOVE_ALL
409 was specified and the kernel was unable to move all existing
410 pages in the range.
412 .B ENOMEM
413 Insufficient kernel memory was available.
415 .B EPERM
417 .I flags
418 argument included the
419 .B MPOL_MF_MOVE_ALL
420 flag and the caller does not have the
421 .B CAP_SYS_NICE
422 privilege.
423 .\" ---------------------------------------------------------------
424 .SH VERSIONS
426 .BR mbind ()
427 system call was added to the Linux kernel in version 2.6.7.
428 .SH CONFORMING TO
429 This system call is Linux-specific.
430 .SH NOTES
431 Glibc does not provide a wrapper for this system call.
432 For information on library support, see
433 .BR numa (7).
435 NUMA policy is not supported on a memory-mapped file range
436 that was mapped with the
437 .B MAP_SHARED
438 flag.
441 .B MPOL_DEFAULT
442 mode can have different effects for
443 .BR mbind ()
445 .BR set_mempolicy (2).
446 When
447 .B MPOL_DEFAULT
448 is specified for
449 .BR set_mempolicy (2),
450 the thread's memory policy reverts to the system default policy
451 or local allocation.
452 When
453 .B MPOL_DEFAULT
454 is specified for a range of memory using
455 .BR mbind (),
456 any pages subsequently allocated for that range will use
457 the thread's memory policy, as set by
458 .BR set_mempolicy (2).
459 This effectively removes the explicit policy from the
460 specified range, "falling back" to a possibly nondefault
461 policy.
462 To select explicit "local allocation" for a memory range,
463 specify a
464 .I mode
466 .B MPOL_LOCAL
468 .B MPOL_PREFERRED
469 with an empty set of nodes.
470 This method will work for
471 .BR set_mempolicy (2),
472 as well.
474 Support for huge page policy was added with 2.6.16.
475 For interleave policy to be effective on huge page mappings the
476 policied memory needs to be tens of megabytes or larger.
478 Before Linux 5.7.
479 .\" commit dcf1763546d76c372f3136c8d6b2b6e77f140cf0
480 .B MPOL_MF_STRICT
481 was ignored on huge page mappings.
483 .B MPOL_MF_MOVE
485 .B MPOL_MF_MOVE_ALL
486 are available only on Linux 2.6.16 and later.
487 .SH SEE ALSO
488 .BR get_mempolicy (2),
489 .BR getcpu (2),
490 .BR mmap (2),
491 .BR set_mempolicy (2),
492 .BR shmat (2),
493 .BR shmget (2),
494 .BR numa (3),
495 .BR cpuset (7),
496 .BR numa (7),
497 .BR numactl (8)