ioctl_tty.2: Update DTR example
[man-pages.git] / man2 / move_pages.2
blobf229df1777d5005f7d95709abd70600c4f285149
1 .\" This manpage is Copyright (C) 2006 Silicon Graphics, Inc.
2 .\"                               Christoph Lameter
3 .\"
4 .\" %%%LICENSE_START(VERBATIM_TWO_PARA)
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 .\" %%%LICENSE_END
14 .\"
15 .\" FIXME Should programs normally be using move_pages() directly, or should
16 .\" they rather be using interfaces in the numactl package?
17 .\" (e.g., compare with recommendation in mbind(2)).
18 .\" Does this page need to give advice on this topic?
19 .\"
20 .TH MOVE_PAGES 2 2021-03-22 "Linux" "Linux Programmer's Manual"
21 .SH NAME
22 move_pages \- move individual pages of a process to another node
23 .SH SYNOPSIS
24 .nf
25 .B #include <numaif.h>
26 .PP
27 .BI "long move_pages(int " pid ", unsigned long " count ", void **" pages ,
28 .BI "                const int *" nodes ", int *" status ", int " flags );
29 .fi
30 .PP
31 Link with \fI\-lnuma\fP.
32 .PP
33 .IR Note :
34 There is no glibc wrapper for this system call; see NOTES.
35 .SH DESCRIPTION
36 .BR move_pages ()
37 moves the specified
38 .I pages
39 of the process
40 .I pid
41 to the memory nodes specified by
42 .IR nodes .
43 The result of the move is reflected in
44 .IR status .
45 The
46 .I flags
47 indicate constraints on the pages to be moved.
48 .PP
49 .I pid
50 is the ID of the process in which pages are to be moved.
52 .I pid
53 is 0, then
54 .BR move_pages ()
55 moves pages of the calling process.
56 .PP
57 To move pages in another process requires the following privileges:
58 .IP * 3
59 In kernels up to and including Linux 4.12:
60 the caller must be privileged
61 .RB ( CAP_SYS_NICE )
62 or the real or effective user ID of the calling process must match the
63 real or saved-set user ID of the target process.
64 .IP *
65 The older rules allowed the caller to discover various
66 virtual address choices made by the kernel that could lead
67 to the defeat of address-space-layout randomization
68 for a process owned by the same UID as the caller,
69 the rules were changed starting with Linux 4.13.
70 Since Linux 4.13,
71 .\" commit 197e7e521384a23b9e585178f3f11c9fa08274b9
72 permission is governed by a ptrace access mode
73 .B PTRACE_MODE_READ_REALCREDS
74 check with respect to the target process; see
75 .BR ptrace (2).
76 .PP
77 .I count
78 is the number of pages to move.
79 It defines the size of the three arrays
80 .IR pages ,
81 .IR nodes ,
82 and
83 .IR status .
84 .PP
85 .I pages
86 is an array of pointers to the pages that should be moved.
87 These are pointers that should be aligned to page boundaries.
88 .\" FIXME Describe the result if pointers in the 'pages' array are
89 .\" not aligned to page boundaries
90 Addresses are specified as seen by the process specified by
91 .IR pid .
92 .PP
93 .I nodes
94 is an array of integers that specify the desired location for each page.
95 Each element in the array is a node number.
96 .I nodes
97 can also be NULL, in which case
98 .BR move_pages ()
99 does not move any pages but instead will return the node
100 where each page currently resides, in the
101 .I status
102 array.
103 Obtaining the status of each page may be necessary to determine
104 pages that need to be moved.
106 .I status
107 is an array of integers that return the status of each page.
108 The array contains valid values only if
109 .BR move_pages ()
110 did not return an error.
111 Preinitialization of the array to a value
112 which cannot represent a real numa node or valid error of status array
113 could help to identify pages that have been migrated.
115 .I flags
116 specify what types of pages to move.
117 .B MPOL_MF_MOVE
118 means that only pages that are in exclusive use by the process
119 are to be moved.
120 .B MPOL_MF_MOVE_ALL
121 means that pages shared between multiple processes can also be moved.
122 The process must be privileged
123 .RB ( CAP_SYS_NICE )
124 to use
125 .BR MPOL_MF_MOVE_ALL .
126 .SS Page states in the status array
127 The following values can be returned in each element of the
128 .I status
129 array.
131 .B 0..MAX_NUMNODES
132 Identifies the node on which the page resides.
134 .B \-EACCES
135 The page is mapped by multiple processes and can be moved only if
136 .B MPOL_MF_MOVE_ALL
137 is specified.
139 .B \-EBUSY
140 The page is currently busy and cannot be moved.
141 Try again later.
142 This occurs if a page is undergoing I/O or another kernel subsystem
143 is holding a reference to the page.
145 .B \-EFAULT
146 This is a zero page or the memory area is not mapped by the process.
148 .B \-EIO
149 Unable to write back a page.
150 The page has to be written back
151 in order to move it since the page is dirty and the filesystem
152 does not provide a migration function that would allow the move
153 of dirty pages.
155 .B \-EINVAL
156 A dirty page cannot be moved.
157 The filesystem does not
158 provide a migration function and has no ability to write back pages.
160 .B \-ENOENT
161 The page is not present.
163 .B \-ENOMEM
164 Unable to allocate memory on target node.
165 .SH RETURN VALUE
166 On success
167 .BR move_pages ()
168 returns zero.
169 .\" FIXME . Is the following quite true: does the wrapper in numactl
170 .\" do the right thing?
171 On error, it returns \-1, and sets
172 .I errno
173 to indicate the error.
174 If positive value is returned, it is the number of
175 nonmigrated pages.
176 .SH ERRORS
178 .B Positive value
179 The number of nonmigrated pages if they were the result of nonfatal
180 reasons (since
181 .\" commit a49bd4d7163707de377aee062f17befef6da891b
182 Linux 4.17).
184 .B E2BIG
185 Too many pages to move.
186 Since Linux 2.6.29,
187 .\" commit 3140a2273009c01c27d316f35ab76a37e105fdd8
188 the kernel no longer generates this error.
190 .B EACCES
191 .\" FIXME Clarify "current cpuset" in the description of the EACCES error.
192 .\" Is that the cpuset of the caller or the target?
193 One of the target nodes is not allowed by the current cpuset.
195 .B EFAULT
196 Parameter array could not be accessed.
198 .B EINVAL
199 Flags other than
200 .B MPOL_MF_MOVE
202 .B MPOL_MF_MOVE_ALL
203 was specified or an attempt was made to migrate pages of a kernel thread.
205 .B ENODEV
206 One of the target nodes is not online.
208 .B EPERM
209 The caller specified
210 .B MPOL_MF_MOVE_ALL
211 without sufficient privileges
212 .RB ( CAP_SYS_NICE ).
213 Or, the caller attempted to move pages of a process belonging
214 to another user but did not have privilege to do so
215 .RB ( CAP_SYS_NICE ).
217 .B ESRCH
218 Process does not exist.
219 .SH VERSIONS
220 .BR move_pages ()
221 first appeared on Linux in version 2.6.18.
222 .SH CONFORMING TO
223 This system call is Linux-specific.
224 .SH NOTES
225 Glibc does not provide a wrapper for this system call.
226 For information on library support, see
227 .BR numa (7).
230 .BR get_mempolicy (2)
231 with the
232 .B MPOL_F_MEMS_ALLOWED
233 flag to obtain the set of nodes that are allowed by
234 .\" FIXME Clarify "current cpuset".  Is that the cpuset of the caller
235 .\" or the target?
236 the current cpuset.
237 Note that this information is subject to change at any
238 time by manual or automatic reconfiguration of the cpuset.
240 Use of this function may result in pages whose location
241 (node) violates the memory policy established for the
242 specified addresses (See
243 .BR mbind (2))
244 and/or the specified process (See
245 .BR set_mempolicy (2)).
246 That is, memory policy does not constrain the destination
247 nodes used by
248 .BR move_pages ().
251 .I <numaif.h>
252 header is not included with glibc, but requires installing
253 .I libnuma\-devel
254 or a similar package.
255 .SH SEE ALSO
256 .BR get_mempolicy (2),
257 .BR mbind (2),
258 .BR set_mempolicy (2),
259 .BR numa (3),
260 .BR numa_maps (5),
261 .BR cpuset (7),
262 .BR numa (7),
263 .BR migratepages (8),
264 .BR numastat (8)