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 the following, which need to be documented.
29 .\" And do they also apply for move_pages()?
32 .\" commit 479e2802d09f1e18a97262c4c6f8f17ae5884bd8
33 .\" Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
34 .\" Date: Thu Oct 25 14:16:28 2012 +0200
36 .\" commit f2a07f40dbc603c15f8b06e6ec7f768af67b424f
37 .\" Author: Hugh Dickins <hughd@google.com>
38 .\" Date: Wed Jan 2 02:01:33 2013 -0800
41 .\" commit b24f53a0bea38b266d219ee651b22dba727c44ae
42 .\" Author: Lee Schermerhorn <lee.schermerhorn@hp.com>
43 .\" Date: Thu Oct 25 14:16:32 2012 +0200
45 .TH MBIND 2 2015-01-22 Linux "Linux Programmer's Manual"
47 mbind \- set memory policy for a memory range
50 .B "#include <numaif.h>"
52 .BI "long mbind(void *" addr ", unsigned long " len ", int " mode ,
53 .BI " const unsigned long *" nodemask ", unsigned long " maxnode ,
54 .BI " unsigned " flags );
56 Link with \fI\-lnuma\fP.
60 sets the NUMA memory policy,
61 which consists of a policy mode and zero or more nodes,
62 for the memory range starting with
67 The memory policy defines from which node memory is allocated.
69 If the memory range specified by the
71 arguments includes an "anonymous" region of memory\(emthat is
72 a region of memory created using the
75 .BR MAP_ANONYMOUS \(emor
76 a memory-mapped file, mapped using the
80 flag, pages will be allocated only according to the specified
81 policy when the application writes [stores] to the page.
82 For anonymous regions, an initial read access will use a shared
83 page in the kernel containing all zeros.
84 For a file mapped with
86 an initial read access will allocate pages according to the
87 process policy of the process that causes the page to be allocated.
88 This may not be the process that called
91 The specified policy will be ignored for any
93 mappings in the specified memory range.
94 Rather the pages will be allocated according to the process policy
95 of the process that caused the page to be allocated.
96 Again, this may not be the process that called
99 If the specified memory range includes a shared memory region
102 system call and attached using the
105 pages allocated for the anonymous or shared memory region will
106 be allocated according to the policy specified, regardless which
107 process attached to the shared memory segment causes the allocation.
108 If, however, the shared memory region was created with the
111 the huge pages will be allocated according to the policy specified
112 only if the page allocation is caused by the process that calls
118 has an effect only for new allocations; if the pages inside
119 the range have been already touched before setting the policy,
120 then the policy has no effect.
121 This default behavior may be overridden by the
125 flags described below.
129 argument must specify one of
132 .BR MPOL_INTERLEAVE ,
135 All policy modes except
137 require the caller to specify via the
140 the node or nodes to which the mode applies.
144 argument may also include an optional
150 .BR MPOL_F_STATIC_NODES " (since Linux-2.6.26)"
153 specifies physical node ids.
154 Linux does not remap the
156 when the process moves to a different cpuset context,
157 nor when the set of nodes allowed by the process's
158 current cpuset context changes.
160 .BR MPOL_F_RELATIVE_NODES " (since Linux-2.6.26)"
163 specifies node ids that are relative to the set of
164 node ids allowed by the process's current cpuset.
167 points to a bit mask of nodes containing up to
170 The bit mask size is rounded to the next multiple of
171 .IR "sizeof(unsigned long)" ,
172 but the kernel will use bits only up to
178 value of zero specifies the empty set of nodes.
187 is required, it must contain at least one node that is on-line,
188 allowed by the process's current cpuset context
190 .B MPOL_F_STATIC_NODES
191 mode flag is specified],
196 mode requests that any nondefault policy be removed,
197 restoring default behavior.
198 When applied to a range of memory via
200 this means to use the process policy,
201 which may have been set with
202 .BR set_mempolicy (2).
203 If the mode of the process policy is also
205 the system-wide default policy will be used.
206 The system-wide default policy allocates
207 pages on the node of the CPU that triggers the allocation.
214 arguments must be specify the empty set of nodes.
218 mode specifies a strict policy that restricts memory allocation to
219 the nodes specified in
223 specifies more than one node, page allocations will come from
224 the node with the lowest numeric node ID first, until that node
225 contains no free memory.
226 Allocations will then come from the node with the next highest
229 and so forth, until none of the specified nodes contain free memory.
230 Pages will not be allocated from any node not specified in the
235 mode specifies that page allocations be interleaved across the
236 set of nodes specified in
238 This optimizes for bandwidth instead of latency
239 by spreading out pages and memory accesses to those pages across
241 To be effective the memory area should be fairly large,
242 at least 1MB or bigger with a fairly uniform access pattern.
243 Accesses to a single page of the area will still be limited to
244 the memory bandwidth of a single node.
247 sets the preferred node for allocation.
248 The kernel will try to allocate pages from this
249 node first and fall back to other nodes if the
250 preferred nodes is low on free memory.
253 specifies more than one node ID, the first node in the
254 mask will be selected as the preferred node.
259 arguments specify the empty set, then the memory is allocated on
260 the node of the CPU that triggered the allocation.
261 This is the only way to specify "local allocation" for a
273 then the call will fail with the error
275 if the existing pages in the memory range don't follow the policy.
276 .\" According to the kernel code, the following is not true
277 .\" --Lee Schermerhorn
278 .\" In 2.6.16 or later the kernel will also try to move pages
279 .\" to the requested node with this flag.
285 then the kernel will attempt to move all the existing pages
286 in the memory range so that they follow the policy.
287 Pages that are shared with other processes will not be moved.
290 is also specified, then the call will fail with the error
292 if some pages could not be moved.
298 then the kernel will attempt to move all existing pages in the memory range
299 regardless of whether other processes use the pages.
300 The calling process must be privileged
305 is also specified, then the call will fail with the error
307 if some pages could not be moved.
308 .\" ---------------------------------------------------------------
313 on error, \-1 is returned and
315 is set to indicate the error.
316 .\" ---------------------------------------------------------------
318 .\" I think I got all of the error returns. --Lee Schermerhorn
321 Part or all of the memory range specified by
325 points outside your accessible address space.
326 Or, there was an unmapped hole in the specified memory range specified by
332 An invalid value was specified for
342 is not a multiple of the system page size.
349 specified a nonempty set;
361 exceeds a kernel-imposed limit.
362 .\" As at 2.6.23, this limit is "a page worth of bits", e.g.,
363 .\" 8 * 4096 bits, assuming a 4kB page size.
366 specifies one or more node IDs that are
367 greater than the maximum supported node ID.
368 Or, none of the node IDs specified by
370 are on-line and allowed by the process's current cpuset context,
371 or none of the specified nodes contain memory.
374 argument specified both
375 .B MPOL_F_STATIC_NODES
377 .BR MPOL_F_RELATIVE_NODES .
381 was specified and an existing page was already on a node
382 that does not follow the policy;
387 was specified and the kernel was unable to move all existing
391 Insufficient kernel memory was available.
396 argument included the
398 flag and the caller does not have the
401 .\" ---------------------------------------------------------------
405 system call was added to the Linux kernel in version 2.6.7.
407 This system call is Linux-specific.
409 For information on library support, see
412 NUMA policy is not supported on a memory-mapped file range
413 that was mapped with the
419 mode can have different effects for
422 .BR set_mempolicy (2).
426 .BR set_mempolicy (2),
427 the process's policy reverts to system default policy
431 is specified for a range of memory using
433 any pages subsequently allocated for that range will use
434 the process's policy, as set by
435 .BR set_mempolicy (2).
436 This effectively removes the explicit policy from the
437 specified range, "falling back" to a possibly nondefault
439 To select explicit "local allocation" for a memory range,
444 with an empty set of nodes.
445 This method will work for
446 .BR set_mempolicy (2),
449 Support for huge page policy was added with 2.6.16.
450 For interleave policy to be effective on huge page mappings the
451 policied memory needs to be tens of megabytes or larger.
454 is ignored on huge page mappings.
459 are available only on Linux 2.6.16 and later.
461 .BR get_mempolicy (2),
464 .BR set_mempolicy (2),
472 This page is part of release 3.79 of the Linux
475 A description of the project,
476 information about reporting bugs,
477 and the latest version of this page,
479 \%http://www.kernel.org/doc/man\-pages/.