OSDN Git Service

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