OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / set_mempolicy.2
1 .\" Copyright 2003,2004 Andi Kleen, SuSE Labs.
2 .\" and Copyright 2007 Lee Schermerhorn, Hewlett Packard
3 .\"
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.
8 .\"
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.
13 .\"
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.
18 .\"
19 .\" Formatted or processed versions of this manual, if unaccompanied by
20 .\" the source, must acknowledge the copyright and authors of this work.
21 .\" %%%LICENSE_END
22 .\"
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.
26 .\"
27 .TH SET_MEMPOLICY 2 2014-05-28 Linux "Linux Programmer's Manual"
28 .SH NAME
29 set_mempolicy \- set default NUMA memory policy for a process and its children
30 .SH SYNOPSIS
31 .nf
32 .B "#include <numaif.h>"
33 .sp
34 .BI "long set_mempolicy(int " mode ", const unsigned long *" nodemask ,
35 .BI "                   unsigned long " maxnode );
36 .sp
37 Link with \fI\-lnuma\fP.
38 .fi
39 .SH DESCRIPTION
40 .BR set_mempolicy ()
41 sets the NUMA memory policy of the calling process,
42 which consists of a policy mode and zero or more nodes,
43 to the values specified by the
44 .IR mode ,
45 .I nodemask
46 and
47 .I maxnode
48 arguments.
49
50 A NUMA machine has different
51 memory controllers with different distances to specific CPUs.
52 The memory policy defines from which node memory is allocated for
53 the process.
54
55 This system call defines the default policy for the process.
56 The process policy governs allocation of pages in the process's
57 address space outside of memory ranges
58 controlled by a more specific policy set by
59 .BR mbind (2).
60 The process default policy also controls allocation of any pages for
61 memory-mapped files mapped using the
62 .BR mmap (2)
63 call with the
64 .B MAP_PRIVATE
65 flag and that are only read [loaded] from by the process
66 and of memory-mapped files mapped using the
67 .BR mmap (2)
68 call with the
69 .B MAP_SHARED
70 flag, regardless of the access type.
71 The policy is applied only when a new page is allocated
72 for the process.
73 For anonymous memory this is when the page is first
74 touched by the application.
75
76 The
77 .I mode
78 argument must specify one of
79 .BR MPOL_DEFAULT ,
80 .BR MPOL_BIND ,
81 .BR MPOL_INTERLEAVE ,
82 or
83 .BR MPOL_PREFERRED .
84 All modes except
85 .B MPOL_DEFAULT
86 require the caller to specify via the
87 .I nodemask
88 argument one or more nodes.
89
90 The
91 .I mode
92 argument may also include an optional
93 .IR "mode flag" .
94 The supported
95 .I "mode flags"
96 are:
97 .TP
98 .BR MPOL_F_STATIC_NODES " (since Linux 2.6.26)"
99 A nonempty
100 .I nodemask
101 specifies physical node ids.
102 Linux will not remap the
103 .I nodemask
104 when the process moves to a different cpuset context,
105 nor when the set of nodes allowed by the process's
106 current cpuset context changes.
107 .TP
108 .BR MPOL_F_RELATIVE_NODES " (since Linux 2.6.26)"
109 A nonempty
110 .I nodemask
111 specifies node ids that are relative to the set of
112 node ids allowed by the process's current cpuset.
113 .PP
114 .I nodemask
115 points to a bit mask of node IDs that contains up to
116 .I maxnode
117 bits.
118 The bit mask size is rounded to the next multiple of
119 .IR "sizeof(unsigned long)" ,
120 but the kernel will use bits only up to
121 .IR maxnode .
122 A NULL value of
123 .I nodemask
124 or a
125 .I maxnode
126 value of zero specifies the empty set of nodes.
127 If the value of
128 .I maxnode
129 is zero,
130 the
131 .I nodemask
132 argument is ignored.
133
134 Where a
135 .I nodemask
136 is required, it must contain at least one node that is on-line,
137 allowed by the process's current cpuset context,
138 [unless the
139 .B MPOL_F_STATIC_NODES
140 mode flag is specified],
141 and contains memory.
142 If the
143 .B MPOL_F_STATIC_NODES
144 is set in
145 .I mode
146 and a required
147 .I nodemask
148 contains no nodes that are allowed by the process's current cpuset context,
149 the memory policy reverts to
150 .IR "local allocation" .
151 This effectively overrides the specified policy until the process's
152 cpuset context includes one or more of the nodes specified by
153 .IR nodemask .
154
155 The
156 .B MPOL_DEFAULT
157 mode specifies that any nondefault process memory policy be removed,
158 so that the memory policy "falls back" to the system default policy.
159 The system default policy is "local allocation"\(emthat is,
160 allocate memory on the node of the CPU that triggered the allocation.
161 .I nodemask
162 must be specified as NULL.
163 If the "local node" contains no free memory, the system will
164 attempt to allocate memory from a "near by" node.
165
166 The
167 .B MPOL_BIND
168 mode defines a strict policy that restricts memory allocation to the
169 nodes specified in
170 .IR nodemask .
171 If
172 .I nodemask
173 specifies more than one node, page allocations will come from
174 the node with the lowest numeric node ID first, until that node
175 contains no free memory.
176 Allocations will then come from the node with the next highest
177 node ID specified in
178 .I nodemask
179 and so forth, until none of the specified nodes contain free memory.
180 Pages will not be allocated from any node not specified in the
181 .IR nodemask .
182
183 .B MPOL_INTERLEAVE
184 interleaves page allocations across the nodes specified in
185 .I nodemask
186 in numeric node ID order.
187 This optimizes for bandwidth instead of latency
188 by spreading out pages and memory accesses to those pages across
189 multiple nodes.
190 However, accesses to a single page will still be limited to
191 the memory bandwidth of a single node.
192 .\" NOTE:  the following sentence doesn't make sense in the context
193 .\" of set_mempolicy() -- no memory area specified.
194 .\" To be effective the memory area should be fairly large,
195 .\" at least 1MB or bigger.
196
197 .B MPOL_PREFERRED
198 sets the preferred node for allocation.
199 The kernel will try to allocate pages from this node first
200 and fall back to "near by" nodes if the preferred node is low on free
201 memory.
202 If
203 .I nodemask
204 specifies more than one node ID, the first node in the
205 mask will be selected as the preferred node.
206 If the
207 .I nodemask
208 and
209 .I maxnode
210 arguments specify the empty set, then the policy
211 specifies "local allocation"
212 (like the system default policy discussed above).
213
214 The process memory policy is preserved across an
215 .BR execve (2),
216 and is inherited by child processes created using
217 .BR fork (2)
218 or
219 .BR clone (2).
220 .SH RETURN VALUE
221 On success,
222 .BR set_mempolicy ()
223 returns 0;
224 on error, \-1 is returned and
225 .I errno
226 is set to indicate the error.
227 .SH ERRORS
228 .TP
229 .B EFAULT
230 Part of all of the memory range specified by
231 .I nodemask
232 and
233 .I maxnode
234 points outside your accessible address space.
235 .TP
236 .B EINVAL
237 .I mode
238 is invalid.
239 Or,
240 .I mode
241 is
242 .B MPOL_DEFAULT
243 and
244 .I nodemask
245 is nonempty,
246 or
247 .I mode
248 is
249 .B MPOL_BIND
250 or
251 .B MPOL_INTERLEAVE
252 and
253 .I nodemask
254 is empty.
255 Or,
256 .I maxnode
257 specifies more than a page worth of bits.
258 Or,
259 .I nodemask
260 specifies one or more node IDs that are
261 greater than the maximum supported node ID.
262 Or, none of the node IDs specified by
263 .I nodemask
264 are on-line and allowed by the process's current cpuset context,
265 or none of the specified nodes contain memory.
266 Or, the
267 .I mode
268 argument specified both
269 .B MPOL_F_STATIC_NODES
270 and
271 .BR MPOL_F_RELATIVE_NODES .
272 .TP
273 .B ENOMEM
274 Insufficient kernel memory was available.
275 .SH VERSIONS
276 The
277 .BR set_mempolicy (),
278 system call was added to the Linux kernel in version 2.6.7.
279 .SH CONFORMING TO
280 This system call is Linux-specific.
281 .SH NOTES
282 Process policy is not remembered if the page is swapped out.
283 When such a page is paged back in, it will use the policy of
284 the process or memory range that is in effect at the time the
285 page is allocated.
286
287 For information on library support, see
288 .BR numa (7).
289 .SH SEE ALSO
290 .BR get_mempolicy (2),
291 .BR getcpu (2),
292 .BR mbind (2),
293 .BR mmap (2),
294 .BR numa (3),
295 .BR cpuset (7),
296 .BR numa (7),
297 .BR numactl (8)
298 .SH COLOPHON
299 This page is part of release 3.79 of the Linux
300 .I man-pages
301 project.
302 A description of the project,
303 information about reporting bugs,
304 and the latest version of this page,
305 can be found at
306 \%http://www.kernel.org/doc/man\-pages/.