]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/posix_madvise.3
man*/: srcfix (Use .P instead of .PP or .LP)
[thirdparty/man-pages.git] / man3 / posix_madvise.3
CommitLineData
b99daa3f
MK
1.\" Copyright (C) 2015 Michael Kerrisk <mtk.manpages@gmail.com>
2.\"
e4a74ca8 3.\" SPDX-License-Identifier: GPL-2.0-or-later
b99daa3f 4.\"
4c1c5274 5.TH posix_madvise 3 (date) "Linux man-pages (unreleased)"
b99daa3f
MK
6.SH NAME
7posix_madvise \- give advice about patterns of memory usage
8497c7a6
AC
8.SH LIBRARY
9Standard C library
8fc3b2cf 10.RI ( libc ", " \-lc )
b99daa3f
MK
11.SH SYNOPSIS
12.nf
13.B #include <sys/mman.h>
c6d039a3 14.P
c64cd13e 15.BI "int posix_madvise(void " addr [. len "], size_t " len ", int " advice );
b99daa3f 16.fi
c6d039a3 17.P
d39ad78f 18.RS -4
b99daa3f
MK
19Feature Test Macro Requirements for glibc (see
20.BR feature_test_macros (7)):
d39ad78f 21.RE
c6d039a3 22.P
b99daa3f 23.BR posix_madvise ():
9d2adbae
MK
24.nf
25 _POSIX_C_SOURCE >= 200112L
26.fi
b99daa3f
MK
27.SH DESCRIPTION
28The
29.BR posix_madvise ()
30function allows an application to advise the system about its expected
31patterns of usage of memory in the address range starting at
32.I addr
33and continuing for
34.I len
35bytes.
36The system is free to use this advice in order to improve the performance
37of memory accesses (or to ignore the advice altogether), but calling
38.BR posix_madvise ()
39shall not affect the semantics of access to memory in the specified range.
c6d039a3 40.P
b99daa3f
MK
41The
42.I advice
43argument is one of the following:
44.TP
45.B POSIX_MADV_NORMAL
46The application has no special advice regarding its memory usage patterns
47for the specified address range.
48This is the default behavior.
49.TP
50.B POSIX_MADV_SEQUENTIAL
51The application expects to access the specified address range sequentially,
52running from lower addresses to higher addresses.
53Hence, pages in this region can be aggressively read ahead,
54and may be freed soon after they are accessed.
55.TP
56.B POSIX_MADV_RANDOM
57The application expects to access the specified address range randomly.
58Thus, read ahead may be less useful than normally.
59.TP
60.B POSIX_MADV_WILLNEED
61The application expects to access the specified address range
62in the near future.
63Thus, read ahead may be beneficial.
64.TP
65.B POSIX_MADV_DONTNEED
66The application expects that it will not access the specified address range
67in the near future.
68.SH RETURN VALUE
69On success,
70.BR posix_madvise ()
71returns 0.
72On failure, it returns a positive error number.
73.SH ERRORS
74.TP
75.B EINVAL
76.I addr
77is not a multiple of the system page size or
78.I len
79is negative.
80.TP
81.B EINVAL
82.I advice
83is invalid.
84.TP
85.B ENOMEM
86Addresses in the specified range are partially or completely outside
87the caller's address space.
88.SH VERSIONS
b99daa3f
MK
89POSIX.1 permits an implementation to generate an error if
90.I len
91is 0.
92On Linux, specifying
93.I len
94as 0 is permitted (as a successful no-op).
c6d039a3 95.P
b99daa3f
MK
96In glibc, this function is implemented using
97.BR madvise (2).
98However, since glibc 2.6,
1ae6b2c7 99.B POSIX_MADV_DONTNEED
b99daa3f
MK
100is treated as a no-op, because the corresponding
101.BR madvise (2)
102value,
103.BR MADV_DONTNEED ,
104has destructive semantics.
4131356c
AC
105.SH STANDARDS
106POSIX.1-2008.
107.SH HISTORY
108glibc 2.2.
109POSIX.1-2001.
b99daa3f
MK
110.SH SEE ALSO
111.BR madvise (2),
112.BR posix_fadvise (2)