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