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 2017-09-15 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)):
39 _POSIX_C_SOURCE >= 200112L
45 function allows an application to advise the system about its expected
46 patterns of usage of memory in the address range starting at
51 The system is free to use this advice in order to improve the performance
52 of memory accesses (or to ignore the advice altogether), but calling
54 shall not affect the semantics of access to memory in the specified range.
58 argument is one of the following:
61 The application has no special advice regarding its memory usage patterns
62 for the specified address range.
63 This is the default behavior.
65 .B POSIX_MADV_SEQUENTIAL
66 The application expects to access the specified address range sequentially,
67 running from lower addresses to higher addresses.
68 Hence, pages in this region can be aggressively read ahead,
69 and may be freed soon after they are accessed.
72 The application expects to access the specified address range randomly.
73 Thus, read ahead may be less useful than normally.
75 .B POSIX_MADV_WILLNEED
76 The application expects to access the specified address range
78 Thus, read ahead may be beneficial.
80 .B POSIX_MADV_DONTNEED
81 The application expects that it will not access the specified address range
87 On failure, it returns a positive error number.
92 is not a multiple of the system page size or
101 Addresses in the specified range are partially or completely outside
102 the caller's address space.
106 first appeared in glibc version 2.2.
110 POSIX.1 permits an implementation to generate an error if
115 as 0 is permitted (as a successful no-op).
117 In glibc, this function is implemented using
119 However, since glibc 2.6,
120 .BR POSIX_MADV_DONTNEED
121 is treated as a no-op, because the corresponding
125 has destructive semantics.
128 .BR posix_fadvise (2)