]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/posix_madvise.3
getauxval.3: wfix
[thirdparty/man-pages.git] / man3 / posix_madvise.3
CommitLineData
b99daa3f
MK
1.\" Copyright (C) 2015 Michael Kerrisk <mtk.manpages@gmail.com>
2.\"
3.\" %%%LICENSE_START(GPLv2+)
4.\"
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.
9.\"
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.
14.\"
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/>.
18.\" %%%LICENSE_END
19.\"
20.TH POSIX_MADVISE 3 2015-02-03 Linux "Linux Programmer's Manual"
21.SH NAME
22posix_madvise \- give advice about patterns of memory usage
23.SH SYNOPSIS
24.nf
25.B #include <sys/mman.h>
26
27.BI "int posix_madvise(void *" addr ", size_t " len ", int " advice );
28.fi
29
30.in -4n
31Feature Test Macro Requirements for glibc (see
32.BR feature_test_macros (7)):
33.in
34.sp
35.BR posix_madvise ():
36.br
37.RS 4
38.ad l
39_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
40.RE
41.ad
42.SH DESCRIPTION
43The
44.BR posix_madvise ()
45function allows an application to advise the system about its expected
46patterns of usage of memory in the address range starting at
47.I addr
48and continuing for
49.I len
50bytes.
51The system is free to use this advice in order to improve the performance
52of memory accesses (or to ignore the advice altogether), but calling
53.BR posix_madvise ()
54shall not affect the semantics of access to memory in the specified range.
55
56The
57.I advice
58argument is one of the following:
59.TP
60.B POSIX_MADV_NORMAL
61The application has no special advice regarding its memory usage patterns
62for the specified address range.
63This is the default behavior.
64.TP
65.B POSIX_MADV_SEQUENTIAL
66The application expects to access the specified address range sequentially,
67running from lower addresses to higher addresses.
68Hence, pages in this region can be aggressively read ahead,
69and may be freed soon after they are accessed.
70.TP
71.B POSIX_MADV_RANDOM
72The application expects to access the specified address range randomly.
73Thus, read ahead may be less useful than normally.
74.TP
75.B POSIX_MADV_WILLNEED
76The application expects to access the specified address range
77in the near future.
78Thus, read ahead may be beneficial.
79.TP
80.B POSIX_MADV_DONTNEED
81The application expects that it will not access the specified address range
82in the near future.
83.SH RETURN VALUE
84On success,
85.BR posix_madvise ()
86returns 0.
87On failure, it returns a positive error number.
88.SH ERRORS
89.TP
90.B EINVAL
91.I addr
92is not a multiple of the system page size or
93.I len
94is negative.
95.TP
96.B EINVAL
97.I advice
98is invalid.
99.TP
100.B ENOMEM
101Addresses in the specified range are partially or completely outside
102the caller's address space.
103.SH VERSIONS
104Support for
105.BR posix_madvise ()
106first appeared in glibc version 2.2.
107.SH CONFORMING TO
108POSIX.1-2001.
109
110POSIX.1-2008 specifies a further value for
111.IR advice ,
112.BR POSIX_FADV_NOREUSE ,
113meaning that the specified data will be accessed only once.
114This value is not currently supported.
115.SH NOTES
116POSIX.1 permits an implementation to generate an error if
117.I len
118is 0.
119On Linux, specifying
120.I len
121as 0 is permitted (as a successful no-op).
122
123In glibc, this function is implemented using
124.BR madvise (2).
125However, since glibc 2.6,
126.BR POSIX_MADV_DONTNEED
127is treated as a no-op, because the corresponding
128.BR madvise (2)
129value,
130.BR MADV_DONTNEED ,
131has destructive semantics.
132.SH SEE ALSO
133.BR madvise (2),
134.BR posix_fadvise (2)