man-pages/man2/remap_file_pages.2.html
2021-03-31 01:06:50 +01:00

281 lines
6.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of REMAP_FILE_PAGES</TITLE>
</HEAD><BODY>
<H1>REMAP_FILE_PAGES</H1>
Section: Linux Programmer's Manual (2)<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>
remap_file_pages - create a nonlinear file mapping
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#define _GNU_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
<B>#include &lt;<A HREF="file:///usr/include/sys/mman.h">sys/mman.h</A>&gt;</B>
<B>int remap_file_pages(void *</B><I>addr</I><B>, size_t </B><I>size</I><B>, int </B><I>prot</I><B>,</B>
<B> size_t </B><I>pgoff</I><B>, int </B><I>flags</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>Note</B>:
this system call was marked as deprecated starting with Linux 3.16.
In Linux 4.0, the implementation was replaced
by a slower in-kernel emulation.
Those few applications that use this system call should
consider migrating to alternatives.
This change was made because the kernel code for this system call was complex,
and it is believed to be little used or perhaps even completely unused.
While it had some use cases in database applications on 32-bit systems,
those use cases don't exist on 64-bit systems.
<P>
The
<B>remap_file_pages</B>()
system call is used to create a nonlinear mapping, that is, a mapping
in which the pages of the file are mapped into a nonsequential order
in memory.
The advantage of using
<B>remap_file_pages</B>()
over using repeated calls to
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2)
is that the former approach does not require the kernel to create
additional VMA (Virtual Memory Area) data structures.
<P>
To create a nonlinear mapping we perform the following steps:
<DL COMPACT>
<DT id="1">1.<DD>
Use
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2)
to create a mapping (which is initially linear).
This mapping must be created with the
<B>MAP_SHARED</B>
flag.
<DT id="2">2.<DD>
Use one or more calls to
<B>remap_file_pages</B>()
to rearrange the correspondence between the pages of the mapping
and the pages of the file.
It is possible to map the same page of a file
into multiple locations within the mapped region.
</DL>
<P>
The
<I>pgoff</I>
and
<I>size</I>
arguments specify the region of the file that is to be relocated
within the mapping:
<I>pgoff</I>
is a file offset in units of the system page size;
<I>size</I>
is the length of the region in bytes.
<P>
The
<I>addr</I>
argument serves two purposes.
First, it identifies the mapping whose pages we want to rearrange.
Thus,
<I>addr</I>
must be an address that falls within
a region previously mapped by a call to
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2).
Second,
<I>addr</I>
specifies the address at which the file pages
identified by
<I>pgoff</I>
and
<I>size</I>
will be placed.
<P>
The values specified in
<I>addr</I>
and
<I>size</I>
should be multiples of the system page size.
If they are not, then the kernel rounds
<I>both</I>
values
<I>down</I>
to the nearest multiple of the page size.
<P>
The
<I>prot</I>
argument must be specified as 0.
<P>
The
<I>flags</I>
argument has the same meaning as for
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2),
but all flags other than
<B>MAP_NONBLOCK</B>
are ignored.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
<B>remap_file_pages</B>()
returns 0.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="3"><B>EINVAL</B>
<DD>
<I>addr</I>
does not refer to a valid mapping
created with the
<B>MAP_SHARED</B>
flag.
<DT id="4"><B>EINVAL</B>
<DD>
<I>addr</I>,
<I>size</I>,
<I>prot</I>,
or
<I>pgoff</I>
is invalid.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
The
<B>remap_file_pages</B>()
system call appeared in Linux 2.5.46;
glibc support was added in version 2.3.3.
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
The
<B>remap_file_pages</B>()
system call is Linux-specific.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
Since Linux 2.6.23,
<B>remap_file_pages</B>()
creates non-linear mappings only
on in-memory filesystems such as
<B><A HREF="/cgi-bin/man/man2html?5+tmpfs">tmpfs</A></B>(5),
hugetlbfs or ramfs.
On filesystems with a backing store,
<B>remap_file_pages</B>()
is not much more efficient than using
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2)
to adjust which parts of the file are mapped to which addresses.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+getpagesize">getpagesize</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+mmap2">mmap2</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+mprotect">mprotect</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+mremap">mremap</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+msync">msync</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="5"><A HREF="#lbAB">NAME</A><DD>
<DT id="6"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="7"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="8"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="9"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="10"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="11"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="12"><A HREF="#lbAI">NOTES</A><DD>
<DT id="13"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="14"><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:34 GMT, March 31, 2021
</BODY>
</HTML>