OSDN Git Service

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