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