man-pages/man3/posix_madvise.3.html
2021-03-31 01:06:50 +01:00

209 lines
4.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of POSIX_MADVISE</TITLE>
</HEAD><BODY>
<H1>POSIX_MADVISE</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
posix_madvise - give advice about patterns of memory usage
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/sys/mman.h">sys/mman.h</A>&gt;</B>
<B>int posix_madvise(void *</B><I>addr</I><B>, size_t </B><I>len</I><B>, int </B><I>advice</I><B>);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>posix_madvise</B>():
<BR>
<DL COMPACT><DT id="1"><DD>
_POSIX_C_SOURCE &gt;= 200112L
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>posix_madvise</B>()
function allows an application to advise the system about its expected
patterns of usage of memory in the address range starting at
<I>addr</I>
and continuing for
<I>len</I>
bytes.
The system is free to use this advice in order to improve the performance
of memory accesses (or to ignore the advice altogether), but calling
<B>posix_madvise</B>()
shall not affect the semantics of access to memory in the specified range.
<P>
The
<I>advice</I>
argument is one of the following:
<DL COMPACT>
<DT id="2"><B>POSIX_MADV_NORMAL</B>
<DD>
The application has no special advice regarding its memory usage patterns
for the specified address range.
This is the default behavior.
<DT id="3"><B>POSIX_MADV_SEQUENTIAL</B>
<DD>
The application expects to access the specified address range sequentially,
running from lower addresses to higher addresses.
Hence, pages in this region can be aggressively read ahead,
and may be freed soon after they are accessed.
<DT id="4"><B>POSIX_MADV_RANDOM</B>
<DD>
The application expects to access the specified address range randomly.
Thus, read ahead may be less useful than normally.
<DT id="5"><B>POSIX_MADV_WILLNEED</B>
<DD>
The application expects to access the specified address range
in the near future.
Thus, read ahead may be beneficial.
<DT id="6"><B>POSIX_MADV_DONTNEED</B>
<DD>
The application expects that it will not access the specified address range
in the near future.
</DL>
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
<B>posix_madvise</B>()
returns 0.
On failure, it returns a positive error number.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="7"><B>EINVAL</B>
<DD>
<I>addr</I>
is not a multiple of the system page size or
<I>len</I>
is negative.
<DT id="8"><B>EINVAL</B>
<DD>
<I>advice</I>
is invalid.
<DT id="9"><B>ENOMEM</B>
<DD>
Addresses in the specified range are partially or completely outside
the caller's address space.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
Support for
<B>posix_madvise</B>()
first appeared in glibc version 2.2.
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
POSIX.1 permits an implementation to generate an error if
<I>len</I>
is 0.
On Linux, specifying
<I>len</I>
as 0 is permitted (as a successful no-op).
<P>
In glibc, this function is implemented using
<B><A HREF="/cgi-bin/man/man2html?2+madvise">madvise</A></B>(2).
However, since glibc 2.6,
<B>POSIX_MADV_DONTNEED</B>
is treated as a no-op, because the corresponding
<B><A HREF="/cgi-bin/man/man2html?2+madvise">madvise</A></B>(2)
value,
<B>MADV_DONTNEED</B>,
has destructive semantics.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+madvise">madvise</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+posix_fadvise">posix_fadvise</A></B>(2)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="10"><A HREF="#lbAB">NAME</A><DD>
<DT id="11"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="12"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="13"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="14"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="15"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="16"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="17"><A HREF="#lbAI">NOTES</A><DD>
<DT id="18"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="19"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:52 GMT, March 31, 2021
</BODY>
</HTML>