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 2007-08-27 Linux "Linux Programmer's Manual"
27 mbind \- Set memory policy for a memory range
30 .B "#include <numaif.h>"
32 .BI "int mbind(void *" start ", 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 task 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.
124 points to a bitmask of nodes containing up to
127 The bit mask size is rounded to the next multiple of
128 .IR "sizeof(unsigned long)" ,
129 but the kernel will only use bits up to
135 value of zero specifies the empty set of nodes.
145 mode specifies that the default policy should be used.
146 When applied to a range of memory via
148 this means to use the process policy,
149 which may have been set with
150 .BR set_mempolicy (2).
151 If the mode of the process policy is also
153 the system-wide default policy will be used.
154 The system-wide default policy will allocate
155 pages on the node of the CPU that triggers the allocation.
162 arguments must be specify the empty set of nodes.
166 mode specifies a strict policy that restricts memory allocation to
167 the nodes specified in
171 specifies more than one node, page allocations will come from
172 the node with the lowest numeric node ID first, until that node
173 contains no free memory.
174 Allocations will then come from the node with the next highest
177 and so forth, until none of the specified nodes contain free memory.
178 Pages will not be allocated from any node not specified in the
183 mode specifies that page allocations be interleaved across the
184 set of nodes specified in
186 This optimizes for bandwidth instead of latency
187 by spreading out pages and memory accesses to those pages across
189 To be effective the memory area should be fairly large,
190 at least 1MB or bigger with a fairly uniform access pattern.
191 Accesses to a single page of the area will still be limited to
192 the memory bandwidth of a single node.
195 sets the preferred node for allocation.
196 The kernel will try to allocate pages from this
197 node first and fall back to other nodes if the
198 preferred nodes is low on free memory.
201 specifies more than one node ID, the first node in the
202 mask will be selected as the preferred node.
207 arguments specify the empty set, then the memory is allocated on
208 the node of the CPU that triggered the allocation.
209 This is the only way to specify "local allocation" for a
221 then the call will fail with the error
223 if the existing pages in the memory range don't follow the policy.
224 .\" According to the kernel code, the following is not true
225 .\" --Lee Schermerhorn
226 .\" In 2.6.16 or later the kernel will also try to move pages
227 .\" to the requested node with this flag.
233 then the kernel will attempt to move all the existing pages
234 in the memory range so that they follow the policy.
235 Pages that are shared with other processes will not be moved.
238 is also specified, then the call will fail with the error
240 if some pages could not be moved.
246 then the kernel will attempt to move all existing pages in the memory range
247 regardless of whether other processes use the pages.
248 The calling process must be privileged
253 is also specified, then the call will fail with the error
255 if some pages could not be moved.
256 .\" ---------------------------------------------------------------
261 on error, \-1 is returned and
263 is set to indicate the error.
264 .\" ---------------------------------------------------------------
266 .\" I think I got all of the error returns. --Lee Schermerhorn
269 Part of all of the memory range specified by
273 points outside your accessible address space.
274 Or, there was an unmapped hole in the specified memory range.
277 An invalid value was specified for
287 is not a multiple of the system page size.
294 specified a nonempty set;
306 exceeds kernel-imposed limit.
307 .\" As at 2.6.23, this limit is "a page worth of bits", e.g.,
308 .\" 8 * 4096 bits, assuming a 4kB page size.
311 specifies one or more node IDs that are
312 greater than the maximum supported node ID,
313 or are not allowed in the calling task's context.
314 .\" "calling task's context" refers to cpusets.
315 .\" No man page avail to ref. --Lee Schermerhorn
316 Or, none of the node IDs specified by
318 are on-line, or none of the specified nodes contain memory.
322 was specified and an existing page was already on a node
323 that does not follow the policy;
328 was specified and the kernel was unable to move all existing
332 Insufficient kernel memory was available.
337 argument included the
339 flag and the caller does not have the
342 .\" ---------------------------------------------------------------
344 This system call is Linux-specific.
346 NUMA policy is not supported on a memory mapped file range
347 that was mapped with the
352 is ignored on huge page mappings.
356 mode has different effects for
359 .BR set_mempolicy (2).
362 is specified for a range of memory using
364 any pages subsequently allocated for that range will use
365 the process's policy, as set by
366 .BR set_mempolicy (2).
367 This effectively removes the explicit policy from the
369 To select "local allocation" for a memory range,
374 with an empty set of nodes.
375 This method will work for
376 .BR set_mempolicy (2),
378 .\" ---------------------------------------------------------------
379 .SS "Versions and Library Support"
382 .BR get_mempolicy (2),
384 .BR set_mempolicy (2)
385 system calls were added to the Linux kernel with version 2.6.7.
386 They are only available on kernels compiled with
391 to get system call definitions.
395 header are available in the
399 However, applications should not use these system calls directly.
400 Instead, the higher level interface provided by the
404 package is recommended.
407 package is available at
408 .IR ftp://ftp.suse.com/pub/people/ak/numa/ .
409 The package is also included in some Linux distributions.
410 Some distributions include the development library and header
415 Support for huge page policy was added with 2.6.16.
416 For interleave policy to be effective on huge page mappings the
417 policied memory needs to be tens of megabytes or larger.
422 are only available on Linux 2.6.16 and later.
424 .BR get_mempolicy (2),
426 .BR set_mempolicy (2),