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-11 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 of a NUMA machine is divided into multiple nodes.
48 The memory policy defines from which node memory is allocated.
50 If the memory range specified by the
52 arguments includes an "anonymous" region of memory\(emthat is
53 a region of memory created using the
56 .BR MAP_ANONYMOUS \(emor
57 a memory mapped file, mapped using the
61 flag, pages will only be allocated according to the specified
62 policy when the application writes [stores] to the page.
63 For anonymous regions, an initial read access will use a shared
64 page in the kernel containing all zeros.
65 For a file mapped with
67 an initial read access will allocate pages according to the
68 process policy of the process that causes the page to be allocated.
69 This may not be the process that called
72 The specified policy will be ignored for any
74 mappings in the specified memory range.
75 Rather the pages will be allocated according to the process policy
76 of the process that caused the page to be allocated.
77 Again, this may not be the process that called
80 If the specified memory range includes a shared memory region
83 system call and attached using the
86 pages allocated for the anonymous or shared memory region will
87 be allocated according to the policy specified, regardless which
88 process attached to the shared memory segment causes the allocation.
89 If, however, the shared memory region was created with the
92 the huge pages will be allocated according to the policy specified
93 only if the page allocation is caused by the process that calls
99 only has an effect for new allocations; if the pages inside
100 the range have been already touched before setting the policy,
101 then the policy has no effect.
102 This default behavior may be overridden by the
106 flags described below.
110 argument must specify one of
116 All policy modes except
118 require the caller to specify via the
121 the node or nodes to which the mode applies.
125 argument may also include an optional
131 .BR MPOL_F_STATIC_NODES " (since Linux-2.6.26)"
134 specifies physical node ids.
135 Linux does will not remap the
137 when the process moves to a different cpuset context,
138 nor when the set of nodes allowed by the process's
139 current cpuset context changes.
141 .BR MPOL_F_RELATIVE_NODES " (since Linux-2.6.26)"
144 specifies node ids that are relative to the set of
145 node ids allowed by the process's current cpuset.
148 points to a bitmask of nodes containing up to
151 The bit mask size is rounded to the next multiple of
152 .IR "sizeof(unsigned long)" ,
153 but the kernel will only use bits up to
159 value of zero specifies the empty set of nodes.
168 is required, it must contain at least one node that is on-line,
169 allowed by the process's current cpuset context
171 .B MPOL_F_STATIC_NODES
172 mode flag is specified],
177 mode requests that any non-default policy be removed,
178 restoring default behavior.
179 When applied to a range of memory via
181 this means to use the process policy,
182 which may have been set with
183 .BR set_mempolicy (2).
184 If the mode of the process policy is also
186 the system-wide default policy will be used.
187 The system-wide default policy allocates
188 pages on the node of the CPU that triggers the allocation.
195 arguments must be specify the empty set of nodes.
199 mode specifies a strict policy that restricts memory allocation to
200 the nodes specified in
204 specifies more than one node, page allocations will come from
205 the node with the lowest numeric node ID first, until that node
206 contains no free memory.
207 Allocations will then come from the node with the next highest
210 and so forth, until none of the specified nodes contain free memory.
211 Pages will not be allocated from any node not specified in the
216 mode specifies that page allocations be interleaved across the
217 set of nodes specified in
219 This optimizes for bandwidth instead of latency
220 by spreading out pages and memory accesses to those pages across
222 To be effective the memory area should be fairly large,
223 at least 1MB or bigger with a fairly uniform access pattern.
224 Accesses to a single page of the area will still be limited to
225 the memory bandwidth of a single node.
228 sets the preferred node for allocation.
229 The kernel will try to allocate pages from this
230 node first and fall back to other nodes if the
231 preferred nodes is low on free memory.
234 specifies more than one node ID, the first node in the
235 mask will be selected as the preferred node.
240 arguments specify the empty set, then the memory is allocated on
241 the node of the CPU that triggered the allocation.
242 This is the only way to specify "local allocation" for a
254 then the call will fail with the error
256 if the existing pages in the memory range don't follow the policy.
257 .\" According to the kernel code, the following is not true
258 .\" --Lee Schermerhorn
259 .\" In 2.6.16 or later the kernel will also try to move pages
260 .\" to the requested node with this flag.
266 then the kernel will attempt to move all the existing pages
267 in the memory range so that they follow the policy.
268 Pages that are shared with other processes will not be moved.
271 is also specified, then the call will fail with the error
273 if some pages could not be moved.
279 then the kernel will attempt to move all existing pages in the memory range
280 regardless of whether other processes use the pages.
281 The calling process must be privileged
286 is also specified, then the call will fail with the error
288 if some pages could not be moved.
289 .\" ---------------------------------------------------------------
294 on error, \-1 is returned and
296 is set to indicate the error.
297 .\" ---------------------------------------------------------------
299 .\" I think I got all of the error returns. --Lee Schermerhorn
302 Part of all of the memory range specified by
306 points outside your accessible address space.
307 Or, there was an unmapped hole in the specified memory range.
310 An invalid value was specified for
320 is not a multiple of the system page size.
327 specified a non-empty set;
339 exceeds a kernel-imposed limit.
340 .\" As at 2.6.23, this limit is "a page worth of bits", e.g.,
341 .\" 8 * 4096 bits, assuming a 4kB page size.
344 specifies one or more node IDs that are
345 greater than the maximum supported node ID.
346 Or, none of the node IDs specified by
348 are on-line and allowed by the process's current cpuset context,
349 or none of the specified nodes contain memory.
352 argument specified both
353 .B MPOL_F_STATIC_NODES
355 .BR MPOL_F_RELATIVE_NODES .
359 was specified and an existing page was already on a node
360 that does not follow the policy;
365 was specified and the kernel was unable to move all existing
369 Insufficient kernel memory was available.
374 argument included the
376 flag and the caller does not have the
379 .\" ---------------------------------------------------------------
381 This system call is Linux-specific.
383 NUMA policy is not supported on a memory mapped file range
384 that was mapped with the
389 is ignored on huge page mappings.
393 mode can have different effects for
396 .BR set_mempolicy (2).
400 .BR set_mempolicy (2),
401 the process's policy reverts to system default policy
405 is specified for a range of memory using
407 any pages subsequently allocated for that range will use
408 the process's policy, as set by
409 .BR set_mempolicy (2).
410 This effectively removes the explicit policy from the
411 specified range, "falling back" to a possibly non-default
413 To select explicit "local allocation" for a memory range,
418 with an empty set of nodes.
419 This method will work for
420 .BR set_mempolicy (2),
422 .\" ---------------------------------------------------------------
423 .SS "Versions and Library Support"
426 .BR get_mempolicy (2),
428 .BR set_mempolicy (2)
429 system calls were added to the Linux kernel with version 2.6.7.
430 They are only available on kernels compiled with
435 to get system call definitions.
439 header are available in the
443 However, applications should not use these system calls directly.
444 Instead, the higher level interface provided by the
448 package is recommended.
451 package is available at
452 .IR ftp://oss.sgi.com/www/projects/libnuma/download/ .
453 The package is also included in some Linux distributions.
454 Some distributions include the development library and header
459 Support for huge page policy was added with 2.6.16.
460 For interleave policy to be effective on huge page mappings the
461 policied memory needs to be tens of megabytes or larger.
466 are only available on Linux 2.6.16 and later.
468 .BR get_mempolicy (2),
471 .BR set_mempolicy (2),