]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/get_mempolicy.2
sched_setattr.2: Minor tweaks to Claudio Scordino's patch
[thirdparty/man-pages.git] / man2 / get_mempolicy.2
CommitLineData
314093c9 1.\" Copyright 2003,2004 Andi Kleen, SuSE Labs.
05c7d833 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
05c7d833
MK
24.\" 2007-08-27, Lee Schermerhorn <Lee.Schermerhorn@hp.com>
25.\" more precise specification of behavior.
314093c9 26.\"
4b8c67d9 27.TH GET_MEMPOLICY 2 2017-09-15 Linux "Linux Programmer's Manual"
314093c9 28.SH NAME
85677816 29get_mempolicy \- retrieve NUMA memory policy for a thread
413901b1 30.SH SYNOPSIS
c13182ef 31.B "#include <numaif.h>"
9d9dc1e8 32.nf
68e4db0a 33.PP
2d5f2098 34.BI "long get_mempolicy(int *" mode ", unsigned long *" nodemask ,
f9e2bea7 35.BI " unsigned long " maxnode ", void *" addr ,
9d9dc1e8 36.BI " unsigned long " flags );
68e4db0a 37.PP
4ed3353d 38Link with \fI\-lnuma\fP.
9d9dc1e8 39.fi
314093c9
MK
40.SH DESCRIPTION
41.BR get_mempolicy ()
85677816 42retrieves the NUMA policy of the calling thread or of a memory address,
314093c9
MK
43depending on the setting of
44.IR flags .
efeece04 45.PP
314093c9
MK
46A NUMA machine has different
47memory controllers with different distances to specific CPUs.
05c7d833 48The memory policy defines from which node memory is allocated for
85677816 49the thread.
efeece04 50.PP
314093c9 51If
0daa9e92 52.I flags
314093c9 53is specified as 0,
85677816 54then information about the calling thread's default policy
314093c9
MK
55(as set by
56.BR set_mempolicy (2))
bafd3d1f 57is returned, in the buffers pointed to by
c5ae834f 58.I mode
63e28ad4 59and
bafd3d1f
MK
60.IR nodemask .
61The value returned in these arguments
85677816 62may be used to restore the thread's policy to its state at
63e28ad4
MK
63the time of the call to
64.BR get_mempolicy ()
65using
66.BR set_mempolicy (2).
3cb972b3
MK
67When
68.I flags
69is 0,
70.I addr
71must be specified as NULL.
efeece04 72.PP
20ca75a0
MK
73If
74.I flags
75specifies
5a35e620 76.BR MPOL_F_MEMS_ALLOWED
20ca75a0
MK
77(available since Linux 2.6.24), the
78.I mode
dedc639c 79argument is ignored and the set of nodes (memories) that the
85677816 80thread is allowed to specify in subsequent calls to
20ca75a0
MK
81.BR mbind (2)
82or
83.BR set_mempolicy (2)
dedc639c
MK
84(in the absence of any
85.IR "mode flags" )
20ca75a0
MK
86is returned in
87.IR nodemask .
88It is not permitted to combine
89.B MPOL_F_MEMS_ALLOWED
90with either
91.B MPOL_F_ADDR
92or
93.BR MPOL_F_NODE .
efeece04 94.PP
c13182ef 95If
314093c9
MK
96.I flags
97specifies
98.BR MPOL_F_ADDR ,
99then information is returned about the policy governing the memory
100address given in
101.IR addr .
85677816 102This policy may be different from the thread's default policy if
05c7d833
MK
103.BR mbind (2)
104or one of the helper functions described in
00045cbb 105.BR numa (3)
05c7d833 106has been used to establish a policy for the memory range containing
314093c9 107.IR addr .
efeece04 108.PP
05c7d833
MK
109If the
110.I mode
111argument is not NULL, then
cf94921b 112.BR get_mempolicy ()
63e28ad4
MK
113will store the policy mode and any optional
114.I "mode flags"
115of the requested NUMA policy in the location pointed to by this argument.
c13182ef 116If
0daa9e92 117.I nodemask
05c7d833
MK
118is not NULL, then the nodemask associated with the policy will be stored
119in the location pointed to by this argument.
c13182ef 120.I maxnode
00045cbb 121specifies the number of node IDs
05c7d833
MK
122that can be stored into
123.IR nodemask \(emthat
00045cbb 124is, the maximum node ID plus one.
05c7d833
MK
125The value specified by
126.I maxnode
127is always rounded to a multiple of
69a72679 128.IR "sizeof(unsigned\ long)*8" .
efeece04 129.PP
05c7d833
MK
130If
131.I flags
132specifies both
133.B MPOL_F_NODE
134and
135.BR MPOL_F_ADDR ,
cf94921b 136.BR get_mempolicy ()
00045cbb 137will return the node ID of the node on which the address
05c7d833
MK
138.I addr
139is allocated into the location pointed to by
140.IR mode .
141If no page has yet been allocated for the specified address,
cf94921b 142.BR get_mempolicy ()
85677816 143will allocate a page as if the thread had performed a read
dedc639c 144(load) access to that address, and return the ID of the node
05c7d833 145where that page was allocated.
efeece04 146.PP
05c7d833
MK
147If
148.I flags
149specifies
150.BR MPOL_F_NODE ,
151but not
152.BR MPOL_F_ADDR ,
85677816 153and the thread's current policy is
05c7d833
MK
154.BR MPOL_INTERLEAVE ,
155then
cf94921b 156.BR get_mempolicy ()
05c7d833
MK
157will return in the location pointed to by a non-NULL
158.I mode
159argument,
00045cbb 160the node ID of the next node that will be used for
85677816 161interleaving of internal kernel pages allocated on behalf of the thread.
00045cbb 162.\" Note: code returns next interleave node via 'mode' argument -Lee Schermerhorn
9a141bfb 163These allocations include pages for memory-mapped files in
05c7d833 164process memory ranges mapped using the
cf94921b 165.BR mmap (2)
05c7d833 166call with the
00045cbb 167.B MAP_PRIVATE
05c7d833 168flag for read accesses, and in memory ranges mapped with the
00045cbb 169.B MAP_SHARED
05c7d833 170flag for all accesses.
efeece04 171.PP
05c7d833 172Other flag values are reserved.
efeece04 173.PP
314093c9
MK
174For an overview of the possible policies see
175.BR set_mempolicy (2).
314093c9
MK
176.SH RETURN VALUE
177On success,
178.BR get_mempolicy ()
179returns 0;
180on error, \-1 is returned and
c13182ef 181.I errno
314093c9 182is set to indicate the error.
05c7d833
MK
183.SH ERRORS
184.TP
b3a7b55e
MK
185.B EFAULT
186Part of all of the memory range specified by
187.I nodemask
188and
189.I maxnode
190points outside your accessible address space.
191.TP
05c7d833
MK
192.B EINVAL
193The value specified by
194.I maxnode
00045cbb 195is less than the number of node IDs supported by the system.
05c7d833
MK
196Or
197.I flags
198specified values other than
199.B MPOL_F_NODE
200or
201.BR MPOL_F_ADDR ;
202or
203.I flags
204specified
205.B MPOL_F_ADDR
206and
207.I addr
208is NULL,
209or
210.I flags
211did not specify
212.B MPOL_F_ADDR
213and
214.I addr
215is not NULL.
216Or,
217.I flags
218specified
219.B MPOL_F_NODE
220but not
221.B MPOL_F_ADDR
85677816 222and the current thread policy is not
05c7d833 223.BR MPOL_INTERLEAVE .
20ca75a0
MK
224Or,
225.I flags
226specified
227.B MPOL_F_MEMS_ALLOWED
228with either
229.B MPOL_F_ADDR
230or
231.BR MPOL_F_NODE .
cf94921b
MK
232(And there are other
233.B EINVAL
234cases.)
69f06e4f
MK
235.SH VERSIONS
236The