1 .\" Copyright 2003,2004 Andi Kleen, SuSE Labs.
2 .\" and Copyright 2007 Lee Schermerhorn, Hewlett Packard
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.
18 .\" Formatted or processed versions of this manual, if unaccompanied by
19 .\" the source, must acknowledge the copyright and authors of this work.
21 .\" 2006-02-03, mtk, substantial wording changes and other improvements
22 .\" 2007-08-27, Lee Schermerhorn <Lee.Schermerhorn@hp.com>
23 .\" more precise specification of behavior.
25 .TH MBIND 2 2008-08-15 Linux "Linux Programmer's Manual"
27 mbind \- Set memory policy for a memory range
30 .B "#include <numaif.h>"
32 .BI "int mbind(void *" addr ", unsigned long " len ", int " mode ,
33 .BI " unsigned long *" nodemask ", unsigned long " maxnode ,
34 .BI " unsigned " flags );
36 Link with \fI\-lnuma\fP.
40 sets the NUMA memory policy,
41 which consists of a policy mode and zero or more nodes,
42 for the memory range starting with
47 The memory policy defines from which node memory is allocated.
49 If the memory range specified by the
51 arguments includes an "anonymous" region of memory\(emthat is
52 a region of memory created using the
55 .BR MAP_ANONYMOUS \(emor
56 a memory mapped file, mapped using the
60 flag, pages will only be allocated according to the specified
61 policy when the application writes [stores] to the page.
62 For anonymous regions, an initial read access will use a shared
63 page in the kernel containing all zeros.
64 For a file mapped with
66 an initial read access will allocate pages according to the
67 process policy of the process that causes the page to be allocated.
68 This may not be the process that called
71 The specified policy will be ignored for any
73 mappings in the specified memory range.
74 Rather the pages will be allocated according to the process policy
75 of the process that caused the page to be allocated.
76 Again, this may not be the process that called
79 If the specified memory range includes a shared memory region
82 system call and attached using the
85 pages allocated for the anonymous or shared memory region will
86 be allocated according to the policy specified, regardless which
87 process attached to the shared memory segment causes the allocation.
88 If, however, the shared memory region was created with the
91 the huge pages will be allocated according to the policy specified
92 only if the page allocation is caused by the process that calls
98 only has an effect for new allocations; if the pages inside
99 the range have been already touched before setting the policy,
100 then the policy has no effect.
101 This default behavior may be overridden by the
105 flags described below.
109 argument must specify one of
115 All policy modes except
117 require the caller to specify via the
120 the node or nodes to which the mode applies.
124 argument may also include an optional
130 .BR MPOL_F_STATIC_NODES " (since Linux-2.6.26)"
133 specifies physical node ids.
134 Linux does not remap the
136 when the process moves to a different cpuset context,
137 nor when the set of nodes allowed by the process's
138 current cpuset context changes.
140 .BR MPOL_F_RELATIVE_NODES " (since Linux-2.6.26)"
143 specifies node ids that are relative to the set of
144 node ids allowed by the process's current cpuset.
147 points to a bitmask of nodes containing up to
150 The bit mask size is rounded to the next multiple of
151 .IR "sizeof(unsigned long)" ,
152 but the kernel will only use bits up to
158 value of zero specifies the empty set of nodes.
167 is required, it must contain at least one node that is on-line,
168 allowed by the process's current cpuset context
170 .B MPOL_F_STATIC_NODES
171 mode flag is specified],
176 mode requests that any nondefault policy be removed,
177 restoring default behavior.
178 When applied to a range of memory via
180 this means to use the process policy,
181 which may have been set with
182 .BR set_mempolicy (2).
183 If the mode of the process policy is also
185 the system-wide default policy will be used.
186 The system-wide default policy allocates
187 pages on the node of the CPU that triggers the allocation.
194 arguments must be specify the empty set of nodes.
198 mode specifies a strict policy that restricts memory allocation to
199 the nodes specified in
203 specifies more than one node, page allocations will come from
204 the node with the lowest numeric node ID first, until that node
205 contains no free memory.
206 Allocations will then come from the node with the next highest
209 and so forth, until none of the specified nodes contain free memory.
210 Pages will not be allocated from any node not specified in the
215 mode specifies that page allocations be interleaved across the
216 set of nodes specified in
218 This optimizes for bandwidth instead of latency
219 by spreading out pages and memory accesses to those pages across
221 To be effective the memory area should be fairly large,
222 at least 1MB or bigger with a fairly uniform access pattern.
223 Accesses to a single page of the area will still be limited to
224 the memory bandwidth of a single node.
227 sets the preferred node for allocation.
228 The kernel will try to allocate pages from this
229 node first and fall back to other nodes if the
230 preferred nodes is low on free memory.
233 specifies more than one node ID, the first node in the
234 mask will be selected as the preferred node.
239 arguments specify the empty set, then the memory is allocated on
240 the node of the CPU that triggered the allocation.
241 This is the only way to specify "local allocation" for a
253 then the call will fail with the error
255 if the existing pages in the memory range don't follow the policy.
256 .\" According to the kernel code, the following is not true
257 .\" --Lee Schermerhorn
258 .\" In 2.6.16 or later the kernel will also try to move pages
259 .\" to the requested node with this flag.
265 then the kernel will attempt to move all the existing pages
266 in the memory range so that they follow the policy.
267 Pages that are shared with other processes will not be moved.
270 is also specified, then the call will fail with the error
272 if some pages could not be moved.
278 then the kernel will attempt to move all existing pages in the memory range
279 regardless of whether other processes use the pages.
280 The calling process must be privileged
285 is also specified, then the call will fail with the error
287 if some pages could not be moved.
288 .\" ---------------------------------------------------------------
293 on error, \-1 is returned and
295 is set to indicate the error.
296 .\" ---------------------------------------------------------------
298 .\" I think I got all of the error returns. --Lee Schermerhorn
301 Part or all of the memory range specified by
305 points outside your accessible address space.
306 Or, there was an unmapped hole in the specified memory range.
309 An invalid value was specified for
319 is not a multiple of the system page size.
326 specified a nonempty set;
338 exceeds a kernel-imposed limit.
339 .\" As at 2.6.23, this limit is "a page worth of bits", e.g.,
340 .\" 8 * 4096 bits, assuming a 4kB page size.
343 specifies one or more node IDs that are
344 greater than the maximum supported node ID.
345 Or, none of the node IDs specified by
347 are on-line and allowed by the process's current cpuset context,
348 or none of the specified nodes contain memory.
351 argument specified both
352 .B MPOL_F_STATIC_NODES
354 .BR MPOL_F_RELATIVE_NODES .
358 was specified and an existing page was already on a node
359 that does not follow the policy;
364 was specified and the kernel was unable to move all existing
368 Insufficient kernel memory was available.
373 argument included the
375 flag and the caller does not have the
378 .\" ---------------------------------------------------------------
382 system call was added to the Linux kernel in version 2.6.7.
384 This system call is Linux-specific.
386 For information on library support, see
389 NUMA policy is not supported on a memory mapped file range
390 that was mapped with the
396 mode can have different effects for
399 .BR set_mempolicy (2).
403 .BR set_mempolicy (2),
404 the process's policy reverts to system default policy
408 is specified for a range of memory using
410 any pages subsequently allocated for that range will use
411 the process's policy, as set by
412 .BR set_mempolicy (2).
413 This effectively removes the explicit policy from the
414 specified range, "falling back" to a possibly nondefault
416 To select explicit "local allocation" for a memory range,
421 with an empty set of nodes.
422 This method will work for
423 .BR set_mempolicy (2),
426 Support for huge page policy was added with 2.6.16.
427 For interleave policy to be effective on huge page mappings the
428 policied memory needs to be tens of megabytes or larger.
431 is ignored on huge page mappings.
436 are only available on Linux 2.6.16 and later.
438 .BR get_mempolicy (2),
441 .BR set_mempolicy (2),