1 .\" Copyright (C) 2015 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(GPLv2+)
5 .\" This program is free software; you can redistribute it and/or modify
6 .\" it under the terms of the GNU General Public License as published by
7 .\" the Free Software Foundation; either version 2 of the License, or
8 .\" (at your option) any later version.
10 .\" This program is distributed in the hope that it will be useful,
11 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
12 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 .\" GNU General Public License for more details.
15 .\" You should have received a copy of the GNU General Public
16 .\" License along with this manual; if not, see
17 .\" <http://www.gnu.org/licenses/>.
20 .TH POSIX_MADVISE 3 2021-03-22 Linux "Linux Programmer's Manual"
22 posix_madvise \- give advice about patterns of memory usage
25 .B #include <sys/mman.h>
27 .BI "int posix_madvise(void *" addr ", size_t " len ", int " advice );
31 Feature Test Macro Requirements for glibc (see
32 .BR feature_test_macros (7)):
37 _POSIX_C_SOURCE >= 200112L
42 function allows an application to advise the system about its expected
43 patterns of usage of memory in the address range starting at
48 The system is free to use this advice in order to improve the performance
49 of memory accesses (or to ignore the advice altogether), but calling
51 shall not affect the semantics of access to memory in the specified range.
55 argument is one of the following:
58 The application has no special advice regarding its memory usage patterns
59 for the specified address range.
60 This is the default behavior.
62 .B POSIX_MADV_SEQUENTIAL
63 The application expects to access the specified address range sequentially,
64 running from lower addresses to higher addresses.
65 Hence, pages in this region can be aggressively read ahead,
66 and may be freed soon after they are accessed.
69 The application expects to access the specified address range randomly.
70 Thus, read ahead may be less useful than normally.
72 .B POSIX_MADV_WILLNEED
73 The application expects to access the specified address range
75 Thus, read ahead may be beneficial.
77 .B POSIX_MADV_DONTNEED
78 The application expects that it will not access the specified address range
84 On failure, it returns a positive error number.
89 is not a multiple of the system page size or
98 Addresses in the specified range are partially or completely outside
99 the caller's address space.
103 first appeared in glibc version 2.2.
107 POSIX.1 permits an implementation to generate an error if
112 as 0 is permitted (as a successful no-op).
114 In glibc, this function is implemented using
116 However, since glibc 2.6,
117 .BR POSIX_MADV_DONTNEED
118 is treated as a no-op, because the corresponding
122 has destructive semantics.
125 .BR posix_fadvise (2)