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.
28 .\" Linux 3.8 added MPOL_MF_LAZY, which needs to be documented.
29 .\" Does it also apply for move_pages()?
31 .\" commit b24f53a0bea38b266d219ee651b22dba727c44ae
32 .\" Author: Lee Schermerhorn <lee.schermerhorn@hp.com>
33 .\" Date: Thu Oct 25 14:16:32 2012 +0200
35 .TH MBIND 2 2021-03-22 Linux "Linux Programmer's Manual"
37 mbind \- set memory policy for a memory range
40 .B "#include <numaif.h>"
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 );
46 Link with \fI\-lnuma\fP.
50 There is no glibc wrapper for this system call; see NOTES.
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
60 The memory policy defines from which node memory is allocated.
62 If the memory range specified by the
64 arguments includes an "anonymous" region of memory\(emthat is
65 a region of memory created using the
68 .BR MAP_ANONYMOUS \(emor
69 a memory-mapped file, mapped using the
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
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
84 The specified policy will be ignored for any
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
92 If the specified memory range includes a shared memory region
95 system call and attached using the
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
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
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
118 flags described below.
122 argument must specify one of
125 .BR MPOL_INTERLEAVE ,
129 (which are described in detail below).
130 All policy modes except
132 require the caller to specify the node or nodes to which the mode applies,
139 argument may also include an optional
145 .BR MPOL_F_STATIC_NODES " (since Linux-2.6.26)"
148 specifies physical node IDs.
149 Linux does not remap the
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)"
158 specifies node IDs that are relative to the set of
159 node IDs allowed by the thread's current cpuset.
162 points to a bit mask of nodes containing up to
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
173 value of zero specifies the empty set of nodes.
182 is required, it must contain at least one node that is on-line,
183 allowed by the thread's current cpuset context
185 .B MPOL_F_STATIC_NODES
186 mode flag is specified),
191 argument must include one of the following values:
194 This mode requests that any nondefault policy be removed,
195 restoring default behavior.
196 When applied to a range of memory via
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
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.
212 arguments must be specify the empty set of nodes.
215 This mode specifies a strict policy that restricts memory allocation to
216 the nodes specified in
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
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
233 and so forth, until none of the specified nodes contained free memory.)
236 This mode specifies that page allocations be interleaved across the
237 set of nodes specified in
239 This optimizes for bandwidth instead of latency
240 by spreading out pages and memory accesses to those pages across
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.
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.
254 specifies more than one node ID, the first node in the
255 mask will be selected as the preferred node.
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").
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.
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".
295 then the call fails with the error
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.
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.
312 is also specified, then the call fails with the error
314 if some pages could not be moved.
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
327 is also specified, then the call fails with the error
329 if some pages could not be moved.
330 .\" ---------------------------------------------------------------
335 on error, \-1 is returned and
337 is set to indicate the error.
338 .\" ---------------------------------------------------------------
340 .\" I think I got all of the error returns. --Lee Schermerhorn
343 Part or all of the memory range specified by
347 points outside your accessible address space.
348 Or, there was an unmapped hole in the specified memory range specified by
354 An invalid value was specified for
364 is not a multiple of the system page size.
371 specified a nonempty set;
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.
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
392 are on-line and allowed by the thread's current cpuset context,
393 or none of the specified nodes contain memory.
396 argument specified both
397 .B MPOL_F_STATIC_NODES
399 .BR MPOL_F_RELATIVE_NODES .
403 was specified and an existing page was already on a node
404 that does not follow the policy;
409 was specified and the kernel was unable to move all existing
413 Insufficient kernel memory was available.
418 argument included the
420 flag and the caller does not have the
423 .\" ---------------------------------------------------------------
427 system call was added to the Linux kernel in version 2.6.7.
429 This system call is Linux-specific.
431 Glibc does not provide a wrapper for this system call.
432 For information on library support, see
435 NUMA policy is not supported on a memory-mapped file range
436 that was mapped with the
442 mode can have different effects for
445 .BR set_mempolicy (2).
449 .BR set_mempolicy (2),
450 the thread's memory policy reverts to the system default policy
454 is specified for a range of memory using
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
462 To select explicit "local allocation" for a memory range,
469 with an empty set of nodes.
470 This method will work for
471 .BR set_mempolicy (2),
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.
479 .\" commit dcf1763546d76c372f3136c8d6b2b6e77f140cf0
481 was ignored on huge page mappings.
486 are available only on Linux 2.6.16 and later.
488 .BR get_mempolicy (2),
491 .BR set_mempolicy (2),