| 1 |
# SOME DESCRIPTIVE TITLE |
| 2 |
# Copyright (C) YEAR Free Software Foundation, Inc. |
| 3 |
# This file is distributed under the same license as the PACKAGE package. |
| 4 |
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
| 5 |
# |
| 6 |
#, fuzzy |
| 7 |
msgid "" |
| 8 |
msgstr "" |
| 9 |
"Project-Id-Version: PACKAGE VERSION\n" |
| 10 |
"POT-Creation-Date: 2026-06-05 06:50+0200\n" |
| 11 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
| 12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 13 |
"Language-Team: LANGUAGE <[email protected]>\n" |
| 14 |
"Language: \n" |
| 15 |
"MIME-Version: 1.0\n" |
| 16 |
"Content-Type: text/plain; charset=UTF-8\n" |
| 17 |
"Content-Transfer-Encoding: 8bit\n" |
| 18 |
|
| 19 |
#. type: TH |
| 20 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 21 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 22 |
#, no-wrap |
| 23 |
msgid "userfaultfd" |
| 24 |
msgstr "" |
| 25 |
|
| 26 |
#. type: TH |
| 27 |
#: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed |
| 28 |
#, no-wrap |
| 29 |
msgid "2026-02-16" |
| 30 |
msgstr "" |
| 31 |
|
| 32 |
#. type: TH |
| 33 |
#: archlinux debian-unstable |
| 34 |
#, no-wrap |
| 35 |
msgid "Linux man-pages 6.18" |
| 36 |
msgstr "" |
| 37 |
|
| 38 |
#. type: SH |
| 39 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 40 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 41 |
#, no-wrap |
| 42 |
msgid "NAME" |
| 43 |
msgstr "" |
| 44 |
|
| 45 |
#. type: Plain text |
| 46 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 47 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 48 |
msgid "" |
| 49 |
"userfaultfd - create a file descriptor for handling page faults in user space" |
| 50 |
msgstr "" |
| 51 |
|
| 52 |
#. type: SH |
| 53 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 54 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 55 |
#, no-wrap |
| 56 |
msgid "LIBRARY" |
| 57 |
msgstr "" |
| 58 |
|
| 59 |
#. type: Plain text |
| 60 |
#: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 61 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 62 |
msgid "Standard C library (I<libc>,\\ I<-lc>)" |
| 63 |
msgstr "" |
| 64 |
|
| 65 |
#. type: SH |
| 66 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 67 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 68 |
#, no-wrap |
| 69 |
msgid "SYNOPSIS" |
| 70 |
msgstr "" |
| 71 |
|
| 72 |
#. type: Plain text |
| 73 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 74 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 75 |
#, no-wrap |
| 76 |
msgid "" |
| 77 |
"B<#include E<lt>fcntl.hE<gt>> /* Definition of B<O_*> constants */\n" |
| 78 |
"B<#include E<lt>sys/syscall.hE<gt>> /* Definition of B<SYS_*> constants */\n" |
| 79 |
"B<#include E<lt>linux/userfaultfd.hE<gt>> /* Definition of B<UFFD_*> constants */\n" |
| 80 |
"B<#include E<lt>unistd.hE<gt>>\n" |
| 81 |
msgstr "" |
| 82 |
|
| 83 |
#. type: Plain text |
| 84 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 85 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 86 |
#, no-wrap |
| 87 |
msgid "B<int syscall(SYS_userfaultfd, int >I<flags>B<);>\n" |
| 88 |
msgstr "" |
| 89 |
|
| 90 |
#. type: Plain text |
| 91 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 92 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 93 |
msgid "" |
| 94 |
"I<Note>: glibc provides no wrapper for B<userfaultfd>(), necessitating the " |
| 95 |
"use of B<syscall>(2)." |
| 96 |
msgstr "" |
| 97 |
|
| 98 |
#. type: SH |
| 99 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 100 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 101 |
#, no-wrap |
| 102 |
msgid "DESCRIPTION" |
| 103 |
msgstr "" |
| 104 |
|
| 105 |
#. type: Plain text |
| 106 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 107 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 108 |
msgid "" |
| 109 |
"B<userfaultfd>() creates a new userfaultfd object that can be used for " |
| 110 |
"delegation of page-fault handling to a user-space application, and returns a " |
| 111 |
"file descriptor that refers to the new object. The new userfaultfd object " |
| 112 |
"is configured using B<ioctl>(2)." |
| 113 |
msgstr "" |
| 114 |
|
| 115 |
#. type: Plain text |
| 116 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 117 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 118 |
msgid "" |
| 119 |
"Once the userfaultfd object is configured, the application can use " |
| 120 |
"B<read>(2) to receive userfaultfd notifications. The reads from " |
| 121 |
"userfaultfd may be blocking or non-blocking, depending on the value of " |
| 122 |
"I<flags> used for the creation of the userfaultfd or subsequent calls to " |
| 123 |
"B<fcntl>(2)." |
| 124 |
msgstr "" |
| 125 |
|
| 126 |
#. type: Plain text |
| 127 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 128 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 129 |
msgid "" |
| 130 |
"The following values may be bitwise ORed in I<flags> to change the behavior " |
| 131 |
"of B<userfaultfd>():" |
| 132 |
msgstr "" |
| 133 |
|
| 134 |
#. type: TP |
| 135 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 136 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 137 |
#, no-wrap |
| 138 |
msgid "B<O_CLOEXEC>" |
| 139 |
msgstr "" |
| 140 |
|
| 141 |
#. type: Plain text |
| 142 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 143 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 144 |
msgid "" |
| 145 |
"Enable the close-on-exec flag for the new userfaultfd file descriptor. See " |
| 146 |
"the description of the B<O_CLOEXEC> flag in B<open>(2)." |
| 147 |
msgstr "" |
| 148 |
|
| 149 |
#. type: TP |
| 150 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 151 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 152 |
#, no-wrap |
| 153 |
msgid "B<O_NONBLOCK>" |
| 154 |
msgstr "" |
| 155 |
|
| 156 |
#. type: Plain text |
| 157 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 158 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 159 |
msgid "" |
| 160 |
"Enables non-blocking operation for the userfaultfd object. See the " |
| 161 |
"description of the B<O_NONBLOCK> flag in B<open>(2)." |
| 162 |
msgstr "" |
| 163 |
|
| 164 |
#. type: TP |
| 165 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 166 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 167 |
#, no-wrap |
| 168 |
msgid "B<UFFD_USER_MODE_ONLY>" |
| 169 |
msgstr "" |
| 170 |
|
| 171 |
#. type: Plain text |
| 172 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 173 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 174 |
msgid "" |
| 175 |
"This is an userfaultfd-specific flag that was introduced in Linux 5.11. " |
| 176 |
"When set, the userfaultfd object will only be able to handle page faults " |
| 177 |
"originated from the user space on the registered regions. When a kernel-" |
| 178 |
"originated fault was triggered on the registered range with this " |
| 179 |
"userfaultfd, a B<SIGBUS> signal will be delivered." |
| 180 |
msgstr "" |
| 181 |
|
| 182 |
#. type: Plain text |
| 183 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 184 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 185 |
msgid "" |
| 186 |
"When the last file descriptor referring to a userfaultfd object is closed, " |
| 187 |
"all memory ranges that were registered with the object are unregistered and " |
| 188 |
"unread events are flushed." |
| 189 |
msgstr "" |
| 190 |
|
| 191 |
#. type: Plain text |
| 192 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 193 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 194 |
msgid "Userfaultfd supports three modes of registration:" |
| 195 |
msgstr "" |
| 196 |
|
| 197 |
#. type: TP |
| 198 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 199 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 200 |
#, no-wrap |
| 201 |
msgid "B<UFFDIO_REGISTER_MODE_MISSING> (since Linux 4.10)" |
| 202 |
msgstr "" |
| 203 |
|
| 204 |
#. type: Plain text |
| 205 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 206 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 207 |
msgid "" |
| 208 |
"When registered with B<UFFDIO_REGISTER_MODE_MISSING> mode, user-space will " |
| 209 |
"receive a page-fault notification when a missing page is accessed. The " |
| 210 |
"faulted thread will be stopped from execution until the page fault is " |
| 211 |
"resolved from user-space by either an B<UFFDIO_COPY> or an " |
| 212 |
"B<UFFDIO_ZEROPAGE> ioctl." |
| 213 |
msgstr "" |
| 214 |
|
| 215 |
#. type: TP |
| 216 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 217 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 218 |
#, no-wrap |
| 219 |
msgid "B<UFFDIO_REGISTER_MODE_MINOR> (since Linux 5.13)" |
| 220 |
msgstr "" |
| 221 |
|
| 222 |
#. type: Plain text |
| 223 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 224 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 225 |
msgid "" |
| 226 |
"When registered with B<UFFDIO_REGISTER_MODE_MINOR> mode, user-space will " |
| 227 |
"receive a page-fault notification when a minor page fault occurs. That is, " |
| 228 |
"when a backing page is in the page cache, but page table entries don't yet " |
| 229 |
"exist. The faulted thread will be stopped from execution until the page " |
| 230 |
"fault is resolved from user-space by an B<UFFDIO_CONTINUE> ioctl." |
| 231 |
msgstr "" |
| 232 |
|
| 233 |
#. type: TP |
| 234 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 235 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 236 |
#, no-wrap |
| 237 |
msgid "B<UFFDIO_REGISTER_MODE_WP> (since Linux 5.7)" |
| 238 |
msgstr "" |
| 239 |
|
| 240 |
#. type: Plain text |
| 241 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 242 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 243 |
msgid "" |
| 244 |
"When registered with B<UFFDIO_REGISTER_MODE_WP> mode, user-space will " |
| 245 |
"receive a page-fault notification when a write-protected page is written. " |
| 246 |
"The faulted thread will be stopped from execution until user-space write-" |
| 247 |
"unprotects the page using an B<UFFDIO_WRITEPROTECT> ioctl." |
| 248 |
msgstr "" |
| 249 |
|
| 250 |
#. type: Plain text |
| 251 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 252 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 253 |
msgid "" |
| 254 |
"Multiple modes can be enabled at the same time for the same memory range." |
| 255 |
msgstr "" |
| 256 |
|
| 257 |
#. type: Plain text |
| 258 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 259 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 260 |
msgid "" |
| 261 |
"Since Linux 4.14, a userfaultfd page-fault notification can selectively " |
| 262 |
"embed faulting thread ID information into the notification. One needs to " |
| 263 |
"enable this feature explicitly using the B<UFFD_FEATURE_THREAD_ID> feature " |
| 264 |
"bit when initializing the userfaultfd context. By default, thread ID " |
| 265 |
"reporting is disabled." |
| 266 |
msgstr "" |
| 267 |
|
| 268 |
#. type: SS |
| 269 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 270 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 271 |
#, no-wrap |
| 272 |
msgid "Usage" |
| 273 |
msgstr "" |
| 274 |
|
| 275 |
#. type: Plain text |
| 276 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 277 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 278 |
msgid "" |
| 279 |
"The userfaultfd mechanism is designed to allow a thread in a multithreaded " |
| 280 |
"program to perform user-space paging for the other threads in the process. " |
| 281 |
"When a page fault occurs for one of the regions registered to the " |
| 282 |
"userfaultfd object, the faulting thread is put to sleep and an event is " |
| 283 |
"generated that can be read via the userfaultfd file descriptor. The fault-" |
| 284 |
"handling thread reads events from this file descriptor and services them " |
| 285 |
"using the operations described in B<ioctl_userfaultfd>(2). When servicing " |
| 286 |
"the page fault events, the fault-handling thread can trigger a wake-up for " |
| 287 |
"the sleeping thread." |
| 288 |
msgstr "" |
| 289 |
|
| 290 |
#. type: Plain text |
| 291 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 292 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 293 |
msgid "" |
| 294 |
"It is possible for the faulting threads and the fault-handling threads to " |
| 295 |
"run in the context of different processes. In this case, these threads may " |
| 296 |
"belong to different programs, and the program that executes the faulting " |
| 297 |
"threads will not necessarily cooperate with the program that handles the " |
| 298 |
"page faults. In such non-cooperative mode, the process that monitors " |
| 299 |
"userfaultfd and handles page faults needs to be aware of the changes in the " |
| 300 |
"virtual memory layout of the faulting process to avoid memory corruption." |
| 301 |
msgstr "" |
| 302 |
|
| 303 |
#. type: Plain text |
| 304 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 305 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 306 |
msgid "" |
| 307 |
"Since Linux 4.11, userfaultfd can also notify the fault-handling threads " |
| 308 |
"about changes in the virtual memory layout of the faulting process. In " |
| 309 |
"addition, if the faulting process invokes B<fork>(2), the userfaultfd " |
| 310 |
"objects associated with the parent may be duplicated into the child process " |
| 311 |
"and the userfaultfd monitor will be notified (via the B<UFFD_EVENT_FORK> " |
| 312 |
"described below) about the file descriptor associated with the userfault " |
| 313 |
"objects created for the child process, which allows the userfaultfd monitor " |
| 314 |
"to perform user-space paging for the child process. Unlike page faults " |
| 315 |
"which have to be synchronous and require an explicit or implicit wakeup, all " |
| 316 |
"other events are delivered asynchronously and the non-cooperative process " |
| 317 |
"resumes execution as soon as the userfaultfd manager executes B<read>(2). " |
| 318 |
"The userfaultfd manager should carefully synchronize calls to B<UFFDIO_COPY> " |
| 319 |
"with the processing of events." |
| 320 |
msgstr "" |
| 321 |
|
| 322 |
#. #-#-#-#-# archlinux: userfaultfd.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 323 |
#. Regarding the preceding sentence, Mike Rapoport says: |
| 324 |
#. The major point here is that current events delivery model could be |
| 325 |
#. problematic for multi-threaded monitor. I even suspect that it would be |
| 326 |
#. impossible to ensure synchronization between page faults and non-page |
| 327 |
#. fault events in multi-threaded monitor. |
| 328 |
#. .P |
| 329 |
#. FIXME elaborate about non-cooperating mode, describe its limitations |
| 330 |
#. for kernels before Linux 4.11, features added in Linux 4.11 |
| 331 |
#. and limitations remaining in Linux 4.11 |
| 332 |
#. Maybe it's worth adding a dedicated sub-section... |
| 333 |
#. type: Plain text |
| 334 |
#. #-#-#-#-# debian-trixie: userfaultfd.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 335 |
#. Regarding the preceding sentence, Mike Rapoport says: |
| 336 |
#. The major point here is that current events delivery model could be |
| 337 |
#. problematic for multi-threaded monitor. I even suspect that it would be |
| 338 |
#. impossible to ensure synchronization between page faults and non-page |
| 339 |
#. fault events in multi-threaded monitor. |
| 340 |
#. .P |
| 341 |
#. FIXME elaborate about non-cooperating mode, describe its limitations |
| 342 |
#. for kernels before Linux 4.11, features added in Linux 4.11 |
| 343 |
#. and limitations remaining in Linux 4.11 |
| 344 |
#. Maybe it's worth adding a dedicated sub-section... |
| 345 |
#. type: Plain text |
| 346 |
#. #-#-#-#-# debian-unstable: userfaultfd.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 347 |
#. Regarding the preceding sentence, Mike Rapoport says: |
| 348 |
#. The major point here is that current events delivery model could be |
| 349 |
#. problematic for multi-threaded monitor. I even suspect that it would be |
| 350 |
#. impossible to ensure synchronization between page faults and non-page |
| 351 |
#. fault events in multi-threaded monitor. |
| 352 |
#. .P |
| 353 |
#. FIXME elaborate about non-cooperating mode, describe its limitations |
| 354 |
#. for kernels before Linux 4.11, features added in Linux 4.11 |
| 355 |
#. and limitations remaining in Linux 4.11 |
| 356 |
#. Maybe it's worth adding a dedicated sub-section... |
| 357 |
#. type: Plain text |
| 358 |
#. #-#-#-#-# fedora-44: userfaultfd.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 359 |
#. Regarding the preceding sentence, Mike Rapoport says: |
| 360 |
#. The major point here is that current events delivery model could be |
| 361 |
#. problematic for multi-threaded monitor. I even suspect that it would be |
| 362 |
#. impossible to ensure synchronization between page faults and non-page |
| 363 |
#. fault events in multi-threaded monitor. |
| 364 |
#. .P |
| 365 |
#. FIXME elaborate about non-cooperating mode, describe its limitations |
| 366 |
#. for kernels before Linux 4.11, features added in Linux 4.11 |
| 367 |
#. and limitations remaining in Linux 4.11 |
| 368 |
#. Maybe it's worth adding a dedicated sub-section... |
| 369 |
#. type: Plain text |
| 370 |
#. #-#-#-#-# fedora-rawhide: userfaultfd.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 371 |
#. Regarding the preceding sentence, Mike Rapoport says: |
| 372 |
#. The major point here is that current events delivery model could be |
| 373 |
#. problematic for multi-threaded monitor. I even suspect that it would be |
| 374 |
#. impossible to ensure synchronization between page faults and non-page |
| 375 |
#. fault events in multi-threaded monitor. |
| 376 |
#. .P |
| 377 |
#. FIXME elaborate about non-cooperating mode, describe its limitations |
| 378 |
#. for kernels before Linux 4.11, features added in Linux 4.11 |
| 379 |
#. and limitations remaining in Linux 4.11 |
| 380 |
#. Maybe it's worth adding a dedicated sub-section... |
| 381 |
#. type: Plain text |
| 382 |
#. #-#-#-#-# mageia-cauldron: userfaultfd.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 383 |
#. Regarding the preceding sentence, Mike Rapoport says: |
| 384 |
#. The major point here is that current events delivery model could be |
| 385 |
#. problematic for multi-threaded monitor. I even suspect that it would be |
| 386 |
#. impossible to ensure synchronization between page faults and non-page |
| 387 |
#. fault events in multi-threaded monitor. |
| 388 |
#. .P |
| 389 |
#. FIXME elaborate about non-cooperating mode, describe its limitations |
| 390 |
#. for kernels before Linux 4.11, features added in Linux 4.11 |
| 391 |
#. and limitations remaining in Linux 4.11 |
| 392 |
#. Maybe it's worth adding a dedicated sub-section... |
| 393 |
#. type: Plain text |
| 394 |
#. #-#-#-#-# opensuse-leap-16-1: userfaultfd.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 395 |
#. Regarding the preceding sentence, Mike Rapoport says: |
| 396 |
#. The major point here is that current events delivery model could be |
| 397 |
#. problematic for multi-threaded monitor. I even suspect that it would be |
| 398 |
#. impossible to ensure synchronization between page faults and non-page |
| 399 |
#. fault events in multi-threaded monitor. |
| 400 |
#. .P |
| 401 |
#. FIXME elaborate about non-cooperating mode, describe its limitations |
| 402 |
#. for kernels before Linux 4.11, features added in Linux 4.11 |
| 403 |
#. and limitations remaining in Linux 4.11 |
| 404 |
#. Maybe it's worth adding a dedicated sub-section... |
| 405 |
#. type: Plain text |
| 406 |
#. #-#-#-#-# opensuse-tumbleweed: userfaultfd.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 407 |
#. Regarding the preceding sentence, Mike Rapoport says: |
| 408 |
#. The major point here is that current events delivery model could be |
| 409 |
#. problematic for multi-threaded monitor. I even suspect that it would be |
| 410 |
#. impossible to ensure synchronization between page faults and non-page |
| 411 |
#. fault events in multi-threaded monitor. |
| 412 |
#. .P |
| 413 |
#. FIXME elaborate about non-cooperating mode, describe its limitations |
| 414 |
#. for kernels before Linux 4.11, features added in Linux 4.11 |
| 415 |
#. and limitations remaining in Linux 4.11 |
| 416 |
#. Maybe it's worth adding a dedicated sub-section... |
| 417 |
#. type: Plain text |
| 418 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 419 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 420 |
msgid "" |
| 421 |
"The current asynchronous model of the event delivery is optimal for single " |
| 422 |
"threaded non-cooperative userfaultfd manager implementations." |
| 423 |
msgstr "" |
| 424 |
|
| 425 |
#. type: Plain text |
| 426 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 427 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 428 |
msgid "" |
| 429 |
"Since Linux 5.7, userfaultfd is able to do synchronous page dirty tracking " |
| 430 |
"using the new write-protect register mode. One should check against the " |
| 431 |
"feature bit B<UFFD_FEATURE_PAGEFAULT_FLAG_WP> before using this feature. " |
| 432 |
"Similar to the original userfaultfd missing mode, the write-protect mode " |
| 433 |
"will generate a userfaultfd notification when the protected page is " |
| 434 |
"written. The user needs to resolve the page fault by unprotecting the " |
| 435 |
"faulted page and kicking the faulted thread to continue. For more " |
| 436 |
"information, please refer to the \"Userfaultfd write-protect mode\" section." |
| 437 |
msgstr "" |
| 438 |
|
| 439 |
#. type: SS |
| 440 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 441 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 442 |
#, no-wrap |
| 443 |
msgid "Userfaultfd operation" |
| 444 |
msgstr "" |
| 445 |
|
| 446 |
#. type: Plain text |
| 447 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 448 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 449 |
msgid "" |
| 450 |
"After the userfaultfd object is created with B<userfaultfd>(), the " |
| 451 |
"application must enable it using the B<UFFDIO_API> B<ioctl>(2) operation. " |
| 452 |
"This operation allows a two-step handshake between the kernel and user space " |
| 453 |
"to determine what API version and features the kernel supports, and then to " |
| 454 |
"enable those features user space wants. This operation must be performed " |
| 455 |
"before any of the other B<ioctl>(2) operations described below (or those " |
| 456 |
"operations fail with the B<EINVAL> error)." |
| 457 |
msgstr "" |
| 458 |
|
| 459 |
#. type: Plain text |
| 460 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 461 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 462 |
msgid "" |
| 463 |
"After a successful B<UFFDIO_API> operation, the application then registers " |
| 464 |
"memory address ranges using the B<UFFDIO_REGISTER> B<ioctl>(2) operation. " |
| 465 |
"After successful completion of a B<UFFDIO_REGISTER> operation, a page fault " |
| 466 |
"occurring in the requested memory range, and satisfying the mode defined at " |
| 467 |
"the registration time, will be forwarded by the kernel to the user-space " |
| 468 |
"application. The application can then use various (e.g., B<UFFDIO_COPY>, " |
| 469 |
"B<UFFDIO_ZEROPAGE>, or B<UFFDIO_CONTINUE>) B<ioctl>(2) operations to " |
| 470 |
"resolve the page fault." |
| 471 |
msgstr "" |
| 472 |
|
| 473 |
#. type: Plain text |
| 474 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 475 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 476 |
msgid "" |
| 477 |
"Since Linux 4.14, if the application sets the B<UFFD_FEATURE_SIGBUS> feature " |
| 478 |
"bit using the B<UFFDIO_API> B<ioctl>(2), no page-fault notification will be " |
| 479 |
"forwarded to user space. Instead a B<SIGBUS> signal is delivered to the " |
| 480 |
"faulting process. With this feature, userfaultfd can be used for robustness " |
| 481 |
"purposes to simply catch any access to areas within the registered address " |
| 482 |
"range that do not have pages allocated, without having to listen to " |
| 483 |
"userfaultfd events. No userfaultfd monitor will be required for dealing " |
| 484 |
"with such memory accesses. For example, this feature can be useful for " |
| 485 |
"applications that want to prevent the kernel from automatically allocating " |
| 486 |
"pages and filling holes in sparse files when the hole is accessed through a " |
| 487 |
"memory mapping." |
| 488 |
msgstr "" |
| 489 |
|
| 490 |
#. type: Plain text |
| 491 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 492 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 493 |
msgid "" |
| 494 |
"The B<UFFD_FEATURE_SIGBUS> feature is implicitly inherited through " |
| 495 |
"B<fork>(2) if used in combination with B<UFFD_FEATURE_FORK>." |
| 496 |
msgstr "" |
| 497 |
|
| 498 |
#. type: Plain text |
| 499 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 500 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 501 |
msgid "" |
| 502 |
"Details of the various B<ioctl>(2) operations can be found in " |
| 503 |
"B<ioctl_userfaultfd>(2)." |
| 504 |
msgstr "" |
| 505 |
|
| 506 |
#. type: Plain text |
| 507 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 508 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 509 |
msgid "" |
| 510 |
"Since Linux 4.11, events other than page-fault may enabled during " |
| 511 |
"B<UFFDIO_API> operation." |
| 512 |
msgstr "" |
| 513 |
|
| 514 |
#. type: Plain text |
| 515 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 516 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 517 |
msgid "" |
| 518 |
"Up to Linux 4.11, userfaultfd can be used only with anonymous private memory " |
| 519 |
"mappings. Since Linux 4.11, userfaultfd can be also used with hugetlbfs and " |
| 520 |
"shared memory mappings." |
| 521 |
msgstr "" |
| 522 |
|
| 523 |
#. type: SS |
| 524 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 525 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 526 |
#, no-wrap |
| 527 |
msgid "Userfaultfd write-protect mode (since Linux 5.7)" |
| 528 |
msgstr "" |
| 529 |
|
| 530 |
#. type: Plain text |
| 531 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 532 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 533 |
msgid "" |
| 534 |
"Since Linux 5.7, userfaultfd supports write-protect mode for anonymous " |
| 535 |
"memory. The user needs to first check availability of this feature using " |
| 536 |
"B<UFFDIO_API> ioctl against the feature bit " |
| 537 |
"B<UFFD_FEATURE_PAGEFAULT_FLAG_WP> before using this feature." |
| 538 |
msgstr "" |
| 539 |
|
| 540 |
#. type: Plain text |
| 541 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 542 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 543 |
msgid "" |
| 544 |
"Since Linux 5.19, the write-protection mode was also supported on shmem and " |
| 545 |
"hugetlbfs memory types. It can be detected with the feature bit " |
| 546 |
"B<UFFD_FEATURE_WP_HUGETLBFS_SHMEM>." |
| 547 |
msgstr "" |
| 548 |
|
| 549 |
#. type: Plain text |
| 550 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 551 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 552 |
msgid "" |
| 553 |
"To register with userfaultfd write-protect mode, the user needs to initiate " |
| 554 |
"the B<UFFDIO_REGISTER> ioctl with mode B<UFFDIO_REGISTER_MODE_WP> set. Note " |
| 555 |
"that it is legal to monitor the same memory range with multiple modes. For " |
| 556 |
"example, the user can do B<UFFDIO_REGISTER> with the mode set to " |
| 557 |
"B<UFFDIO_REGISTER_MODE_MISSING | UFFDIO_REGISTER_MODE_WP>. When there is " |
| 558 |
"only B<UFFDIO_REGISTER_MODE_WP> registered, user-space will I<not> receive " |
| 559 |
"any notification when a missing page is written. Instead, user-space will " |
| 560 |
"receive a write-protect page-fault notification only when an existing but " |
| 561 |
"write-protected page got written." |
| 562 |
msgstr "" |
| 563 |
|
| 564 |
#. type: Plain text |
| 565 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 566 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 567 |
msgid "" |
| 568 |
"After the B<UFFDIO_REGISTER> ioctl completed with B<UFFDIO_REGISTER_MODE_WP> " |
| 569 |
"mode set, the user can write-protect any existing memory within the range " |
| 570 |
"using the ioctl B<UFFDIO_WRITEPROTECT> where I<uffdio_writeprotect.mode> " |
| 571 |
"should be set to B<UFFDIO_WRITEPROTECT_MODE_WP>." |
| 572 |
msgstr "" |
| 573 |
|
| 574 |
#. type: Plain text |
| 575 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 576 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 577 |
msgid "" |
| 578 |
"When a write-protect event happens, user-space will receive a page-fault " |
| 579 |
"notification whose I<uffd_msg.pagefault.flags> will be with " |
| 580 |
"B<UFFD_PAGEFAULT_FLAG_WP> flag set. Note: since only writes can trigger " |
| 581 |
"this kind of fault, write-protect notifications will always have the " |
| 582 |
"B<UFFD_PAGEFAULT_FLAG_WRITE> bit set along with the " |
| 583 |
"B<UFFD_PAGEFAULT_FLAG_WP> bit." |
| 584 |
msgstr "" |
| 585 |
|
| 586 |
#. type: Plain text |
| 587 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 588 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 589 |
msgid "" |
| 590 |
"To resolve a write-protection page fault, the user should initiate another " |
| 591 |
"B<UFFDIO_WRITEPROTECT> ioctl, whose I<uffd_msg.pagefault.flags> should have " |
| 592 |
"the flag B<UFFDIO_WRITEPROTECT_MODE_WP> cleared upon the faulted page or " |
| 593 |
"range." |
| 594 |
msgstr "" |
| 595 |
|
| 596 |
#. type: SS |
| 597 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 598 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 599 |
#, no-wrap |
| 600 |
msgid "Userfaultfd minor fault mode (since Linux 5.13)" |
| 601 |
msgstr "" |
| 602 |
|
| 603 |
#. type: Plain text |
| 604 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 605 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 606 |
msgid "" |
| 607 |
"Since Linux 5.13, userfaultfd supports minor fault mode. In this mode, " |
| 608 |
"fault messages are produced not for major faults (where the page was " |
| 609 |
"missing), but rather for minor faults, where a page exists in the page " |
| 610 |
"cache, but the page table entries are not yet present. The user needs to " |
| 611 |
"first check availability of this feature using the B<UFFDIO_API> ioctl with " |
| 612 |
"the appropriate feature bits set before using this feature: " |
| 613 |
"B<UFFD_FEATURE_MINOR_HUGETLBFS> since Linux 5.13, or " |
| 614 |
"B<UFFD_FEATURE_MINOR_SHMEM> since Linux 5.14." |
| 615 |
msgstr "" |
| 616 |
|
| 617 |
#. type: Plain text |
| 618 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 619 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 620 |
msgid "" |
| 621 |
"To register with userfaultfd minor fault mode, the user needs to initiate " |
| 622 |
"the B<UFFDIO_REGISTER> ioctl with mode B<UFFD_REGISTER_MODE_MINOR> set." |
| 623 |
msgstr "" |
| 624 |
|
| 625 |
#. type: Plain text |
| 626 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 627 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 628 |
msgid "" |
| 629 |
"When a minor fault occurs, user-space will receive a page-fault notification " |
| 630 |
"whose I<uffd_msg.pagefault.flags> will have the B<UFFD_PAGEFAULT_FLAG_MINOR> " |
| 631 |
"flag set." |
| 632 |
msgstr "" |
| 633 |
|
| 634 |
#. type: Plain text |
| 635 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 636 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 637 |
msgid "" |
| 638 |
"To resolve a minor page fault, the handler should decide whether or not the " |
| 639 |
"existing page contents need to be modified first. If so, this should be " |
| 640 |
"done in-place via a second, non-userfaultfd-registered mapping to the same " |
| 641 |
"backing page (e.g., by mapping the shmem or hugetlbfs file twice). Once the " |
| 642 |
"page is considered \"up to date\", the fault can be resolved by initiating " |
| 643 |
"an B<UFFDIO_CONTINUE> ioctl, which installs the page table entries and (by " |
| 644 |
"default) wakes up the faulting thread(s)." |
| 645 |
msgstr "" |
| 646 |
|
| 647 |
#. type: Plain text |
| 648 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 649 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 650 |
msgid "" |
| 651 |
"Minor fault mode supports only hugetlbfs-backed (since Linux 5.13) and " |
| 652 |
"shmem-backed (since Linux 5.14) memory." |
| 653 |
msgstr "" |
| 654 |
|
| 655 |
#. type: SS |
| 656 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 657 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 658 |
#, no-wrap |
| 659 |
msgid "Reading from the userfaultfd structure" |
| 660 |
msgstr "" |
| 661 |
|
| 662 |
#. type: Plain text |
| 663 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 664 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 665 |
msgid "" |
| 666 |
"Each B<read>(2) from the userfaultfd file descriptor returns one or more " |
| 667 |
"I<uffd_msg> structures, each of which describes a page-fault event or an " |
| 668 |
"event required for the non-cooperative userfaultfd usage:" |
| 669 |
msgstr "" |
| 670 |
|
| 671 |
#. type: Plain text |
| 672 |
#: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 673 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 674 |
#, no-wrap |
| 675 |
msgid "" |
| 676 |
"struct uffd_msg {\n" |
| 677 |
" __u8 event; /* Type of event */\n" |
| 678 |
" ...\n" |
| 679 |
" union {\n" |
| 680 |
" struct {\n" |
| 681 |
" __u64 flags; /* Flags describing fault */\n" |
| 682 |
" __u64 address; /* Faulting address */\n" |
| 683 |
" union {\n" |
| 684 |
" __u32 ptid; /* Thread ID of the fault */\n" |
| 685 |
" } feat;\n" |
| 686 |
" } pagefault;\n" |
| 687 |
"\\&\n" |
| 688 |
" struct { /* Since Linux 4.11 */\n" |
| 689 |
" __u32 ufd; /* Userfault file descriptor\n" |
| 690 |
" of the child process */\n" |
| 691 |
" } fork;\n" |
| 692 |
"\\&\n" |
| 693 |
" struct { /* Since Linux 4.11 */\n" |
| 694 |
" __u64 from; /* Old address of remapped area */\n" |
| 695 |
" __u64 to; /* New address of remapped area */\n" |
| 696 |
" __u64 len; /* Original mapping size */\n" |
| 697 |
" } remap;\n" |
| 698 |
"\\&\n" |
| 699 |
" struct { /* Since Linux 4.11 */\n" |
| 700 |
" __u64 start; /* Start address of removed area */\n" |
| 701 |
" __u64 end; /* End address of removed area */\n" |
| 702 |
" } remove;\n" |
| 703 |
" ...\n" |
| 704 |
" } arg;\n" |
| 705 |
"\\&\n" |
| 706 |
" /* Padding fields omitted */\n" |
| 707 |
"} __packed;\n" |
| 708 |
msgstr "" |
| 709 |
|
| 710 |
#. type: Plain text |
| 711 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 712 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 713 |
msgid "" |
| 714 |
"If multiple events are available and the supplied buffer is large enough, " |
| 715 |
"B<read>(2) returns as many events as will fit in the supplied buffer. If " |
| 716 |
"the buffer supplied to B<read>(2) is smaller than the size of the " |
| 717 |
"I<uffd_msg> structure, the B<read>(2) fails with the error B<EINVAL>." |
| 718 |
msgstr "" |
| 719 |
|
| 720 |
#. type: Plain text |
| 721 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 722 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 723 |
msgid "The fields set in the I<uffd_msg> structure are as follows:" |
| 724 |
msgstr "" |
| 725 |
|
| 726 |
#. type: TP |
| 727 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 728 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 729 |
#, no-wrap |
| 730 |
msgid "I<event>" |
| 731 |
msgstr "" |
| 732 |
|
| 733 |
#. type: Plain text |
| 734 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 735 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 736 |
msgid "" |
| 737 |
"The type of event. Depending of the event type, different fields of the " |
| 738 |
"I<arg> union represent details required for the event processing. The non-" |
| 739 |
"page-fault events are generated only when appropriate feature is enabled " |
| 740 |
"during API handshake with B<UFFDIO_API> B<ioctl>(2)." |
| 741 |
msgstr "" |
| 742 |
|
| 743 |
#. type: Plain text |
| 744 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 745 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 746 |
msgid "The following values can appear in the I<event> field:" |
| 747 |
msgstr "" |
| 748 |
|
| 749 |
#. type: TP |
| 750 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 751 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 752 |
#, no-wrap |
| 753 |
msgid "B<UFFD_EVENT_PAGEFAULT> (since Linux 4.3)" |
| 754 |
msgstr "" |
| 755 |
|
| 756 |
#. type: Plain text |
| 757 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 758 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 759 |
msgid "" |
| 760 |
"A page-fault event. The page-fault details are available in the " |
| 761 |
"I<pagefault> field." |
| 762 |
msgstr "" |
| 763 |
|
| 764 |
#. type: TP |
| 765 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 766 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 767 |
#, no-wrap |
| 768 |
msgid "B<UFFD_EVENT_FORK> (since Linux 4.11)" |
| 769 |
msgstr "" |
| 770 |
|
| 771 |
#. FIXME describe duplication of userfault file descriptor during fork |
| 772 |
#. type: Plain text |
| 773 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 774 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 775 |
msgid "" |
| 776 |
"Generated when the faulting process invokes B<fork>(2) (or B<clone>(2) " |
| 777 |
"without the B<CLONE_VM> flag). The event details are available in the " |
| 778 |
"I<fork> field." |
| 779 |
msgstr "" |
| 780 |
|
| 781 |
#. type: TP |
| 782 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 783 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 784 |
#, no-wrap |
| 785 |
msgid "B<UFFD_EVENT_REMAP> (since Linux 4.11)" |
| 786 |
msgstr "" |
| 787 |
|
| 788 |
#. type: Plain text |
| 789 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 790 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 791 |
msgid "" |
| 792 |
"Generated when the faulting process invokes B<mremap>(2). The event details " |
| 793 |
"are available in the I<remap> field." |
| 794 |
msgstr "" |
| 795 |
|
| 796 |
#. type: TP |
| 797 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 798 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 799 |
#, no-wrap |
| 800 |
msgid "B<UFFD_EVENT_REMOVE> (since Linux 4.11)" |
| 801 |
msgstr "" |
| 802 |
|
| 803 |
#. type: Plain text |
| 804 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 805 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 806 |
msgid "" |
| 807 |
"Generated when the faulting process invokes B<madvise>(2) with " |
| 808 |
"B<MADV_DONTNEED> or B<MADV_REMOVE> advice. The event details are available " |
| 809 |
"in the I<remove> field." |
| 810 |
msgstr "" |
| 811 |
|
| 812 |
#. type: TP |
| 813 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 814 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 815 |
#, no-wrap |
| 816 |
msgid "B<UFFD_EVENT_UNMAP> (since Linux 4.11)" |
| 817 |
msgstr "" |
| 818 |
|
| 819 |
#. type: Plain text |
| 820 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 821 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 822 |
msgid "" |
| 823 |
"Generated when the faulting process unmaps a memory range, either explicitly " |
| 824 |
"using B<munmap>(2) or implicitly during B<mmap>(2) or B<mremap>(2). The " |
| 825 |
"event details are available in the I<remove> field." |
| 826 |
msgstr "" |
| 827 |
|
| 828 |
#. type: TP |
| 829 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 830 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 831 |
#, no-wrap |
| 832 |
msgid "I<pagefault.address>" |
| 833 |
msgstr "" |
| 834 |
|
| 835 |
#. type: Plain text |
| 836 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 837 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 838 |
msgid "The address that triggered the page fault." |
| 839 |
msgstr "" |
| 840 |
|
| 841 |
#. type: TP |
| 842 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 843 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 844 |
#, no-wrap |
| 845 |
msgid "I<pagefault.flags>" |
| 846 |
msgstr "" |
| 847 |
|
| 848 |
#. type: Plain text |
| 849 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 850 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 851 |
msgid "" |
| 852 |
"A bit mask of flags that describe the event. For B<UFFD_EVENT_PAGEFAULT>, " |
| 853 |
"the following flag may appear:" |
| 854 |
msgstr "" |
| 855 |
|
| 856 |
#. type: TP |
| 857 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 858 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 859 |
#, no-wrap |
| 860 |
msgid "B<UFFD_PAGEFAULT_FLAG_WP>" |
| 861 |
msgstr "" |
| 862 |
|
| 863 |
#. type: Plain text |
| 864 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 865 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 866 |
msgid "If this flag is set, then the fault was a write-protect fault." |
| 867 |
msgstr "" |
| 868 |
|
| 869 |
#. type: TP |
| 870 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 871 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 872 |
#, no-wrap |
| 873 |
msgid "B<UFFD_PAGEFAULT_FLAG_MINOR>" |
| 874 |
msgstr "" |
| 875 |
|
| 876 |
#. type: Plain text |
| 877 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 878 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 879 |
msgid "If this flag is set, then the fault was a minor fault." |
| 880 |
msgstr "" |
| 881 |
|
| 882 |
#. type: TP |
| 883 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 884 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 885 |
#, no-wrap |
| 886 |
msgid "B<UFFD_PAGEFAULT_FLAG_WRITE>" |
| 887 |
msgstr "" |
| 888 |
|
| 889 |
#. type: Plain text |
| 890 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 891 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 892 |
msgid "If this flag is set, then the fault was a write fault." |
| 893 |
msgstr "" |
| 894 |
|
| 895 |
#. type: Plain text |
| 896 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 897 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 898 |
msgid "" |
| 899 |
"If neither B<UFFD_PAGEFAULT_FLAG_WP> nor B<UFFD_PAGEFAULT_FLAG_MINOR> are " |
| 900 |
"set, then the fault was a missing fault." |
| 901 |
msgstr "" |
| 902 |
|
| 903 |
#. type: TP |
| 904 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 905 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 906 |
#, no-wrap |
| 907 |
msgid "I<pagefault.feat.pid>" |
| 908 |
msgstr "" |
| 909 |
|
| 910 |
#. type: Plain text |
| 911 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 912 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 913 |
msgid "The thread ID that triggered the page fault." |
| 914 |
msgstr "" |
| 915 |
|
| 916 |
#. type: TP |
| 917 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 918 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 919 |
#, no-wrap |
| 920 |
msgid "I<fork.ufd>" |
| 921 |
msgstr "" |
| 922 |
|
| 923 |
#. type: Plain text |
| 924 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 925 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 926 |
msgid "" |
| 927 |
"The file descriptor associated with the userfault object created for the " |
| 928 |
"child created by B<fork>(2)." |
| 929 |
msgstr "" |
| 930 |
|
| 931 |
#. type: TP |
| 932 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 933 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 934 |
#, no-wrap |
| 935 |
msgid "I<remap.from>" |
| 936 |
msgstr "" |
| 937 |
|
| 938 |
#. type: Plain text |
| 939 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 940 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 941 |
msgid "" |
| 942 |
"The original address of the memory range that was remapped using " |
| 943 |
"B<mremap>(2)." |
| 944 |
msgstr "" |
| 945 |
|
| 946 |
#. type: TP |
| 947 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 948 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 949 |
#, no-wrap |
| 950 |
msgid "I<remap.to>" |
| 951 |
msgstr "" |
| 952 |
|
| 953 |
#. type: Plain text |
| 954 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 955 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 956 |
msgid "" |
| 957 |
"The new address of the memory range that was remapped using B<mremap>(2)." |
| 958 |
msgstr "" |
| 959 |
|
| 960 |
#. type: TP |
| 961 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 962 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 963 |
#, no-wrap |
| 964 |
msgid "I<remap.len>" |
| 965 |
msgstr "" |
| 966 |
|
| 967 |
#. type: Plain text |
| 968 |
#: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 969 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 970 |
msgid "" |
| 971 |
"The original size of the memory range that was remapped using B<mremap>(2)." |
| 972 |
msgstr "" |
| 973 |
|
| 974 |
#. type: TP |
| 975 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 976 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 977 |
#, no-wrap |
| 978 |
msgid "I<remove.start>" |
| 979 |
msgstr "" |
| 980 |
|
| 981 |
#. type: Plain text |
| 982 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 983 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 984 |
msgid "" |
| 985 |
"The start address of the memory range that was freed using B<madvise>(2) or " |
| 986 |
"unmapped" |
| 987 |
msgstr "" |
| 988 |
|
| 989 |
#. type: TP |
| 990 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 991 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 992 |
#, no-wrap |
| 993 |
msgid "I<remove.end>" |
| 994 |
msgstr "" |
| 995 |
|
| 996 |
#. type: Plain text |
| 997 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 998 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 999 |
msgid "" |
| 1000 |
"The end address of the memory range that was freed using B<madvise>(2) or " |
| 1001 |
"unmapped" |
| 1002 |
msgstr "" |
| 1003 |
|
| 1004 |
#. type: Plain text |
| 1005 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1006 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1007 |
msgid "" |
| 1008 |
"A B<read>(2) on a userfaultfd file descriptor can fail with the following " |
| 1009 |
"errors:" |
| 1010 |
msgstr "" |
| 1011 |
|
| 1012 |
#. type: TP |
| 1013 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1014 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1015 |
#, no-wrap |
| 1016 |
msgid "B<EINVAL>" |
| 1017 |
msgstr "" |
| 1018 |
|
| 1019 |
#. type: Plain text |
| 1020 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1021 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1022 |
msgid "" |
| 1023 |
"The userfaultfd object has not yet been enabled using the B<UFFDIO_API> " |
| 1024 |
"B<ioctl>(2) operation" |
| 1025 |
msgstr "" |
| 1026 |
|
| 1027 |
#. FIXME What is the reason for this seemingly odd behavior with respect |
| 1028 |
#. to the O_NONBLOCK flag? (see userfaultfd_poll() in fs/userfaultfd.c). |
| 1029 |
#. Something needs to be said about this. |
| 1030 |
#. type: Plain text |
| 1031 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1032 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1033 |
msgid "" |
| 1034 |
"If the B<O_NONBLOCK> flag is enabled in the associated open file " |
| 1035 |
"description, the userfaultfd file descriptor can be monitored with " |
| 1036 |
"B<poll>(2), B<select>(2), and B<epoll>(7). When events are available, the " |
| 1037 |
"file descriptor indicates as readable. If the B<O_NONBLOCK> flag is not " |
| 1038 |
"enabled, then B<poll>(2) (always) indicates the file as having a B<POLLERR> " |
| 1039 |
"condition, and B<select>(2) indicates the file descriptor as both readable " |
| 1040 |
"and writable." |
| 1041 |
msgstr "" |
| 1042 |
|
| 1043 |
#. type: SH |
| 1044 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1045 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1046 |
#, no-wrap |
| 1047 |
msgid "RETURN VALUE" |
| 1048 |
msgstr "" |
| 1049 |
|
| 1050 |
#. type: Plain text |
| 1051 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1052 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1053 |
msgid "" |
| 1054 |
"On success, B<userfaultfd>() returns a new file descriptor that refers to " |
| 1055 |
"the userfaultfd object. On error, -1 is returned, and I<errno> is set to " |
| 1056 |
"indicate the error." |
| 1057 |
msgstr "" |
| 1058 |
|
| 1059 |
#. type: SH |
| 1060 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1061 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1062 |
#, no-wrap |
| 1063 |
msgid "ERRORS" |
| 1064 |
msgstr "" |
| 1065 |
|
| 1066 |
#. type: Plain text |
| 1067 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1068 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1069 |
msgid "An unsupported value was specified in I<flags>." |
| 1070 |
msgstr "" |
| 1071 |
|
| 1072 |
#. type: TP |
| 1073 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1074 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1075 |
#, no-wrap |
| 1076 |
msgid "B<EMFILE>" |
| 1077 |
msgstr "" |
| 1078 |
|
| 1079 |
#. type: Plain text |
| 1080 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1081 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1082 |
msgid "" |
| 1083 |
"The per-process limit on the number of open file descriptors has been reached" |
| 1084 |
msgstr "" |
| 1085 |
|
| 1086 |
#. type: TP |
| 1087 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1088 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1089 |
#, no-wrap |
| 1090 |
msgid "B<ENFILE>" |
| 1091 |
msgstr "" |
| 1092 |
|
| 1093 |
#. type: Plain text |
| 1094 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1095 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1096 |
msgid "" |
| 1097 |
"The system-wide limit on the total number of open files has been reached." |
| 1098 |
msgstr "" |
| 1099 |
|
| 1100 |
#. type: TP |
| 1101 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1102 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1103 |
#, no-wrap |
| 1104 |
msgid "B<ENOMEM>" |
| 1105 |
msgstr "" |
| 1106 |
|
| 1107 |
#. type: Plain text |
| 1108 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1109 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1110 |
msgid "Insufficient kernel memory was available." |
| 1111 |
msgstr "" |
| 1112 |
|
| 1113 |
#. type: TP |
| 1114 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1115 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1116 |
#, no-wrap |
| 1117 |
msgid "B<EPERM> (since Linux 5.2)" |
| 1118 |
msgstr "" |
| 1119 |
|
| 1120 |
#. cefdca0a86be517bc390fc4541e3674b8e7803b0 |
| 1121 |
#. type: Plain text |
| 1122 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1123 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1124 |
msgid "" |
| 1125 |
"The caller is not privileged (does not have the B<CAP_SYS_PTRACE> capability " |
| 1126 |
"in the initial user namespace), and I</proc/sys/vm/unprivileged_userfaultfd> " |
| 1127 |
"has the value 0." |
| 1128 |
msgstr "" |
| 1129 |
|
| 1130 |
#. type: SH |
| 1131 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1132 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1133 |
#, no-wrap |
| 1134 |
msgid "STANDARDS" |
| 1135 |
msgstr "" |
| 1136 |
|
| 1137 |
#. type: Plain text |
| 1138 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1139 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1140 |
msgid "Linux." |
| 1141 |
msgstr "" |
| 1142 |
|
| 1143 |
#. type: SH |
| 1144 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1145 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1146 |
#, no-wrap |
| 1147 |
msgid "HISTORY" |
| 1148 |
msgstr "" |
| 1149 |
|
| 1150 |
#. type: Plain text |
| 1151 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1152 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1153 |
msgid "Linux 4.3." |
| 1154 |
msgstr "" |
| 1155 |
|
| 1156 |
#. type: Plain text |
| 1157 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1158 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1159 |
msgid "" |
| 1160 |
"Support for hugetlbfs and shared memory areas and non-page-fault events was " |
| 1161 |
"added in Linux 4.11" |
| 1162 |
msgstr "" |
| 1163 |
|
| 1164 |
#. type: SH |
| 1165 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1166 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1167 |
#, no-wrap |
| 1168 |
msgid "NOTES" |
| 1169 |
msgstr "" |
| 1170 |
|
| 1171 |
#. type: Plain text |
| 1172 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1173 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1174 |
msgid "" |
| 1175 |
"The userfaultfd mechanism can be used as an alternative to traditional user-" |
| 1176 |
"space paging techniques based on the use of the B<SIGSEGV> signal and " |
| 1177 |
"B<mmap>(2). It can also be used to implement lazy restore for checkpoint/" |
| 1178 |
"restore mechanisms, as well as post-copy migration to allow (nearly) " |
| 1179 |
"uninterrupted execution when transferring virtual machines and Linux " |
| 1180 |
"containers from one host to another." |
| 1181 |
msgstr "" |
| 1182 |
|
| 1183 |
#. type: SH |
| 1184 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1185 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1186 |
#, no-wrap |
| 1187 |
msgid "BUGS" |
| 1188 |
msgstr "" |
| 1189 |
|
| 1190 |
#. type: Plain text |
| 1191 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1192 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1193 |
msgid "" |
| 1194 |
"If the B<UFFD_FEATURE_EVENT_FORK> is enabled and a system call from the " |
| 1195 |
"B<fork>(2) family is interrupted by a signal or failed, a stale userfaultfd " |
| 1196 |
"descriptor might be created. In this case, a spurious B<UFFD_EVENT_FORK> " |
| 1197 |
"will be delivered to the userfaultfd monitor." |
| 1198 |
msgstr "" |
| 1199 |
|
| 1200 |
#. type: SH |
| 1201 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1202 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1203 |
#, no-wrap |
| 1204 |
msgid "EXAMPLES" |
| 1205 |
msgstr "" |
| 1206 |
|
| 1207 |
#. type: Plain text |
| 1208 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1209 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1210 |
msgid "" |
| 1211 |
"The program below demonstrates the use of the userfaultfd mechanism. The " |
| 1212 |
"program creates two threads, one of which acts as the page-fault handler for " |
| 1213 |
"the process, for the pages in a demand-page zero region created using " |
| 1214 |
"B<mmap>(2)." |
| 1215 |
msgstr "" |
| 1216 |
|
| 1217 |
#. type: Plain text |
| 1218 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1219 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1220 |
msgid "" |
| 1221 |
"The program takes one command-line argument, which is the number of pages " |
| 1222 |
"that will be created in a mapping whose page faults will be handled via " |
| 1223 |
"userfaultfd. After creating a userfaultfd object, the program then creates " |
| 1224 |
"an anonymous private mapping of the specified size and registers the address " |
| 1225 |
"range of that mapping using the B<UFFDIO_REGISTER> B<ioctl>(2) operation. " |
| 1226 |
"The program then creates a second thread that will perform the task of " |
| 1227 |
"handling page faults." |
| 1228 |
msgstr "" |
| 1229 |
|
| 1230 |
#. type: Plain text |
| 1231 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1232 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1233 |
msgid "" |
| 1234 |
"The main thread then walks through the pages of the mapping fetching bytes " |
| 1235 |
"from successive pages. Because the pages have not yet been accessed, the " |
| 1236 |
"first access of a byte in each page will trigger a page-fault event on the " |
| 1237 |
"userfaultfd file descriptor." |
| 1238 |
msgstr "" |
| 1239 |
|
| 1240 |
#. type: Plain text |
| 1241 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1242 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1243 |
msgid "" |
| 1244 |
"Each of the page-fault events is handled by the second thread, which sits in " |
| 1245 |
"a loop processing input from the userfaultfd file descriptor. In each loop " |
| 1246 |
"iteration, the second thread first calls B<poll>(2) to check the state of " |
| 1247 |
"the file descriptor, and then reads an event from the file descriptor. All " |
| 1248 |
"such events should be B<UFFD_EVENT_PAGEFAULT> events, which the thread " |
| 1249 |
"handles by copying a page of data into the faulting region using the " |
| 1250 |
"B<UFFDIO_COPY> B<ioctl>(2) operation." |
| 1251 |
msgstr "" |
| 1252 |
|
| 1253 |
#. type: Plain text |
| 1254 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1255 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1256 |
msgid "The following is an example of what we see when running the program:" |
| 1257 |
msgstr "" |
| 1258 |
|
| 1259 |
#. type: Plain text |
| 1260 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 1261 |
#: opensuse-tumbleweed |
| 1262 |
#, no-wrap |
| 1263 |
msgid "" |
| 1264 |
"$B< ./userfaultfd_demo 3>;\n" |
| 1265 |
"Address returned by mmap() = 0x7fd30106c000\n" |
| 1266 |
"\\&\n" |
| 1267 |
"fault_handler_thread():\n" |
| 1268 |
" poll() returns: nready = 1; POLLIN = 1; POLLERR = 0\n" |
| 1269 |
" UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106c00f\n" |
| 1270 |
" (uffdio_copy.copy returned 4096)\n" |
| 1271 |
"Read address 0x7fd30106c00f in main(): A\n" |
| 1272 |
"Read address 0x7fd30106c40f in main(): A\n" |
| 1273 |
"Read address 0x7fd30106c80f in main(): A\n" |
| 1274 |
"Read address 0x7fd30106cc0f in main(): A\n" |
| 1275 |
"\\&\n" |
| 1276 |
"fault_handler_thread():\n" |
| 1277 |
" poll() returns: nready = 1; POLLIN = 1; POLLERR = 0\n" |
| 1278 |
" UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106d00f\n" |
| 1279 |
" (uffdio_copy.copy returned 4096)\n" |
| 1280 |
"Read address 0x7fd30106d00f in main(): B\n" |
| 1281 |
"Read address 0x7fd30106d40f in main(): B\n" |
| 1282 |
"Read address 0x7fd30106d80f in main(): B\n" |
| 1283 |
"Read address 0x7fd30106dc0f in main(): B\n" |
| 1284 |
"\\&\n" |
| 1285 |
"fault_handler_thread():\n" |
| 1286 |
" poll() returns: nready = 1; POLLIN = 1; POLLERR = 0\n" |
| 1287 |
" UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106e00f\n" |
| 1288 |
" (uffdio_copy.copy returned 4096)\n" |
| 1289 |
"Read address 0x7fd30106e00f in main(): C\n" |
| 1290 |
"Read address 0x7fd30106e40f in main(): C\n" |
| 1291 |
"Read address 0x7fd30106e80f in main(): C\n" |
| 1292 |
"Read address 0x7fd30106ec0f in main(): C\n" |
| 1293 |
msgstr "" |
| 1294 |
|
| 1295 |
#. type: SS |
| 1296 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1297 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1298 |
#, no-wrap |
| 1299 |
msgid "Program source" |
| 1300 |
msgstr "" |
| 1301 |
|
| 1302 |
#. type: Plain text |
| 1303 |
#: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed |
| 1304 |
#, no-wrap |
| 1305 |
msgid "" |
| 1306 |
"/* userfaultfd_demo.c\n" |
| 1307 |
"\\&\n" |
| 1308 |
" Licensed under the GNU General Public License version 2 or later.\n" |
| 1309 |
"*/\n" |
| 1310 |
"#define _GNU_SOURCE\n" |
| 1311 |
"#include E<lt>err.hE<gt>\n" |
| 1312 |
"#include E<lt>errno.hE<gt>\n" |
| 1313 |
"#include E<lt>fcntl.hE<gt>\n" |
| 1314 |
"#include E<lt>inttypes.hE<gt>\n" |
| 1315 |
"#include E<lt>linux/userfaultfd.hE<gt>\n" |
| 1316 |
"#include E<lt>poll.hE<gt>\n" |
| 1317 |
"#include E<lt>pthread.hE<gt>\n" |
| 1318 |
"#include E<lt>stdio.hE<gt>\n" |
| 1319 |
"#include E<lt>stdlib.hE<gt>\n" |
| 1320 |
"#include E<lt>string.hE<gt>\n" |
| 1321 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 1322 |
"#include E<lt>sys/mman.hE<gt>\n" |
| 1323 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 1324 |
"#include E<lt>unistd.hE<gt>\n" |
| 1325 |
"\\&\n" |
| 1326 |
"static int page_size;\n" |
| 1327 |
"\\&\n" |
| 1328 |
"static void *\n" |
| 1329 |
"fault_handler_thread(void *arg)\n" |
| 1330 |
"{\n" |
| 1331 |
" long uffd; /* userfaultfd file descriptor */\n" |
| 1332 |
"\\&\n" |
| 1333 |
" static int fault_cnt = 0; /* Number of faults so far handled */\n" |
| 1334 |
" static char *page = NULL;\n" |
| 1335 |
" static struct uffd_msg msg; /* Data read from userfaultfd */\n" |
| 1336 |
"\\&\n" |
| 1337 |
" uffd = (long) arg;\n" |
| 1338 |
"\\&\n" |
| 1339 |
" /* Create a page that will be copied into the faulting region. */\n" |
| 1340 |
"\\&\n" |
| 1341 |
" if (page == NULL) {\n" |
| 1342 |
" page = mmap(NULL, page_size, PROT_READ | PROT_WRITE,\n" |
| 1343 |
" MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n" |
| 1344 |
" if (page == MAP_FAILED)\n" |
| 1345 |
" err(EXIT_FAILURE, \"mmap\");\n" |
| 1346 |
" }\n" |
| 1347 |
"\\&\n" |
| 1348 |
" /* Loop, handling incoming events on the userfaultfd\n" |
| 1349 |
" file descriptor. */\n" |
| 1350 |
"\\&\n" |
| 1351 |
" for (;;) {\n" |
| 1352 |
" int nready;\n" |
| 1353 |
" ssize_t nread;\n" |
| 1354 |
" struct pollfd pollfd;\n" |
| 1355 |
" struct uffdio_copy uffdio_copy;\n" |
| 1356 |
"\\&\n" |
| 1357 |
" /* See what poll() tells us about the userfaultfd. */\n" |
| 1358 |
"\\&\n" |
| 1359 |
" pollfd.fd = uffd;\n" |
| 1360 |
" pollfd.events = POLLIN;\n" |
| 1361 |
" nready = poll(&pollfd, 1, -1);\n" |
| 1362 |
" if (nready == -1)\n" |
| 1363 |
" err(EXIT_FAILURE, \"poll\");\n" |
| 1364 |
"\\&\n" |
| 1365 |
" printf(\"\\[rs]nfault_handler_thread():\\[rs]n\");\n" |
| 1366 |
" printf(\" poll() returns: nready = %d; \"\n" |
| 1367 |
" \"POLLIN = %d; POLLERR = %d\\[rs]n\", nready,\n" |
| 1368 |
" (pollfd.revents & POLLIN) != 0,\n" |
| 1369 |
" (pollfd.revents & POLLERR) != 0);\n" |
| 1370 |
"\\&\n" |
| 1371 |
" /* Read an event from the userfaultfd. */\n" |
| 1372 |
"\\&\n" |
| 1373 |
" nread = read(uffd, &msg, sizeof(msg));\n" |
| 1374 |
" if (nread == 0) {\n" |
| 1375 |
" printf(\"EOF on userfaultfd!\\[rs]n\");\n" |
| 1376 |
" exit(EXIT_FAILURE);\n" |
| 1377 |
" }\n" |
| 1378 |
"\\&\n" |
| 1379 |
" if (nread == -1)\n" |
| 1380 |
" err(EXIT_FAILURE, \"read\");\n" |
| 1381 |
"\\&\n" |
| 1382 |
" /* We expect only one kind of event; verify that assumption. */\n" |
| 1383 |
"\\&\n" |
| 1384 |
" if (msg.event != UFFD_EVENT_PAGEFAULT) {\n" |
| 1385 |
" fprintf(stderr, \"Unexpected event on userfaultfd\\[rs]n\");\n" |
| 1386 |
" exit(EXIT_FAILURE);\n" |
| 1387 |
" }\n" |
| 1388 |
"\\&\n" |
| 1389 |
" /* Display info about the page-fault event. */\n" |
| 1390 |
"\\&\n" |
| 1391 |
" printf(\" UFFD_EVENT_PAGEFAULT event: \");\n" |
| 1392 |
" printf(\"flags = %w64x; \", msg.arg.pagefault.flags);\n" |
| 1393 |
" printf(\"address = %w64x\\[rs]n\", msg.arg.pagefault.address);\n" |
| 1394 |
"\\&\n" |
| 1395 |
" /* Copy the page pointed to by \\[aq]page\\[aq] into the faulting\n" |
| 1396 |
" region. Vary the contents that are copied in, so that it\n" |
| 1397 |
" is more obvious that each fault is handled separately. */\n" |
| 1398 |
"\\&\n" |
| 1399 |
" memset(page, \\[aq]A\\[aq] + fault_cnt % 20, page_size);\n" |
| 1400 |
" fault_cnt++;\n" |
| 1401 |
"\\&\n" |
| 1402 |
" uffdio_copy.src = (unsigned long) page;\n" |
| 1403 |
"\\&\n" |
| 1404 |
" /* We need to handle page faults in units of pages(!).\n" |
| 1405 |
" So, round faulting address down to page boundary. */\n" |
| 1406 |
"\\&\n" |
| 1407 |
" uffdio_copy.dst = (unsigned long) msg.arg.pagefault.address &\n" |
| 1408 |
" \\[ti](page_size - 1);\n" |
| 1409 |
" uffdio_copy.len = page_size;\n" |
| 1410 |
" uffdio_copy.mode = 0;\n" |
| 1411 |
" uffdio_copy.copy = 0;\n" |
| 1412 |
" if (ioctl(uffd, UFFDIO_COPY, &uffdio_copy) == -1)\n" |
| 1413 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_COPY\");\n" |
| 1414 |
"\\&\n" |
| 1415 |
" printf(\" (uffdio_copy.copy returned %w64d)\\[rs]n\",\n" |
| 1416 |
" uffdio_copy.copy);\n" |
| 1417 |
" }\n" |
| 1418 |
"}\n" |
| 1419 |
"\\&\n" |
| 1420 |
"int\n" |
| 1421 |
"main(int argc, char *argv[])\n" |
| 1422 |
"{\n" |
| 1423 |
" int s;\n" |
| 1424 |
" char *addr; /* Start of region handled by userfaultfd */\n" |
| 1425 |
" long uffd; /* userfaultfd file descriptor */\n" |
| 1426 |
" size_t size, i; /* Size of region handled by userfaultfd */\n" |
| 1427 |
" pthread_t thr; /* ID of thread that handles page faults */\n" |
| 1428 |
" struct uffdio_api uffdio_api;\n" |
| 1429 |
" struct uffdio_register uffdio_register;\n" |
| 1430 |
"\\&\n" |
| 1431 |
" if (argc != 2) {\n" |
| 1432 |
" fprintf(stderr, \"Usage: %s num-pages\\[rs]n\", argv[0]);\n" |
| 1433 |
" exit(EXIT_FAILURE);\n" |
| 1434 |
" }\n" |
| 1435 |
"\\&\n" |
| 1436 |
" page_size = sysconf(_SC_PAGE_SIZE);\n" |
| 1437 |
" size = strtoull(argv[1], NULL, 0) * page_size;\n" |
| 1438 |
"\\&\n" |
| 1439 |
" /* Create and enable userfaultfd object. */\n" |
| 1440 |
"\\&\n" |
| 1441 |
" uffd = syscall(SYS_userfaultfd, O_CLOEXEC | O_NONBLOCK);\n" |
| 1442 |
" if (uffd == -1)\n" |
| 1443 |
" err(EXIT_FAILURE, \"userfaultfd\");\n" |
| 1444 |
"\\&\n" |
| 1445 |
" /* NOTE: Two-step feature handshake is not needed here, since this\n" |
| 1446 |
" example doesn't require any specific features.\n" |
| 1447 |
"\\&\n" |
| 1448 |
" Programs that *do* should call UFFDIO_API twice: once with\n" |
| 1449 |
" `features = 0` to detect features supported by this kernel, and\n" |
| 1450 |
" again with the subset of features the program actually wants to\n" |
| 1451 |
" enable. */\n" |
| 1452 |
" uffdio_api.api = UFFD_API;\n" |
| 1453 |
" uffdio_api.features = 0;\n" |
| 1454 |
" if (ioctl(uffd, UFFDIO_API, &uffdio_api) == -1)\n" |
| 1455 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_API\");\n" |
| 1456 |
"\\&\n" |
| 1457 |
" /* Create a private anonymous mapping. The memory will be\n" |
| 1458 |
" demand-zero paged--that is, not yet allocated. When we\n" |
| 1459 |
" actually touch the memory, it will be allocated via\n" |
| 1460 |
" the userfaultfd. */\n" |
| 1461 |
"\\&\n" |
| 1462 |
" addr = mmap(NULL, size, PROT_READ | PROT_WRITE,\n" |
| 1463 |
" MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n" |
| 1464 |
" if (addr == MAP_FAILED)\n" |
| 1465 |
" err(EXIT_FAILURE, \"mmap\");\n" |
| 1466 |
"\\&\n" |
| 1467 |
" printf(\"Address returned by mmap() = %p\\[rs]n\", addr);\n" |
| 1468 |
"\\&\n" |
| 1469 |
" /* Register the memory range of the mapping we just created for\n" |
| 1470 |
" handling by the userfaultfd object. In mode, we request to track\n" |
| 1471 |
" missing pages (i.e., pages that have not yet been faulted in). */\n" |
| 1472 |
"\\&\n" |
| 1473 |
" uffdio_register.range.start = (unsigned long) addr;\n" |
| 1474 |
" uffdio_register.range.len = size;\n" |
| 1475 |
" uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;\n" |
| 1476 |
" if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1)\n" |
| 1477 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_REGISTER\");\n" |
| 1478 |
"\\&\n" |
| 1479 |
" /* Create a thread that will process the userfaultfd events. */\n" |
| 1480 |
"\\&\n" |
| 1481 |
" s = pthread_create(&thr, NULL, fault_handler_thread, (void *) uffd);\n" |
| 1482 |
" if (s != 0) {\n" |
| 1483 |
" errc(EXIT_FAILURE, s, \"pthread_create\");\n" |
| 1484 |
" }\n" |
| 1485 |
"\\&\n" |
| 1486 |
" /* Main thread now touches memory in the mapping, touching\n" |
| 1487 |
" locations 1024 bytes apart. This will trigger userfaultfd\n" |
| 1488 |
" events for all pages in the region. */\n" |
| 1489 |
"\\&\n" |
| 1490 |
" i = 0xf; /* Ensure that faulting address is not on a page\n" |
| 1491 |
" boundary, in order to test that we correctly\n" |
| 1492 |
" handle that case in fault_handling_thread(). */\n" |
| 1493 |
" while (i E<lt> size) {\n" |
| 1494 |
" char c;\n" |
| 1495 |
"\\&\n" |
| 1496 |
" c = addr[i];\n" |
| 1497 |
" printf(\"Read address %p in %s(): \", addr + i, __func__);\n" |
| 1498 |
" printf(\"%c\\[rs]n\", c);\n" |
| 1499 |
" i += 1024;\n" |
| 1500 |
" usleep(100000); /* Slow things down a little */\n" |
| 1501 |
" }\n" |
| 1502 |
"\\&\n" |
| 1503 |
" exit(EXIT_SUCCESS);\n" |
| 1504 |
"}\n" |
| 1505 |
msgstr "" |
| 1506 |
|
| 1507 |
#. SRC END |
| 1508 |
#. type: SH |
| 1509 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1510 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1511 |
#, no-wrap |
| 1512 |
msgid "SEE ALSO" |
| 1513 |
msgstr "" |
| 1514 |
|
| 1515 |
#. type: Plain text |
| 1516 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1517 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1518 |
msgid "" |
| 1519 |
"B<fcntl>(2), B<ioctl>(2), B<ioctl_userfaultfd>(2), B<madvise>(2), B<mmap>(2)" |
| 1520 |
msgstr "" |
| 1521 |
|
| 1522 |
#. type: Plain text |
| 1523 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1524 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1525 |
msgid "" |
| 1526 |
"I<Documentation/admin-guide/mm/userfaultfd.rst> in the Linux kernel source " |
| 1527 |
"tree" |
| 1528 |
msgstr "" |
| 1529 |
|
| 1530 |
#. type: TH |
| 1531 |
#: debian-trixie |
| 1532 |
#, no-wrap |
| 1533 |
msgid "2024-06-15" |
| 1534 |
msgstr "" |
| 1535 |
|
| 1536 |
#. type: TH |
| 1537 |
#: debian-trixie |
| 1538 |
#, no-wrap |
| 1539 |
msgid "Linux man-pages 6.9.1" |
| 1540 |
msgstr "" |
| 1541 |
|
| 1542 |
#. type: Plain text |
| 1543 |
#: debian-trixie |
| 1544 |
msgid "Standard C library (I<libc>, I<-lc>)" |
| 1545 |
msgstr "" |
| 1546 |
|
| 1547 |
#. type: Plain text |
| 1548 |
#: debian-trixie |
| 1549 |
#, no-wrap |
| 1550 |
msgid "" |
| 1551 |
"struct uffd_msg {\n" |
| 1552 |
" __u8 event; /* Type of event */\n" |
| 1553 |
" ...\n" |
| 1554 |
" union {\n" |
| 1555 |
" struct {\n" |
| 1556 |
" __u64 flags; /* Flags describing fault */\n" |
| 1557 |
" __u64 address; /* Faulting address */\n" |
| 1558 |
" union {\n" |
| 1559 |
" __u32 ptid; /* Thread ID of the fault */\n" |
| 1560 |
" } feat;\n" |
| 1561 |
" } pagefault;\n" |
| 1562 |
"\\&\n" |
| 1563 |
" struct { /* Since Linux 4.11 */\n" |
| 1564 |
" __u32 ufd; /* Userfault file descriptor\n" |
| 1565 |
" of the child process */\n" |
| 1566 |
" } fork;\n" |
| 1567 |
"\\&\n" |
| 1568 |
" struct { /* Since Linux 4.11 */\n" |
| 1569 |
" __u64 from; /* Old address of remapped area */\n" |
| 1570 |
" __u64 to; /* New address of remapped area */\n" |
| 1571 |
" __u64 len; /* Original mapping length */\n" |
| 1572 |
" } remap;\n" |
| 1573 |
"\\&\n" |
| 1574 |
" struct { /* Since Linux 4.11 */\n" |
| 1575 |
" __u64 start; /* Start address of removed area */\n" |
| 1576 |
" __u64 end; /* End address of removed area */\n" |
| 1577 |
" } remove;\n" |
| 1578 |
" ...\n" |
| 1579 |
" } arg;\n" |
| 1580 |
"\\&\n" |
| 1581 |
" /* Padding fields omitted */\n" |
| 1582 |
"} __packed;\n" |
| 1583 |
msgstr "" |
| 1584 |
|
| 1585 |
#. type: Plain text |
| 1586 |
#: debian-trixie |
| 1587 |
msgid "" |
| 1588 |
"The original length of the memory range that was remapped using B<mremap>(2)." |
| 1589 |
msgstr "" |
| 1590 |
|
| 1591 |
#. type: Plain text |
| 1592 |
#: debian-trixie fedora-44 fedora-rawhide |
| 1593 |
#, no-wrap |
| 1594 |
msgid "" |
| 1595 |
"$ B<./userfaultfd_demo 3>\n" |
| 1596 |
"Address returned by mmap() = 0x7fd30106c000\n" |
| 1597 |
"\\&\n" |
| 1598 |
"fault_handler_thread():\n" |
| 1599 |
" poll() returns: nready = 1; POLLIN = 1; POLLERR = 0\n" |
| 1600 |
" UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106c00f\n" |
| 1601 |
" (uffdio_copy.copy returned 4096)\n" |
| 1602 |
"Read address 0x7fd30106c00f in main(): A\n" |
| 1603 |
"Read address 0x7fd30106c40f in main(): A\n" |
| 1604 |
"Read address 0x7fd30106c80f in main(): A\n" |
| 1605 |
"Read address 0x7fd30106cc0f in main(): A\n" |
| 1606 |
"\\&\n" |
| 1607 |
"fault_handler_thread():\n" |
| 1608 |
" poll() returns: nready = 1; POLLIN = 1; POLLERR = 0\n" |
| 1609 |
" UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106d00f\n" |
| 1610 |
" (uffdio_copy.copy returned 4096)\n" |
| 1611 |
"Read address 0x7fd30106d00f in main(): B\n" |
| 1612 |
"Read address 0x7fd30106d40f in main(): B\n" |
| 1613 |
"Read address 0x7fd30106d80f in main(): B\n" |
| 1614 |
"Read address 0x7fd30106dc0f in main(): B\n" |
| 1615 |
"\\&\n" |
| 1616 |
"fault_handler_thread():\n" |
| 1617 |
" poll() returns: nready = 1; POLLIN = 1; POLLERR = 0\n" |
| 1618 |
" UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106e00f\n" |
| 1619 |
" (uffdio_copy.copy returned 4096)\n" |
| 1620 |
"Read address 0x7fd30106e00f in main(): C\n" |
| 1621 |
"Read address 0x7fd30106e40f in main(): C\n" |
| 1622 |
"Read address 0x7fd30106e80f in main(): C\n" |
| 1623 |
"Read address 0x7fd30106ec0f in main(): C\n" |
| 1624 |
msgstr "" |
| 1625 |
|
| 1626 |
#. type: Plain text |
| 1627 |
#: debian-trixie |
| 1628 |
#, no-wrap |
| 1629 |
msgid "" |
| 1630 |
"/* userfaultfd_demo.c\n" |
| 1631 |
"\\&\n" |
| 1632 |
" Licensed under the GNU General Public License version 2 or later.\n" |
| 1633 |
"*/\n" |
| 1634 |
"#define _GNU_SOURCE\n" |
| 1635 |
"#include E<lt>err.hE<gt>\n" |
| 1636 |
"#include E<lt>errno.hE<gt>\n" |
| 1637 |
"#include E<lt>fcntl.hE<gt>\n" |
| 1638 |
"#include E<lt>inttypes.hE<gt>\n" |
| 1639 |
"#include E<lt>linux/userfaultfd.hE<gt>\n" |
| 1640 |
"#include E<lt>poll.hE<gt>\n" |
| 1641 |
"#include E<lt>pthread.hE<gt>\n" |
| 1642 |
"#include E<lt>stdio.hE<gt>\n" |
| 1643 |
"#include E<lt>stdlib.hE<gt>\n" |
| 1644 |
"#include E<lt>string.hE<gt>\n" |
| 1645 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 1646 |
"#include E<lt>sys/mman.hE<gt>\n" |
| 1647 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 1648 |
"#include E<lt>unistd.hE<gt>\n" |
| 1649 |
"\\&\n" |
| 1650 |
"static int page_size;\n" |
| 1651 |
"\\&\n" |
| 1652 |
"static void *\n" |
| 1653 |
"fault_handler_thread(void *arg)\n" |
| 1654 |
"{\n" |
| 1655 |
" int nready;\n" |
| 1656 |
" long uffd; /* userfaultfd file descriptor */\n" |
| 1657 |
" ssize_t nread;\n" |
| 1658 |
" struct pollfd pollfd;\n" |
| 1659 |
" struct uffdio_copy uffdio_copy;\n" |
| 1660 |
"\\&\n" |
| 1661 |
" static int fault_cnt = 0; /* Number of faults so far handled */\n" |
| 1662 |
" static char *page = NULL;\n" |
| 1663 |
" static struct uffd_msg msg; /* Data read from userfaultfd */\n" |
| 1664 |
"\\&\n" |
| 1665 |
" uffd = (long) arg;\n" |
| 1666 |
"\\&\n" |
| 1667 |
" /* Create a page that will be copied into the faulting region. */\n" |
| 1668 |
"\\&\n" |
| 1669 |
" if (page == NULL) {\n" |
| 1670 |
" page = mmap(NULL, page_size, PROT_READ | PROT_WRITE,\n" |
| 1671 |
" MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n" |
| 1672 |
" if (page == MAP_FAILED)\n" |
| 1673 |
" err(EXIT_FAILURE, \"mmap\");\n" |
| 1674 |
" }\n" |
| 1675 |
"\\&\n" |
| 1676 |
" /* Loop, handling incoming events on the userfaultfd\n" |
| 1677 |
" file descriptor. */\n" |
| 1678 |
"\\&\n" |
| 1679 |
" for (;;) {\n" |
| 1680 |
"\\&\n" |
| 1681 |
" /* See what poll() tells us about the userfaultfd. */\n" |
| 1682 |
"\\&\n" |
| 1683 |
" pollfd.fd = uffd;\n" |
| 1684 |
" pollfd.events = POLLIN;\n" |
| 1685 |
" nready = poll(&pollfd, 1, -1);\n" |
| 1686 |
" if (nready == -1)\n" |
| 1687 |
" err(EXIT_FAILURE, \"poll\");\n" |
| 1688 |
"\\&\n" |
| 1689 |
" printf(\"\\[rs]nfault_handler_thread():\\[rs]n\");\n" |
| 1690 |
" printf(\" poll() returns: nready = %d; \"\n" |
| 1691 |
" \"POLLIN = %d; POLLERR = %d\\[rs]n\", nready,\n" |
| 1692 |
" (pollfd.revents & POLLIN) != 0,\n" |
| 1693 |
" (pollfd.revents & POLLERR) != 0);\n" |
| 1694 |
"\\&\n" |
| 1695 |
" /* Read an event from the userfaultfd. */\n" |
| 1696 |
"\\&\n" |
| 1697 |
" nread = read(uffd, &msg, sizeof(msg));\n" |
| 1698 |
" if (nread == 0) {\n" |
| 1699 |
" printf(\"EOF on userfaultfd!\\[rs]n\");\n" |
| 1700 |
" exit(EXIT_FAILURE);\n" |
| 1701 |
" }\n" |
| 1702 |
"\\&\n" |
| 1703 |
" if (nread == -1)\n" |
| 1704 |
" err(EXIT_FAILURE, \"read\");\n" |
| 1705 |
"\\&\n" |
| 1706 |
" /* We expect only one kind of event; verify that assumption. */\n" |
| 1707 |
"\\&\n" |
| 1708 |
" if (msg.event != UFFD_EVENT_PAGEFAULT) {\n" |
| 1709 |
" fprintf(stderr, \"Unexpected event on userfaultfd\\[rs]n\");\n" |
| 1710 |
" exit(EXIT_FAILURE);\n" |
| 1711 |
" }\n" |
| 1712 |
"\\&\n" |
| 1713 |
" /* Display info about the page-fault event. */\n" |
| 1714 |
"\\&\n" |
| 1715 |
" printf(\" UFFD_EVENT_PAGEFAULT event: \");\n" |
| 1716 |
" printf(\"flags = %\"PRIx64\"; \", msg.arg.pagefault.flags);\n" |
| 1717 |
" printf(\"address = %\"PRIx64\"\\[rs]n\", msg.arg.pagefault.address);\n" |
| 1718 |
"\\&\n" |
| 1719 |
" /* Copy the page pointed to by \\[aq]page\\[aq] into the faulting\n" |
| 1720 |
" region. Vary the contents that are copied in, so that it\n" |
| 1721 |
" is more obvious that each fault is handled separately. */\n" |
| 1722 |
"\\&\n" |
| 1723 |
" memset(page, \\[aq]A\\[aq] + fault_cnt % 20, page_size);\n" |
| 1724 |
" fault_cnt++;\n" |
| 1725 |
"\\&\n" |
| 1726 |
" uffdio_copy.src = (unsigned long) page;\n" |
| 1727 |
"\\&\n" |
| 1728 |
" /* We need to handle page faults in units of pages(!).\n" |
| 1729 |
" So, round faulting address down to page boundary. */\n" |
| 1730 |
"\\&\n" |
| 1731 |
" uffdio_copy.dst = (unsigned long) msg.arg.pagefault.address &\n" |
| 1732 |
" \\[ti](page_size - 1);\n" |
| 1733 |
" uffdio_copy.len = page_size;\n" |
| 1734 |
" uffdio_copy.mode = 0;\n" |
| 1735 |
" uffdio_copy.copy = 0;\n" |
| 1736 |
" if (ioctl(uffd, UFFDIO_COPY, &uffdio_copy) == -1)\n" |
| 1737 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_COPY\");\n" |
| 1738 |
"\\&\n" |
| 1739 |
" printf(\" (uffdio_copy.copy returned %\"PRId64\")\\[rs]n\",\n" |
| 1740 |
" uffdio_copy.copy);\n" |
| 1741 |
" }\n" |
| 1742 |
"}\n" |
| 1743 |
"\\&\n" |
| 1744 |
"int\n" |
| 1745 |
"main(int argc, char *argv[])\n" |
| 1746 |
"{\n" |
| 1747 |
" int s;\n" |
| 1748 |
" char c;\n" |
| 1749 |
" char *addr; /* Start of region handled by userfaultfd */\n" |
| 1750 |
" long uffd; /* userfaultfd file descriptor */\n" |
| 1751 |
" size_t len, l; /* Length of region handled by userfaultfd */\n" |
| 1752 |
" pthread_t thr; /* ID of thread that handles page faults */\n" |
| 1753 |
" struct uffdio_api uffdio_api;\n" |
| 1754 |
" struct uffdio_register uffdio_register;\n" |
| 1755 |
"\\&\n" |
| 1756 |
" if (argc != 2) {\n" |
| 1757 |
" fprintf(stderr, \"Usage: %s num-pages\\[rs]n\", argv[0]);\n" |
| 1758 |
" exit(EXIT_FAILURE);\n" |
| 1759 |
" }\n" |
| 1760 |
"\\&\n" |
| 1761 |
" page_size = sysconf(_SC_PAGE_SIZE);\n" |
| 1762 |
" len = strtoull(argv[1], NULL, 0) * page_size;\n" |
| 1763 |
"\\&\n" |
| 1764 |
" /* Create and enable userfaultfd object. */\n" |
| 1765 |
"\\&\n" |
| 1766 |
" uffd = syscall(SYS_userfaultfd, O_CLOEXEC | O_NONBLOCK);\n" |
| 1767 |
" if (uffd == -1)\n" |
| 1768 |
" err(EXIT_FAILURE, \"userfaultfd\");\n" |
| 1769 |
"\\&\n" |
| 1770 |
" /* NOTE: Two-step feature handshake is not needed here, since this\n" |
| 1771 |
" example doesn't require any specific features.\n" |
| 1772 |
"\\&\n" |
| 1773 |
" Programs that *do* should call UFFDIO_API twice: once with\n" |
| 1774 |
" `features = 0` to detect features supported by this kernel, and\n" |
| 1775 |
" again with the subset of features the program actually wants to\n" |
| 1776 |
" enable. */\n" |
| 1777 |
" uffdio_api.api = UFFD_API;\n" |
| 1778 |
" uffdio_api.features = 0;\n" |
| 1779 |
" if (ioctl(uffd, UFFDIO_API, &uffdio_api) == -1)\n" |
| 1780 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_API\");\n" |
| 1781 |
"\\&\n" |
| 1782 |
" /* Create a private anonymous mapping. The memory will be\n" |
| 1783 |
" demand-zero paged--that is, not yet allocated. When we\n" |
| 1784 |
" actually touch the memory, it will be allocated via\n" |
| 1785 |
" the userfaultfd. */\n" |
| 1786 |
"\\&\n" |
| 1787 |
" addr = mmap(NULL, len, PROT_READ | PROT_WRITE,\n" |
| 1788 |
" MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n" |
| 1789 |
" if (addr == MAP_FAILED)\n" |
| 1790 |
" err(EXIT_FAILURE, \"mmap\");\n" |
| 1791 |
"\\&\n" |
| 1792 |
" printf(\"Address returned by mmap() = %p\\[rs]n\", addr);\n" |
| 1793 |
"\\&\n" |
| 1794 |
" /* Register the memory range of the mapping we just created for\n" |
| 1795 |
" handling by the userfaultfd object. In mode, we request to track\n" |
| 1796 |
" missing pages (i.e., pages that have not yet been faulted in). */\n" |
| 1797 |
"\\&\n" |
| 1798 |
" uffdio_register.range.start = (unsigned long) addr;\n" |
| 1799 |
" uffdio_register.range.len = len;\n" |
| 1800 |
" uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;\n" |
| 1801 |
" if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1)\n" |
| 1802 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_REGISTER\");\n" |
| 1803 |
"\\&\n" |
| 1804 |
" /* Create a thread that will process the userfaultfd events. */\n" |
| 1805 |
"\\&\n" |
| 1806 |
" s = pthread_create(&thr, NULL, fault_handler_thread, (void *) uffd);\n" |
| 1807 |
" if (s != 0) {\n" |
| 1808 |
" errc(EXIT_FAILURE, s, \"pthread_create\");\n" |
| 1809 |
" }\n" |
| 1810 |
"\\&\n" |
| 1811 |
" /* Main thread now touches memory in the mapping, touching\n" |
| 1812 |
" locations 1024 bytes apart. This will trigger userfaultfd\n" |
| 1813 |
" events for all pages in the region. */\n" |
| 1814 |
"\\&\n" |
| 1815 |
" l = 0xf; /* Ensure that faulting address is not on a page\n" |
| 1816 |
" boundary, in order to test that we correctly\n" |
| 1817 |
" handle that case in fault_handling_thread(). */\n" |
| 1818 |
" while (l E<lt> len) {\n" |
| 1819 |
" c = addr[l];\n" |
| 1820 |
" printf(\"Read address %p in %s(): \", addr + l, __func__);\n" |
| 1821 |
" printf(\"%c\\[rs]n\", c);\n" |
| 1822 |
" l += 1024;\n" |
| 1823 |
" usleep(100000); /* Slow things down a little */\n" |
| 1824 |
" }\n" |
| 1825 |
"\\&\n" |
| 1826 |
" exit(EXIT_SUCCESS);\n" |
| 1827 |
"}\n" |
| 1828 |
msgstr "" |
| 1829 |
|
| 1830 |
#. type: TH |
| 1831 |
#: fedora-44 fedora-rawhide |
| 1832 |
#, no-wrap |
| 1833 |
msgid "2024-11-17" |
| 1834 |
msgstr "" |
| 1835 |
|
| 1836 |
#. type: TH |
| 1837 |
#: fedora-44 fedora-rawhide |
| 1838 |
#, no-wrap |
| 1839 |
msgid "Linux man-pages 6.13" |
| 1840 |
msgstr "" |
| 1841 |
|
| 1842 |
#. type: Plain text |
| 1843 |
#: fedora-44 fedora-rawhide |
| 1844 |
#, no-wrap |
| 1845 |
msgid "" |
| 1846 |
"/* userfaultfd_demo.c\n" |
| 1847 |
"\\&\n" |
| 1848 |
" Licensed under the GNU General Public License version 2 or later.\n" |
| 1849 |
"*/\n" |
| 1850 |
"#define _GNU_SOURCE\n" |
| 1851 |
"#include E<lt>err.hE<gt>\n" |
| 1852 |
"#include E<lt>errno.hE<gt>\n" |
| 1853 |
"#include E<lt>fcntl.hE<gt>\n" |
| 1854 |
"#include E<lt>inttypes.hE<gt>\n" |
| 1855 |
"#include E<lt>linux/userfaultfd.hE<gt>\n" |
| 1856 |
"#include E<lt>poll.hE<gt>\n" |
| 1857 |
"#include E<lt>pthread.hE<gt>\n" |
| 1858 |
"#include E<lt>stdio.hE<gt>\n" |
| 1859 |
"#include E<lt>stdlib.hE<gt>\n" |
| 1860 |
"#include E<lt>string.hE<gt>\n" |
| 1861 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 1862 |
"#include E<lt>sys/mman.hE<gt>\n" |
| 1863 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 1864 |
"#include E<lt>unistd.hE<gt>\n" |
| 1865 |
"\\&\n" |
| 1866 |
"static int page_size;\n" |
| 1867 |
"\\&\n" |
| 1868 |
"static void *\n" |
| 1869 |
"fault_handler_thread(void *arg)\n" |
| 1870 |
"{\n" |
| 1871 |
" int nready;\n" |
| 1872 |
" long uffd; /* userfaultfd file descriptor */\n" |
| 1873 |
" ssize_t nread;\n" |
| 1874 |
" struct pollfd pollfd;\n" |
| 1875 |
" struct uffdio_copy uffdio_copy;\n" |
| 1876 |
"\\&\n" |
| 1877 |
" static int fault_cnt = 0; /* Number of faults so far handled */\n" |
| 1878 |
" static char *page = NULL;\n" |
| 1879 |
" static struct uffd_msg msg; /* Data read from userfaultfd */\n" |
| 1880 |
"\\&\n" |
| 1881 |
" uffd = (long) arg;\n" |
| 1882 |
"\\&\n" |
| 1883 |
" /* Create a page that will be copied into the faulting region. */\n" |
| 1884 |
"\\&\n" |
| 1885 |
" if (page == NULL) {\n" |
| 1886 |
" page = mmap(NULL, page_size, PROT_READ | PROT_WRITE,\n" |
| 1887 |
" MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n" |
| 1888 |
" if (page == MAP_FAILED)\n" |
| 1889 |
" err(EXIT_FAILURE, \"mmap\");\n" |
| 1890 |
" }\n" |
| 1891 |
"\\&\n" |
| 1892 |
" /* Loop, handling incoming events on the userfaultfd\n" |
| 1893 |
" file descriptor. */\n" |
| 1894 |
"\\&\n" |
| 1895 |
" for (;;) {\n" |
| 1896 |
"\\&\n" |
| 1897 |
" /* See what poll() tells us about the userfaultfd. */\n" |
| 1898 |
"\\&\n" |
| 1899 |
" pollfd.fd = uffd;\n" |
| 1900 |
" pollfd.events = POLLIN;\n" |
| 1901 |
" nready = poll(&pollfd, 1, -1);\n" |
| 1902 |
" if (nready == -1)\n" |
| 1903 |
" err(EXIT_FAILURE, \"poll\");\n" |
| 1904 |
"\\&\n" |
| 1905 |
" printf(\"\\[rs]nfault_handler_thread():\\[rs]n\");\n" |
| 1906 |
" printf(\" poll() returns: nready = %d; \"\n" |
| 1907 |
" \"POLLIN = %d; POLLERR = %d\\[rs]n\", nready,\n" |
| 1908 |
" (pollfd.revents & POLLIN) != 0,\n" |
| 1909 |
" (pollfd.revents & POLLERR) != 0);\n" |
| 1910 |
"\\&\n" |
| 1911 |
" /* Read an event from the userfaultfd. */\n" |
| 1912 |
"\\&\n" |
| 1913 |
" nread = read(uffd, &msg, sizeof(msg));\n" |
| 1914 |
" if (nread == 0) {\n" |
| 1915 |
" printf(\"EOF on userfaultfd!\\[rs]n\");\n" |
| 1916 |
" exit(EXIT_FAILURE);\n" |
| 1917 |
" }\n" |
| 1918 |
"\\&\n" |
| 1919 |
" if (nread == -1)\n" |
| 1920 |
" err(EXIT_FAILURE, \"read\");\n" |
| 1921 |
"\\&\n" |
| 1922 |
" /* We expect only one kind of event; verify that assumption. */\n" |
| 1923 |
"\\&\n" |
| 1924 |
" if (msg.event != UFFD_EVENT_PAGEFAULT) {\n" |
| 1925 |
" fprintf(stderr, \"Unexpected event on userfaultfd\\[rs]n\");\n" |
| 1926 |
" exit(EXIT_FAILURE);\n" |
| 1927 |
" }\n" |
| 1928 |
"\\&\n" |
| 1929 |
" /* Display info about the page-fault event. */\n" |
| 1930 |
"\\&\n" |
| 1931 |
" printf(\" UFFD_EVENT_PAGEFAULT event: \");\n" |
| 1932 |
" printf(\"flags = %\"PRIx64\"; \", msg.arg.pagefault.flags);\n" |
| 1933 |
" printf(\"address = %\"PRIx64\"\\[rs]n\", msg.arg.pagefault.address);\n" |
| 1934 |
"\\&\n" |
| 1935 |
" /* Copy the page pointed to by \\[aq]page\\[aq] into the faulting\n" |
| 1936 |
" region. Vary the contents that are copied in, so that it\n" |
| 1937 |
" is more obvious that each fault is handled separately. */\n" |
| 1938 |
"\\&\n" |
| 1939 |
" memset(page, \\[aq]A\\[aq] + fault_cnt % 20, page_size);\n" |
| 1940 |
" fault_cnt++;\n" |
| 1941 |
"\\&\n" |
| 1942 |
" uffdio_copy.src = (unsigned long) page;\n" |
| 1943 |
"\\&\n" |
| 1944 |
" /* We need to handle page faults in units of pages(!).\n" |
| 1945 |
" So, round faulting address down to page boundary. */\n" |
| 1946 |
"\\&\n" |
| 1947 |
" uffdio_copy.dst = (unsigned long) msg.arg.pagefault.address &\n" |
| 1948 |
" \\[ti](page_size - 1);\n" |
| 1949 |
" uffdio_copy.len = page_size;\n" |
| 1950 |
" uffdio_copy.mode = 0;\n" |
| 1951 |
" uffdio_copy.copy = 0;\n" |
| 1952 |
" if (ioctl(uffd, UFFDIO_COPY, &uffdio_copy) == -1)\n" |
| 1953 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_COPY\");\n" |
| 1954 |
"\\&\n" |
| 1955 |
" printf(\" (uffdio_copy.copy returned %\"PRId64\")\\[rs]n\",\n" |
| 1956 |
" uffdio_copy.copy);\n" |
| 1957 |
" }\n" |
| 1958 |
"}\n" |
| 1959 |
"\\&\n" |
| 1960 |
"int\n" |
| 1961 |
"main(int argc, char *argv[])\n" |
| 1962 |
"{\n" |
| 1963 |
" int s;\n" |
| 1964 |
" char c;\n" |
| 1965 |
" char *addr; /* Start of region handled by userfaultfd */\n" |
| 1966 |
" long uffd; /* userfaultfd file descriptor */\n" |
| 1967 |
" size_t size, i; /* Size of region handled by userfaultfd */\n" |
| 1968 |
" pthread_t thr; /* ID of thread that handles page faults */\n" |
| 1969 |
" struct uffdio_api uffdio_api;\n" |
| 1970 |
" struct uffdio_register uffdio_register;\n" |
| 1971 |
"\\&\n" |
| 1972 |
" if (argc != 2) {\n" |
| 1973 |
" fprintf(stderr, \"Usage: %s num-pages\\[rs]n\", argv[0]);\n" |
| 1974 |
" exit(EXIT_FAILURE);\n" |
| 1975 |
" }\n" |
| 1976 |
"\\&\n" |
| 1977 |
" page_size = sysconf(_SC_PAGE_SIZE);\n" |
| 1978 |
" size = strtoull(argv[1], NULL, 0) * page_size;\n" |
| 1979 |
"\\&\n" |
| 1980 |
" /* Create and enable userfaultfd object. */\n" |
| 1981 |
"\\&\n" |
| 1982 |
" uffd = syscall(SYS_userfaultfd, O_CLOEXEC | O_NONBLOCK);\n" |
| 1983 |
" if (uffd == -1)\n" |
| 1984 |
" err(EXIT_FAILURE, \"userfaultfd\");\n" |
| 1985 |
"\\&\n" |
| 1986 |
" /* NOTE: Two-step feature handshake is not needed here, since this\n" |
| 1987 |
" example doesn't require any specific features.\n" |
| 1988 |
"\\&\n" |
| 1989 |
" Programs that *do* should call UFFDIO_API twice: once with\n" |
| 1990 |
" `features = 0` to detect features supported by this kernel, and\n" |
| 1991 |
" again with the subset of features the program actually wants to\n" |
| 1992 |
" enable. */\n" |
| 1993 |
" uffdio_api.api = UFFD_API;\n" |
| 1994 |
" uffdio_api.features = 0;\n" |
| 1995 |
" if (ioctl(uffd, UFFDIO_API, &uffdio_api) == -1)\n" |
| 1996 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_API\");\n" |
| 1997 |
"\\&\n" |
| 1998 |
" /* Create a private anonymous mapping. The memory will be\n" |
| 1999 |
" demand-zero paged--that is, not yet allocated. When we\n" |
| 2000 |
" actually touch the memory, it will be allocated via\n" |
| 2001 |
" the userfaultfd. */\n" |
| 2002 |
"\\&\n" |
| 2003 |
" addr = mmap(NULL, size, PROT_READ | PROT_WRITE,\n" |
| 2004 |
" MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n" |
| 2005 |
" if (addr == MAP_FAILED)\n" |
| 2006 |
" err(EXIT_FAILURE, \"mmap\");\n" |
| 2007 |
"\\&\n" |
| 2008 |
" printf(\"Address returned by mmap() = %p\\[rs]n\", addr);\n" |
| 2009 |
"\\&\n" |
| 2010 |
" /* Register the memory range of the mapping we just created for\n" |
| 2011 |
" handling by the userfaultfd object. In mode, we request to track\n" |
| 2012 |
" missing pages (i.e., pages that have not yet been faulted in). */\n" |
| 2013 |
"\\&\n" |
| 2014 |
" uffdio_register.range.start = (unsigned long) addr;\n" |
| 2015 |
" uffdio_register.range.len = size;\n" |
| 2016 |
" uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;\n" |
| 2017 |
" if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1)\n" |
| 2018 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_REGISTER\");\n" |
| 2019 |
"\\&\n" |
| 2020 |
" /* Create a thread that will process the userfaultfd events. */\n" |
| 2021 |
"\\&\n" |
| 2022 |
" s = pthread_create(&thr, NULL, fault_handler_thread, (void *) uffd);\n" |
| 2023 |
" if (s != 0) {\n" |
| 2024 |
" errc(EXIT_FAILURE, s, \"pthread_create\");\n" |
| 2025 |
" }\n" |
| 2026 |
"\\&\n" |
| 2027 |
" /* Main thread now touches memory in the mapping, touching\n" |
| 2028 |
" locations 1024 bytes apart. This will trigger userfaultfd\n" |
| 2029 |
" events for all pages in the region. */\n" |
| 2030 |
"\\&\n" |
| 2031 |
" i = 0xf; /* Ensure that faulting address is not on a page\n" |
| 2032 |
" boundary, in order to test that we correctly\n" |
| 2033 |
" handle that case in fault_handling_thread(). */\n" |
| 2034 |
" while (i E<lt> size) {\n" |
| 2035 |
" c = addr[i];\n" |
| 2036 |
" printf(\"Read address %p in %s(): \", addr + i, __func__);\n" |
| 2037 |
" printf(\"%c\\[rs]n\", c);\n" |
| 2038 |
" i += 1024;\n" |
| 2039 |
" usleep(100000); /* Slow things down a little */\n" |
| 2040 |
" }\n" |
| 2041 |
"\\&\n" |
| 2042 |
" exit(EXIT_SUCCESS);\n" |
| 2043 |
"}\n" |
| 2044 |
msgstr "" |
| 2045 |
|
| 2046 |
#. type: TH |
| 2047 |
#: mageia-cauldron |
| 2048 |
#, no-wrap |
| 2049 |
msgid "2026-02-08" |
| 2050 |
msgstr "" |
| 2051 |
|
| 2052 |
#. type: TH |
| 2053 |
#: mageia-cauldron |
| 2054 |
#, no-wrap |
| 2055 |
msgid "Linux man-pages 6.17" |
| 2056 |
msgstr "" |
| 2057 |
|
| 2058 |
#. type: Plain text |
| 2059 |
#: mageia-cauldron |
| 2060 |
#, no-wrap |
| 2061 |
msgid "" |
| 2062 |
"/* userfaultfd_demo.c\n" |
| 2063 |
"\\&\n" |
| 2064 |
" Licensed under the GNU General Public License version 2 or later.\n" |
| 2065 |
"*/\n" |
| 2066 |
"#define _GNU_SOURCE\n" |
| 2067 |
"#include E<lt>err.hE<gt>\n" |
| 2068 |
"#include E<lt>errno.hE<gt>\n" |
| 2069 |
"#include E<lt>fcntl.hE<gt>\n" |
| 2070 |
"#include E<lt>inttypes.hE<gt>\n" |
| 2071 |
"#include E<lt>linux/userfaultfd.hE<gt>\n" |
| 2072 |
"#include E<lt>poll.hE<gt>\n" |
| 2073 |
"#include E<lt>pthread.hE<gt>\n" |
| 2074 |
"#include E<lt>stdio.hE<gt>\n" |
| 2075 |
"#include E<lt>stdlib.hE<gt>\n" |
| 2076 |
"#include E<lt>string.hE<gt>\n" |
| 2077 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 2078 |
"#include E<lt>sys/mman.hE<gt>\n" |
| 2079 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 2080 |
"#include E<lt>unistd.hE<gt>\n" |
| 2081 |
"\\&\n" |
| 2082 |
"static int page_size;\n" |
| 2083 |
"\\&\n" |
| 2084 |
"static void *\n" |
| 2085 |
"fault_handler_thread(void *arg)\n" |
| 2086 |
"{\n" |
| 2087 |
" long uffd; /* userfaultfd file descriptor */\n" |
| 2088 |
"\\&\n" |
| 2089 |
" static int fault_cnt = 0; /* Number of faults so far handled */\n" |
| 2090 |
" static char *page = NULL;\n" |
| 2091 |
" static struct uffd_msg msg; /* Data read from userfaultfd */\n" |
| 2092 |
"\\&\n" |
| 2093 |
" uffd = (long) arg;\n" |
| 2094 |
"\\&\n" |
| 2095 |
" /* Create a page that will be copied into the faulting region. */\n" |
| 2096 |
"\\&\n" |
| 2097 |
" if (page == NULL) {\n" |
| 2098 |
" page = mmap(NULL, page_size, PROT_READ | PROT_WRITE,\n" |
| 2099 |
" MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n" |
| 2100 |
" if (page == MAP_FAILED)\n" |
| 2101 |
" err(EXIT_FAILURE, \"mmap\");\n" |
| 2102 |
" }\n" |
| 2103 |
"\\&\n" |
| 2104 |
" /* Loop, handling incoming events on the userfaultfd\n" |
| 2105 |
" file descriptor. */\n" |
| 2106 |
"\\&\n" |
| 2107 |
" for (;;) {\n" |
| 2108 |
" int nready;\n" |
| 2109 |
" ssize_t nread;\n" |
| 2110 |
" struct pollfd pollfd;\n" |
| 2111 |
" struct uffdio_copy uffdio_copy;\n" |
| 2112 |
"\\&\n" |
| 2113 |
" /* See what poll() tells us about the userfaultfd. */\n" |
| 2114 |
"\\&\n" |
| 2115 |
" pollfd.fd = uffd;\n" |
| 2116 |
" pollfd.events = POLLIN;\n" |
| 2117 |
" nready = poll(&pollfd, 1, -1);\n" |
| 2118 |
" if (nready == -1)\n" |
| 2119 |
" err(EXIT_FAILURE, \"poll\");\n" |
| 2120 |
"\\&\n" |
| 2121 |
" printf(\"\\[rs]nfault_handler_thread():\\[rs]n\");\n" |
| 2122 |
" printf(\" poll() returns: nready = %d; \"\n" |
| 2123 |
" \"POLLIN = %d; POLLERR = %d\\[rs]n\", nready,\n" |
| 2124 |
" (pollfd.revents & POLLIN) != 0,\n" |
| 2125 |
" (pollfd.revents & POLLERR) != 0);\n" |
| 2126 |
"\\&\n" |
| 2127 |
" /* Read an event from the userfaultfd. */\n" |
| 2128 |
"\\&\n" |
| 2129 |
" nread = read(uffd, &msg, sizeof(msg));\n" |
| 2130 |
" if (nread == 0) {\n" |
| 2131 |
" printf(\"EOF on userfaultfd!\\[rs]n\");\n" |
| 2132 |
" exit(EXIT_FAILURE);\n" |
| 2133 |
" }\n" |
| 2134 |
"\\&\n" |
| 2135 |
" if (nread == -1)\n" |
| 2136 |
" err(EXIT_FAILURE, \"read\");\n" |
| 2137 |
"\\&\n" |
| 2138 |
" /* We expect only one kind of event; verify that assumption. */\n" |
| 2139 |
"\\&\n" |
| 2140 |
" if (msg.event != UFFD_EVENT_PAGEFAULT) {\n" |
| 2141 |
" fprintf(stderr, \"Unexpected event on userfaultfd\\[rs]n\");\n" |
| 2142 |
" exit(EXIT_FAILURE);\n" |
| 2143 |
" }\n" |
| 2144 |
"\\&\n" |
| 2145 |
" /* Display info about the page-fault event. */\n" |
| 2146 |
"\\&\n" |
| 2147 |
" printf(\" UFFD_EVENT_PAGEFAULT event: \");\n" |
| 2148 |
" printf(\"flags = %\"PRIx64\"; \", msg.arg.pagefault.flags);\n" |
| 2149 |
" printf(\"address = %\"PRIx64\"\\[rs]n\", msg.arg.pagefault.address);\n" |
| 2150 |
"\\&\n" |
| 2151 |
" /* Copy the page pointed to by \\[aq]page\\[aq] into the faulting\n" |
| 2152 |
" region. Vary the contents that are copied in, so that it\n" |
| 2153 |
" is more obvious that each fault is handled separately. */\n" |
| 2154 |
"\\&\n" |
| 2155 |
" memset(page, \\[aq]A\\[aq] + fault_cnt % 20, page_size);\n" |
| 2156 |
" fault_cnt++;\n" |
| 2157 |
"\\&\n" |
| 2158 |
" uffdio_copy.src = (unsigned long) page;\n" |
| 2159 |
"\\&\n" |
| 2160 |
" /* We need to handle page faults in units of pages(!).\n" |
| 2161 |
" So, round faulting address down to page boundary. */\n" |
| 2162 |
"\\&\n" |
| 2163 |
" uffdio_copy.dst = (unsigned long) msg.arg.pagefault.address &\n" |
| 2164 |
" \\[ti](page_size - 1);\n" |
| 2165 |
" uffdio_copy.len = page_size;\n" |
| 2166 |
" uffdio_copy.mode = 0;\n" |
| 2167 |
" uffdio_copy.copy = 0;\n" |
| 2168 |
" if (ioctl(uffd, UFFDIO_COPY, &uffdio_copy) == -1)\n" |
| 2169 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_COPY\");\n" |
| 2170 |
"\\&\n" |
| 2171 |
" printf(\" (uffdio_copy.copy returned %\"PRId64\")\\[rs]n\",\n" |
| 2172 |
" uffdio_copy.copy);\n" |
| 2173 |
" }\n" |
| 2174 |
"}\n" |
| 2175 |
"\\&\n" |
| 2176 |
"int\n" |
| 2177 |
"main(int argc, char *argv[])\n" |
| 2178 |
"{\n" |
| 2179 |
" int s;\n" |
| 2180 |
" char *addr; /* Start of region handled by userfaultfd */\n" |
| 2181 |
" long uffd; /* userfaultfd file descriptor */\n" |
| 2182 |
" size_t size, i; /* Size of region handled by userfaultfd */\n" |
| 2183 |
" pthread_t thr; /* ID of thread that handles page faults */\n" |
| 2184 |
" struct uffdio_api uffdio_api;\n" |
| 2185 |
" struct uffdio_register uffdio_register;\n" |
| 2186 |
"\\&\n" |
| 2187 |
" if (argc != 2) {\n" |
| 2188 |
" fprintf(stderr, \"Usage: %s num-pages\\[rs]n\", argv[0]);\n" |
| 2189 |
" exit(EXIT_FAILURE);\n" |
| 2190 |
" }\n" |
| 2191 |
"\\&\n" |
| 2192 |
" page_size = sysconf(_SC_PAGE_SIZE);\n" |
| 2193 |
" size = strtoull(argv[1], NULL, 0) * page_size;\n" |
| 2194 |
"\\&\n" |
| 2195 |
" /* Create and enable userfaultfd object. */\n" |
| 2196 |
"\\&\n" |
| 2197 |
" uffd = syscall(SYS_userfaultfd, O_CLOEXEC | O_NONBLOCK);\n" |
| 2198 |
" if (uffd == -1)\n" |
| 2199 |
" err(EXIT_FAILURE, \"userfaultfd\");\n" |
| 2200 |
"\\&\n" |
| 2201 |
" /* NOTE: Two-step feature handshake is not needed here, since this\n" |
| 2202 |
" example doesn't require any specific features.\n" |
| 2203 |
"\\&\n" |
| 2204 |
" Programs that *do* should call UFFDIO_API twice: once with\n" |
| 2205 |
" `features = 0` to detect features supported by this kernel, and\n" |
| 2206 |
" again with the subset of features the program actually wants to\n" |
| 2207 |
" enable. */\n" |
| 2208 |
" uffdio_api.api = UFFD_API;\n" |
| 2209 |
" uffdio_api.features = 0;\n" |
| 2210 |
" if (ioctl(uffd, UFFDIO_API, &uffdio_api) == -1)\n" |
| 2211 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_API\");\n" |
| 2212 |
"\\&\n" |
| 2213 |
" /* Create a private anonymous mapping. The memory will be\n" |
| 2214 |
" demand-zero paged--that is, not yet allocated. When we\n" |
| 2215 |
" actually touch the memory, it will be allocated via\n" |
| 2216 |
" the userfaultfd. */\n" |
| 2217 |
"\\&\n" |
| 2218 |
" addr = mmap(NULL, size, PROT_READ | PROT_WRITE,\n" |
| 2219 |
" MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n" |
| 2220 |
" if (addr == MAP_FAILED)\n" |
| 2221 |
" err(EXIT_FAILURE, \"mmap\");\n" |
| 2222 |
"\\&\n" |
| 2223 |
" printf(\"Address returned by mmap() = %p\\[rs]n\", addr);\n" |
| 2224 |
"\\&\n" |
| 2225 |
" /* Register the memory range of the mapping we just created for\n" |
| 2226 |
" handling by the userfaultfd object. In mode, we request to track\n" |
| 2227 |
" missing pages (i.e., pages that have not yet been faulted in). */\n" |
| 2228 |
"\\&\n" |
| 2229 |
" uffdio_register.range.start = (unsigned long) addr;\n" |
| 2230 |
" uffdio_register.range.len = size;\n" |
| 2231 |
" uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;\n" |
| 2232 |
" if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1)\n" |
| 2233 |
" err(EXIT_FAILURE, \"ioctl-UFFDIO_REGISTER\");\n" |
| 2234 |
"\\&\n" |
| 2235 |
" /* Create a thread that will process the userfaultfd events. */\n" |
| 2236 |
"\\&\n" |
| 2237 |
" s = pthread_create(&thr, NULL, fault_handler_thread, (void *) uffd);\n" |
| 2238 |
" if (s != 0) {\n" |
| 2239 |
" errc(EXIT_FAILURE, s, \"pthread_create\");\n" |
| 2240 |
" }\n" |
| 2241 |
"\\&\n" |
| 2242 |
" /* Main thread now touches memory in the mapping, touching\n" |
| 2243 |
" locations 1024 bytes apart. This will trigger userfaultfd\n" |
| 2244 |
" events for all pages in the region. */\n" |
| 2245 |
"\\&\n" |
| 2246 |
" i = 0xf; /* Ensure that faulting address is not on a page\n" |
| 2247 |
" boundary, in order to test that we correctly\n" |
| 2248 |
" handle that case in fault_handling_thread(). */\n" |
| 2249 |
" while (i E<lt> size) {\n" |
| 2250 |
" char c;\n" |
| 2251 |
"\\&\n" |
| 2252 |
" c = addr[i];\n" |
| 2253 |
" printf(\"Read address %p in %s(): \", addr + i, __func__);\n" |
| 2254 |
" printf(\"%c\\[rs]n\", c);\n" |
| 2255 |
" i += 1024;\n" |
| 2256 |
" usleep(100000); /* Slow things down a little */\n" |
| 2257 |
" }\n" |
| 2258 |
"\\&\n" |
| 2259 |
" exit(EXIT_SUCCESS);\n" |
| 2260 |
"}\n" |
| 2261 |
msgstr "" |
| 2262 |
|
| 2263 |
#. type: TH |
| 2264 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2265 |
#, no-wrap |
| 2266 |
msgid "Linux man-pages (unreleased)" |
| 2267 |
msgstr "" |