]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/madvise.2
madvise.2: tfix
[thirdparty/man-pages.git] / man2 / madvise.2
1 .\" Copyright (C) 2001 David Gómez <davidge@jazzfree.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Based on comments from mm/filemap.c. Last modified on 10-06-2001
26 .\" Modified, 25 Feb 2002, Michael Kerrisk, <mtk.manpages@gmail.com>
27 .\" Added notes on MADV_DONTNEED
28 .\" 2010-06-19, mtk, Added documentation of MADV_MERGEABLE and
29 .\" MADV_UNMERGEABLE
30 .\" 2010-06-15, Andi Kleen, Add documentation of MADV_HWPOISON.
31 .\" 2010-06-19, Andi Kleen, Add documentation of MADV_SOFT_OFFLINE.
32 .\" 2011-09-18, Doug Goldstein <cardoe@cardoe.com>
33 .\" Document MADV_HUGEPAGE and MADV_NOHUGEPAGE
34 .\"
35 .TH MADVISE 2 2021-03-22 "Linux" "Linux Programmer's Manual"
36 .SH NAME
37 madvise \- give advice about use of memory
38 .SH SYNOPSIS
39 .nf
40 .B #include <sys/mman.h>
41 .PP
42 .BI "int madvise(void *" addr ", size_t " length ", int " advice );
43 .fi
44 .PP
45 .RS -4
46 Feature Test Macro Requirements for glibc (see
47 .BR feature_test_macros (7)):
48 .RE
49 .PP
50 .BR madvise ():
51 .nf
52 Since glibc 2.19:
53 _DEFAULT_SOURCE
54 Up to and including glibc 2.19:
55 _BSD_SOURCE
56 .fi
57 .SH DESCRIPTION
58 The
59 .BR madvise ()
60 system call is used to give advice or directions to the kernel
61 about the address range beginning at address
62 .I addr
63 and with size
64 .I length
65 bytes.
66 In most cases,
67 the goal of such advice is to improve system or application performance.
68 .PP
69 Initially, the system call supported a set of "conventional"
70 .I advice
71 values, which are also available on several other implementations.
72 (Note, though, that
73 .BR madvise ()
74 is not specified in POSIX.)
75 Subsequently, a number of Linux-specific
76 .IR advice
77 values have been added.
78 .\"
79 .\" ======================================================================
80 .\"
81 .SS Conventional advice values
82 The
83 .I advice
84 values listed below
85 allow an application to tell the kernel how it expects to use
86 some mapped or shared memory areas, so that the kernel can choose
87 appropriate read-ahead and caching techniques.
88 These
89 .I advice
90 values do not influence the semantics of the application
91 (except in the case of
92 .BR MADV_DONTNEED ),
93 but may influence its performance.
94 All of the
95 .I advice
96 values listed here have analogs in the POSIX-specified
97 .BR posix_madvise (3)
98 function, and the values have the same meanings, with the exception of
99 .BR MADV_DONTNEED .
100 .PP
101 The advice is indicated in the
102 .I advice
103 argument, which is one of the following:
104 .TP
105 .B MADV_NORMAL
106 No special treatment.
107 This is the default.
108 .TP
109 .B MADV_RANDOM
110 Expect page references in random order.
111 (Hence, read ahead may be less useful than normally.)
112 .TP
113 .B MADV_SEQUENTIAL
114 Expect page references in sequential order.
115 (Hence, pages in the given range can be aggressively read ahead,
116 and may be freed soon after they are accessed.)
117 .TP
118 .B MADV_WILLNEED
119 Expect access in the near future.
120 (Hence, it might be a good idea to read some pages ahead.)
121 .TP
122 .B MADV_DONTNEED
123 Do not expect access in the near future.
124 (For the time being, the application is finished with the given range,
125 so the kernel can free resources associated with it.)
126 .IP
127 After a successful
128 .B MADV_DONTNEED
129 operation,
130 the semantics of memory access in the specified region are changed:
131 subsequent accesses of pages in the range will succeed, but will result
132 in either repopulating the memory contents from the
133 up-to-date contents of the underlying mapped file
134 (for shared file mappings, shared anonymous mappings,
135 and shmem-based techniques such as System V shared memory segments)
136 or zero-fill-on-demand pages for anonymous private mappings.
137 .IP
138 Note that, when applied to shared mappings,
139 .BR MADV_DONTNEED
140 might not lead to immediate freeing of the pages in the range.
141 The kernel is free to delay freeing the pages until an appropriate moment.
142 The resident set size (RSS) of the calling process will be immediately
143 reduced however.
144 .IP
145 .B MADV_DONTNEED
146 cannot be applied to locked pages, Huge TLB pages, or
147 .BR VM_PFNMAP
148 pages.
149 (Pages marked with the kernel-internal
150 .B VM_PFNMAP
151 .\" http://lwn.net/Articles/162860/
152 flag are special memory areas that are not managed
153 by the virtual memory subsystem.
154 Such pages are typically created by device drivers that
155 map the pages into user space.)
156 .\"
157 .\" ======================================================================
158 .\"
159 .SS Linux-specific advice values
160 The following Linux-specific
161 .I advice
162 values have no counterparts in the POSIX-specified
163 .BR posix_madvise (3),
164 and may or may not have counterparts in the
165 .BR madvise ()
166 interface available on other implementations.
167 Note that some of these operations change the semantics of memory accesses.
168 .TP
169 .BR MADV_REMOVE " (since Linux 2.6.16)"
170 .\" commit f6b3ec238d12c8cc6cc71490c6e3127988460349
171 Free up a given range of pages
172 and its associated backing store.
173 This is equivalent to punching a hole in the corresponding byte
174 range of the backing store (see
175 .BR fallocate (2)).
176 Subsequent accesses in the specified address range will see
177 bytes containing zero.
178 .\" Databases want to use this feature to drop a section of their
179 .\" bufferpool (shared memory segments) - without writing back to
180 .\" disk/swap space. This feature is also useful for supporting
181 .\" hot-plug memory on UML.
182 .IP
183 The specified address range must be mapped shared and writable.
184 This flag cannot be applied to locked pages, Huge TLB pages, or
185 .BR VM_PFNMAP
186 pages.
187 .IP
188 In the initial implementation, only
189 .BR tmpfs (5)
190 was supported
191 .BR MADV_REMOVE ;
192 but since Linux 3.5,
193 .\" commit 3f31d07571eeea18a7d34db9af21d2285b807a17
194 any filesystem which supports the
195 .BR fallocate (2)
196 .BR FALLOC_FL_PUNCH_HOLE
197 mode also supports
198 .BR MADV_REMOVE .
199 Hugetlbfs fails with the error
200 .BR EINVAL
201 and other filesystems fail with the error
202 .BR EOPNOTSUPP .
203 .TP
204 .BR MADV_DONTFORK " (since Linux 2.6.16)"
205 .\" commit f822566165dd46ff5de9bf895cfa6c51f53bb0c4
206 .\" See http://lwn.net/Articles/171941/
207 Do not make the pages in this range available to the child after a
208 .BR fork (2).
209 This is useful to prevent copy-on-write semantics from changing
210 the physical location of a page if the parent writes to it after a
211 .BR fork (2).
212 (Such page relocations cause problems for hardware that
213 DMAs into the page.)
214 .\" [PATCH] madvise MADV_DONTFORK/MADV_DOFORK
215 .\" Currently, copy-on-write may change the physical address of
216 .\" a page even if the user requested that the page is pinned in
217 .\" memory (either by mlock or by get_user_pages). This happens
218 .\" if the process forks meanwhile, and the parent writes to that
219 .\" page. As a result, the page is orphaned: in case of
220 .\" get_user_pages, the application will never see any data hardware
221 .\" DMA's into this page after the COW. In case of mlock'd memory,
222 .\" the parent is not getting the realtime/security benefits of mlock.
223 .\"
224 .\" In particular, this affects the Infiniband modules which do DMA from
225 .\" and into user pages all the time.
226 .\"
227 .\" This patch adds madvise options to control whether memory range is
228 .\" inherited across fork. Useful e.g. for when hardware is doing DMA
229 .\" from/into these pages. Could also be useful to an application
230 .\" wanting to speed up its forks by cutting large areas out of
231 .\" consideration.
232 .\"
233 .\" SEE ALSO: http://lwn.net/Articles/171941/
234 .\" "Tweaks to madvise() and posix_fadvise()", 14 Feb 2006
235 .TP
236 .BR MADV_DOFORK " (since Linux 2.6.16)"
237 Undo the effect of
238 .BR MADV_DONTFORK ,
239 restoring the default behavior, whereby a mapping is inherited across
240 .BR fork (2).
241 .TP
242 .BR MADV_HWPOISON " (since Linux 2.6.32)"
243 .\" commit 9893e49d64a4874ea67849ee2cfbf3f3d6817573
244 Poison the pages in the range specified by
245 .I addr
246 and
247 .IR length
248 and handle subsequent references to those pages
249 like a hardware memory corruption.
250 This operation is available only for privileged
251 .RB ( CAP_SYS_ADMIN )
252 processes.
253 This operation may result in the calling process receiving a
254 .B SIGBUS
255 and the page being unmapped.
256 .IP
257 This feature is intended for testing of memory error-handling code;
258 it is available only if the kernel was configured with
259 .BR CONFIG_MEMORY_FAILURE .
260 .TP
261 .BR MADV_MERGEABLE " (since Linux 2.6.32)"
262 .\" commit f8af4da3b4c14e7267c4ffb952079af3912c51c5
263 Enable Kernel Samepage Merging (KSM) for the pages in the range specified by
264 .I addr
265 and
266 .IR length .
267 The kernel regularly scans those areas of user memory that have
268 been marked as mergeable,
269 looking for pages with identical content.
270 These are replaced by a single write-protected page (which is automatically
271 copied if a process later wants to update the content of the page).
272 KSM merges only private anonymous pages (see
273 .BR mmap (2)).
274 .IP
275 The KSM feature is intended for applications that generate many
276 instances of the same data (e.g., virtualization systems such as KVM).
277 It can consume a lot of processing power; use with care.
278 See the Linux kernel source file
279 .I Documentation/admin\-guide/mm/ksm.rst
280 for more details.
281 .IP
282 The
283 .BR MADV_MERGEABLE
284 and
285 .BR MADV_UNMERGEABLE
286 operations are available only if the kernel was configured with
287 .BR CONFIG_KSM .
288 .TP
289 .BR MADV_UNMERGEABLE " (since Linux 2.6.32)"
290 Undo the effect of an earlier
291 .BR MADV_MERGEABLE
292 operation on the specified address range;
293 KSM unmerges whatever pages it had merged in the address range specified by
294 .IR addr
295 and
296 .IR length .
297 .TP
298 .BR MADV_SOFT_OFFLINE " (since Linux 2.6.33)"
299 .\" commit afcf938ee0aac4ef95b1a23bac704c6fbeb26de6
300 Soft offline the pages in the range specified by
301 .I addr
302 and
303 .IR length .
304 The memory of each page in the specified range is preserved
305 (i.e., when next accessed, the same content will be visible,
306 but in a new physical page frame),
307 and the original page is offlined
308 (i.e., no longer used, and taken out of normal memory management).
309 The effect of the
310 .B MADV_SOFT_OFFLINE
311 operation is invisible to (i.e., does not change the semantics of)
312 the calling process.
313 .IP
314 This feature is intended for testing of memory error-handling code;
315 it is available only if the kernel was configured with
316 .BR CONFIG_MEMORY_FAILURE .
317 .TP
318 .BR MADV_HUGEPAGE " (since Linux 2.6.38)"
319 .\" commit 0af4e98b6b095c74588af04872f83d333c958c32
320 .\" http://lwn.net/Articles/358904/
321 .\" https://lwn.net/Articles/423584/
322 Enable Transparent Huge Pages (THP) for pages in the range specified by
323 .I addr
324 and
325 .IR length .
326 Currently, Transparent Huge Pages work only with private anonymous pages (see
327 .BR mmap (2)).
328 The kernel will regularly scan the areas marked as huge page candidates
329 to replace them with huge pages.
330 The kernel will also allocate huge pages directly when the region is
331 naturally aligned to the huge page size (see
332 .BR posix_memalign (2)).
333 .IP
334 This feature is primarily aimed at applications that use large mappings of
335 data and access large regions of that memory at a time (e.g., virtualization
336 systems such as QEMU).
337 It can very easily waste memory (e.g., a 2\ MB mapping that only ever accesses
338 1 byte will result in 2\ MB of wired memory instead of one 4\ KB page).
339 See the Linux kernel source file
340 .I Documentation/admin\-guide/mm/transhuge.rst
341 for more details.
342 .IP
343 Most common kernels configurations provide
344 .BR MADV_HUGEPAGE -style
345 behavior by default, and thus
346 .BR MADV_HUGEPAGE
347 is normally not necessary.
348 It is mostly intended for embedded systems, where
349 .BR MADV_HUGEPAGE -style
350 behavior may not be enabled by default in the kernel.
351 On such systems,
352 this flag can be used in order to selectively enable THP.
353 Whenever
354 .BR MADV_HUGEPAGE
355 is used, it should always be in regions of memory with
356 an access pattern that the developer knows in advance won't risk
357 to increase the memory footprint of the application when transparent
358 hugepages are enabled.
359 .IP
360 The
361 .BR MADV_HUGEPAGE
362 and
363 .BR MADV_NOHUGEPAGE
364 operations are available only if the kernel was configured with
365 .BR CONFIG_TRANSPARENT_HUGEPAGE .
366 .TP
367 .BR MADV_NOHUGEPAGE " (since Linux 2.6.38)"
368 Ensures that memory in the address range specified by
369 .IR addr
370 and
371 .IR length
372 will not be backed by transparent hugepages.
373 .TP
374 .BR MADV_DONTDUMP " (since Linux 3.4)"
375 .\" commit 909af768e88867016f427264ae39d27a57b6a8ed
376 .\" commit accb61fe7bb0f5c2a4102239e4981650f9048519
377 Exclude from a core dump those pages in the range specified by
378 .I addr
379 and
380 .IR length .
381 This is useful in applications that have large areas of memory
382 that are known not to be useful in a core dump.
383 The effect of
384 .BR MADV_DONTDUMP
385 takes precedence over the bit mask that is set via the
386 .I /proc/[pid]/coredump_filter
387 file (see
388 .BR core (5)).
389 .TP
390 .BR MADV_DODUMP " (since Linux 3.4)"
391 Undo the effect of an earlier
392 .BR MADV_DONTDUMP .
393 .TP
394 .BR MADV_FREE " (since Linux 4.5)"
395 The application no longer requires the pages in the range specified by
396 .IR addr
397 and
398 .IR len .
399 The kernel can thus free these pages,
400 but the freeing could be delayed until memory pressure occurs.
401 For each of the pages that has been marked to be freed
402 but has not yet been freed,
403 the free operation will be canceled if the caller writes into the page.
404 After a successful
405 .B MADV_FREE
406 operation, any stale data (i.e., dirty, unwritten pages) will be lost
407 when the kernel frees the pages.
408 However, subsequent writes to pages in the range will succeed
409 and then kernel cannot free those dirtied pages,
410 so that the caller can always see just written data.
411 If there is no subsequent write,
412 the kernel can free the pages at any time.
413 Once pages in the range have been freed, the caller will
414 see zero-fill-on-demand pages upon subsequent page references.
415 .IP
416 The
417 .B MADV_FREE
418 operation
419 can be applied only to private anonymous pages (see
420 .BR mmap (2)).
421 In Linux before version 4.12,
422 .\" commit 93e06c7a645343d222c9a838834a51042eebbbf7
423 when freeing pages on a swapless system,
424 the pages in the given range are freed instantly,
425 regardless of memory pressure.
426 .TP
427 .BR MADV_WIPEONFORK " (since Linux 4.14)"
428 .\" commit d2cd9ede6e193dd7d88b6d27399e96229a551b19
429 Present the child process with zero-filled memory in this range after a
430 .BR fork (2).
431 This is useful in forking servers in order to ensure
432 that sensitive per-process data
433 (for example, PRNG seeds, cryptographic secrets, and so on)
434 is not handed to child processes.
435 .IP
436 The
437 .B MADV_WIPEONFORK
438 operation can be applied only to private anonymous pages (see
439 .BR mmap (2)).
440 .IP
441 Within the child created by
442 .BR fork (2),
443 the
444 .B MADV_WIPEONFORK
445 setting remains in place on the specified address range.
446 This setting is cleared during
447 .BR execve (2).
448 .TP
449 .BR MADV_KEEPONFORK " (since Linux 4.14)"
450 .\" commit d2cd9ede6e193dd7d88b6d27399e96229a551b19
451 Undo the effect of an earlier
452 .BR MADV_WIPEONFORK .
453 .TP
454 .BR MADV_COLD " (since Linux 5.4)"
455 .\" commit 9c276cc65a58faf98be8e56962745ec99ab87636
456 Deactivate a given range of pages.
457 This will make the pages a more probable
458 reclaim target should there be a memory pressure.
459 This is a nondestructive operation.
460 The advice might be ignored for some pages in the range when it is not
461 applicable.
462 .TP
463 .BR MADV_PAGEOUT " (since Linux 5.4)"
464 .\" commit 1a4e58cce84ee88129d5d49c064bd2852b481357
465 Reclaim a given range of pages.
466 This is done to free up memory occupied by these pages.
467 If a page is anonymous, it will be swapped out.
468 If a page is file-backed and dirty, it will be written back to the backing
469 storage.
470 The advice might be ignored for some pages in the range when it is not
471 applicable.
472 .TP
473 .BR MADV_POPULATE_READ " (since Linux 5.14)"
474 "Populate (prefault) page tables readable,
475 faulting in all pages in the range just as if manually reading from each page;
476 however,
477 avoid the actual memory access that would have been performed after handling
478 the fault.
479 .IP
480 In contrast to
481 .BR MAP_POPULATE ,
482 .B MADV_POPULATE_READ
483 does not hide errors,
484 can be applied to (parts of) existing mappings and will always populate
485 (prefault) page tables readable.
486 One example use case is prefaulting a file mapping,
487 reading all file content from disk;
488 however,
489 pages won't be dirtied and consequently won't have to be written back to disk
490 when evicting the pages from memory.
491 .IP
492 Depending on the underlying mapping,
493 map the shared zeropage,
494 preallocate memory or read the underlying file;
495 files with holes might or might not preallocate blocks.
496 If populating fails,
497 a
498 .B SIGBUS
499 signal is not generated; instead, an error is returned.
500 .IP
501 If
502 .B MADV_POPULATE_READ
503 succeeds,
504 all page tables have been populated (prefaulted) readable once.
505 If
506 .B MADV_POPULATE_READ
507 fails,
508 some page tables might have been populated.
509 .IP
510 .B MADV_POPULATE_READ
511 cannot be applied to mappings without read permissions
512 and special mappings,
513 for example,
514 mappings marked with kernel-internal flags such as
515 .B VM_PFNMAP
516 or
517 .BR VM_IO ,
518 or secret memory regions created using
519 .BR memfd_secret(2) .
520 .IP
521 Note that with
522 .BR MADV_POPULATE_READ ,
523 the process can be killed at any moment when the system runs out of memory.
524 .TP
525 .BR MADV_POPULATE_WRITE " (since Linux 5.14)"
526 Populate (prefault) page tables writable,
527 faulting in all pages in the range just as if manually writing to each
528 each page;
529 however,
530 avoid the actual memory access that would have been performed after handling
531 the fault.
532 .IP
533 In contrast to
534 .BR MAP_POPULATE ,
535 MADV_POPULATE_WRITE does not hide errors,
536 can be applied to (parts of) existing mappings and will always populate
537 (prefault) page tables writable.
538 One example use case is preallocating memory,
539 breaking any CoW (Copy on Write).
540 .IP
541 Depending on the underlying mapping,
542 preallocate memory or read the underlying file;
543 files with holes will preallocate blocks.
544 If populating fails,
545 a
546 .B SIGBUS
547 signal is not generated; instead, an error is returned.
548 .IP
549 If
550 .B MADV_POPULATE_WRITE
551 succeeds,
552 all page tables have been populated (prefaulted) writable once.
553 If
554 .B MADV_POPULATE_WRITE
555 fails,
556 some page tables might have been populated.
557 .IP
558 .B MADV_POPULATE_WRITE
559 cannot be applied to mappings without write permissions
560 and special mappings,
561 for example,
562 mappings marked with kernel-internal flags such as
563 .B VM_PFNMAP
564 or
565 .BR VM_IO ,
566 or secret memory regions created using
567 .BR memfd_secret(2) .
568 .IP
569 Note that with
570 .BR MADV_POPULATE_WRITE ,
571 the process can be killed at any moment when the system runs out of memory.
572 .SH RETURN VALUE
573 On success,
574 .BR madvise ()
575 returns zero.
576 On error, it returns \-1 and
577 .I errno
578 is set to indicate the error.
579 .SH ERRORS
580 .TP
581 .B EACCES
582 .I advice
583 is
584 .BR MADV_REMOVE ,
585 but the specified address range is not a shared writable mapping.
586 .TP
587 .B EAGAIN
588 A kernel resource was temporarily unavailable.
589 .TP
590 .B EBADF
591 The map exists, but the area maps something that isn't a file.
592 .TP
593 .B EFAULT
594 .I advice
595 is
596 .B MADV_POPULATE_READ
597 or
598 .BR MADV_POPULATE_WRITE ,
599 and populating (prefaulting) page tables failed because a
600 .B SIGBUS
601 would have been generated on actual memory access and the reason is not a
602 HW poisoned page
603 (HW poisoned pages can,
604 for example,
605 be created using the
606 .B MADV_HWPOISON
607 flag described elsewhere in this page).
608 .TP
609 .B EINVAL
610 .I addr
611 is not page-aligned or
612 .I length
613 is negative.
614 .\" .I length
615 .\" is zero,
616 .TP
617 .B EINVAL
618 .I advice
619 is not a valid.
620 .TP
621 .B EINVAL
622 .I advice
623 is
624 .B MADV_DONTNEED
625 or
626 .BR MADV_REMOVE
627 and the specified address range includes locked, Huge TLB pages, or
628 .B VM_PFNMAP
629 pages.
630 .TP
631 .B EINVAL
632 .I advice
633 is
634 .BR MADV_MERGEABLE
635 or
636 .BR MADV_UNMERGEABLE ,
637 but the kernel was not configured with
638 .BR CONFIG_KSM .
639 .TP
640 .B EINVAL
641 .I advice
642 is
643 .BR MADV_FREE
644 or
645 .BR MADV_WIPEONFORK
646 but the specified address range includes file, Huge TLB,
647 .BR MAP_SHARED ,
648 or
649 .BR VM_PFNMAP
650 ranges.
651 .TP
652 .B EINVAL
653 .I advice
654 is
655 .B MADV_POPULATE_READ
656 or
657 .BR MADV_POPULATE_WRITE ,
658 but the specified address range includes ranges with insufficient permissions
659 or special mappings,
660 for example,
661 mappings marked with kernel-internal flags such a
662 .B VM_IO
663 or
664 .BR VM_PFNMAP ,
665 or secret memory regions created using
666 .BR memfd_secret(2) .
667 .TP
668 .B EIO
669 (for
670 .BR MADV_WILLNEED )
671 Paging in this area would exceed the process's
672 maximum resident set size.
673 .TP
674 .B ENOMEM
675 (for
676 .BR MADV_WILLNEED )
677 Not enough memory: paging in failed.
678 .TP
679 .B ENOMEM
680 Addresses in the specified range are not currently
681 mapped, or are outside the address space of the process.
682 .TP
683 .B ENOMEM
684 .I advice
685 is
686 .B MADV_POPULATE_READ
687 or
688 .BR MADV_POPULATE_WRITE ,
689 and populating (prefaulting) page tables failed because there was not enough
690 memory.
691 .TP
692 .B EPERM
693 .I advice
694 is
695 .BR MADV_HWPOISON ,
696 but the caller does not have the
697 .B CAP_SYS_ADMIN
698 capability.
699 .TP
700 .B EHWPOISON
701 .I advice
702 is
703 .B MADV_POPULATE_READ
704 or
705 .BR MADV_POPULATE_WRITE ,
706 and populating (prefaulting) page tables failed because a HW poisoned page
707 (HW poisoned pages can,
708 for example,
709 be created using the
710 .B MADV_HWPOISON
711 flag described elsewhere in this page)
712 was encountered.
713 .SH VERSIONS
714 Since Linux 3.18,
715 .\" commit d3ac21cacc24790eb45d735769f35753f5b56ceb
716 support for this system call is optional,
717 depending on the setting of the
718 .B CONFIG_ADVISE_SYSCALLS
719 configuration option.
720 .SH CONFORMING TO
721 .BR madvise ()
722 is not specified by any standards.
723 Versions of this system call, implementing a wide variety of
724 .I advice
725 values, exist on many other implementations.
726 Other implementations typically implement at least the flags listed
727 above under
728 .IR "Conventional advice flags" ,
729 albeit with some variation in semantics.
730 .PP
731 POSIX.1-2001 describes
732 .BR posix_madvise (3)
733 with constants
734 .BR POSIX_MADV_NORMAL ,
735 .BR POSIX_MADV_RANDOM ,
736 .BR POSIX_MADV_SEQUENTIAL ,
737 .BR POSIX_MADV_WILLNEED ,
738 and
739 .BR POSIX_MADV_DONTNEED ,
740 and so on, with behavior close to the similarly named flags listed above.
741 .SH NOTES
742 .SS Linux notes
743 The Linux implementation requires that the address
744 .I addr
745 be page-aligned, and allows
746 .I length
747 to be zero.
748 If there are some parts of the specified address range
749 that are not mapped, the Linux version of
750 .BR madvise ()
751 ignores them and applies the call to the rest (but returns
752 .B ENOMEM
753 from the system call, as it should).
754 .\" .SH HISTORY
755 .\" The
756 .\" .BR madvise ()
757 .\" function first appeared in 4.4BSD.
758 .SH SEE ALSO
759 .BR getrlimit (2),
760 .BR memfd_secret(2),
761 .BR mincore (2),
762 .BR mmap (2),
763 .BR mprotect (2),
764 .BR msync (2),
765 .BR munmap (2),
766 .BR prctl (2),
767 .BR process_madvise (2),
768 .BR posix_madvise (3),
769 .BR core (5)