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 2017-09-15 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 " flags );
46 Link with \fI\-lnuma\fP.
50 sets the NUMA memory policy,
51 which consists of a policy mode and zero or more nodes,
52 for the memory range starting with
57 The memory policy defines from which node memory is allocated.
59 If the memory range specified by the
61 arguments includes an "anonymous" region of memory\(emthat is
62 a region of memory created using the
65 .BR MAP_ANONYMOUS \(emor
66 a memory-mapped file, mapped using the
70 flag, pages will be allocated only according to the specified
71 policy when the application writes (stores) to the page.
72 For anonymous regions, an initial read access will use a shared
73 page in the kernel containing all zeros.
74 For a file mapped with
76 an initial read access will allocate pages according to the
77 memory policy of the thread that causes the page to be allocated.
78 This may not be the thread that called
81 The specified policy will be ignored for any
83 mappings in the specified memory range.
84 Rather the pages will be allocated according to the memory policy
85 of the thread that caused the page to be allocated.
86 Again, this may not be the thread that called
89 If the specified memory range includes a shared memory region
92 system call and attached using the
95 pages allocated for the anonymous or shared memory region will
96 be allocated according to the policy specified, regardless of which
97 process attached to the shared memory segment causes the allocation.
98 If, however, the shared memory region was created with the
101 the huge pages will be allocated according to the policy specified
102 only if the page allocation is caused by the process that calls
108 has an effect only for new allocations; if the pages inside
109 the range have been already touched before setting the policy,
110 then the policy has no effect.
111 This default behavior may be overridden by the
115 flags described below.
119 argument must specify one of
122 .BR MPOL_INTERLEAVE ,
126 (which are described in detail below).
127 All policy modes except
129 require the caller to specify the node or nodes to which the mode applies,
136 argument may also include an optional
142 .BR MPOL_F_STATIC_NODES " (since Linux-2.6.26)"
145 specifies physical node IDs.
146 Linux does not remap the
148 when the thread moves to a different cpuset context,
149 nor when the set of nodes allowed by the thread's
150 current cpuset context changes.
152 .BR MPOL_F_RELATIVE_NODES " (since Linux-2.6.26)"
155 specifies node IDs that are relative to the set of
156 node IDs allowed by the thread's current cpuset.
159 points to a bit mask of nodes containing up to
162 The bit mask size is rounded to the next multiple of
163 .IR "sizeof(unsigned long)" ,
164 but the kernel will use bits only up to
170 value of zero specifies the empty set of nodes.
179 is required, it must contain at least one node that is on-line,
180 allowed by the thread's current cpuset context
182 .B MPOL_F_STATIC_NODES
183 mode flag is specified),
188 argument must include one of the following values:
191 This mode requests that any nondefault policy be removed,
192 restoring default behavior.
193 When applied to a range of memory via
195 this means to use the thread memory policy,
196 which may have been set with
197 .BR set_mempolicy (2).
198 If the mode of the thread memory policy is also
200 the system-wide default policy will be used.
201 The system-wide default policy allocates
202 pages on the node of the CPU that triggers the allocation.
209 arguments must be specify the empty set of nodes.
212 This mode specifies a strict policy that restricts memory allocation to
213 the nodes specified in
217 specifies more than one node, page allocations will come from
218 the node with sufficient free memory that is closest to
219 the node where the allocation takes place.
220 Pages will not be allocated from any node not specified in the
222 (Before Linux 2.6.26,
223 .\" commit 19770b32609b6bf97a3dece2529089494cbfc549
224 page allocations came from
225 the node with the lowest numeric node ID first, until that node
226 contained no free memory.
227 Allocations then came from the node with the next highest
230 and so forth, until none of the specified nodes contained free memory.)
233 This mode specifies that page allocations be interleaved across the
234 set of nodes specified in
236 This optimizes for bandwidth instead of latency
237 by spreading out pages and memory accesses to those pages across
239 To be effective the memory area should be fairly large,
240 at least 1\ MB or bigger with a fairly uniform access pattern.
241 Accesses to a single page of the area will still be limited to
242 the memory bandwidth of a single node.
245 This mode sets the preferred node for allocation.
246 The kernel will try to allocate pages from this
247 node first and fall back to other nodes if the
248 preferred nodes is low on free memory.
251 specifies more than one node ID, the first node in the
252 mask will be selected as the preferred node.
257 arguments specify the empty set, then the memory is allocated on
258 the node of the CPU that triggered the allocation.
260 .BR MPOL_LOCAL " (since Linux 3.8)"
261 .\" commit 479e2802d09f1e18a97262c4c6f8f17ae5884bd8
262 .\" commit f2a07f40dbc603c15f8b06e6ec7f768af67b424f
263 This mode specifies "local allocation"; the memory is allocated on
264 the node of the CPU that triggered the allocation (the "local node").
269 arguments must specify the empty set.
270 If the "local node" is low on free memory,
271 the kernel will try to allocate memory from other nodes.
272 The kernel will allocate memory from the "local node"
273 whenever memory for this node is available.
274 If the "local node" is not allowed by the thread's current cpuset context,
275 the kernel will try to allocate memory from other nodes.
276 The kernel will allocate memory from the "local node" whenever
277 it becomes allowed by the thread's current cpuset context.
280 reverts to the memory policy of the thread (which may be set via
281 .BR set_mempolicy (2));
282 that policy may be something other than "local allocation".
292 then the call fails with the error
294 if the existing pages in the memory range don't follow the policy.
295 .\" According to the kernel code, the following is not true
296 .\" --Lee Schermerhorn
297 .\" In 2.6.16 or later the kernel will also try to move pages
298 .\" to the requested node with this flag.
304 then the kernel will attempt to move all the existing pages
305 in the memory range so that they follow the policy.
306 Pages that are shared with other processes will not be moved.
309 is also specified, then the call fails with the error
311 if some pages could not be moved.
317 then the kernel will attempt to move all existing pages in the memory range
318 regardless of whether other processes use the pages.
319 The calling thread must be privileged
324 is also specified, then the call fails with the error
326 if some pages could not be moved.
327 .\" ---------------------------------------------------------------
332 on error, \-1 is returned and
334 is set to indicate the error.
335 .\" ---------------------------------------------------------------
337 .\" I think I got all of the error returns. --Lee Schermerhorn
340 Part or all of the memory range specified by
344 points outside your accessible address space.
345 Or, there was an unmapped hole in the specified memory range specified by
351 An invalid value was specified for
361 is not a multiple of the system page size.
368 specified a nonempty set;
380 exceeds a kernel-imposed limit.
381 .\" As at 2.6.23, this limit is "a page worth of bits", e.g.,
382 .\" 8 * 4096 bits, assuming a 4kB page size.
385 specifies one or more node IDs that are
386 greater than the maximum supported node ID.
387 Or, none of the node IDs specified by
389 are on-line and allowed by the thread's current cpuset context,
390 or none of the specified nodes contain memory.
393 argument specified both
394 .B MPOL_F_STATIC_NODES
396 .BR MPOL_F_RELATIVE_NODES .
400 was specified and an existing page was already on a node
401 that does not follow the policy;
406 was specified and the kernel was unable to move all existing
410 Insufficient kernel memory was available.
415 argument included the
417 flag and the caller does not have the
420 .\" ---------------------------------------------------------------
424 system call was added to the Linux kernel in version 2.6.7.
426 This system call is Linux-specific.
428 For information on library support, see
431 NUMA policy is not supported on a memory-mapped file range
432 that was mapped with the
438 mode can have different effects for
441 .BR set_mempolicy (2).
445 .BR set_mempolicy (2),
446 the thread's memory policy reverts to the system default policy
450 is specified for a range of memory using
452 any pages subsequently allocated for that range will use
453 the thread's memory policy, as set by
454 .BR set_mempolicy (2).
455 This effectively removes the explicit policy from the
456 specified range, "falling back" to a possibly nondefault
458 To select explicit "local allocation" for a memory range,
465 with an empty set of nodes.
466 This method will work for
467 .BR set_mempolicy (2),
470 Support for huge page policy was added with 2.6.16.
471 For interleave policy to be effective on huge page mappings the
472 policied memory needs to be tens of megabytes or larger.
475 is ignored on huge page mappings.
480 are available only on Linux 2.6.16 and later.
482 .BR get_mempolicy (2),
485 .BR set_mempolicy (2),