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