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