Blame man2/remap_file_pages.2

Packit 7cfc04
.\" Copyright (C) 2003, Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" 2003-12-10 Initial creation, Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\" 2004-10-28 aeb, corrected prototype, prot must be 0
Packit 7cfc04
.\"
Packit 7cfc04
.TH REMAP_FILE_PAGES 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
remap_file_pages \- create a nonlinear file mapping
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
Packit 7cfc04
.B #include <sys/mman.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int remap_file_pages(void *" addr ", size_t " size ", int " prot ,
Packit 7cfc04
.BI "                     size_t " pgoff ", int " flags );
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR Note :
Packit 7cfc04
.\" commit 33041a0d76d3c3e0aff28ac95a2ffdedf1282dbc
Packit 7cfc04
.\" http://lwn.net/Articles/597632/
Packit 7cfc04
this system call was marked as deprecated starting with Linux 3.16.
Packit 7cfc04
In Linux 4.0, the implementation was replaced
Packit 7cfc04
.\" commit c8d78c1823f46519473949d33f0d1d33fe21ea16
Packit 7cfc04
by a slower in-kernel emulation.
Packit 7cfc04
Those few applications that use this system call should
Packit 7cfc04
consider migrating to alternatives.
Packit 7cfc04
This change was made because the kernel code for this system call was complex,
Packit 7cfc04
and it is believed to be little used or perhaps even completely unused.
Packit 7cfc04
While it had some use cases in database applications on 32-bit systems,
Packit 7cfc04
those use cases don't exist on 64-bit systems.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR remap_file_pages ()
Packit 7cfc04
system call is used to create a nonlinear mapping, that is, a mapping
Packit 7cfc04
in which the pages of the file are mapped into a nonsequential order
Packit 7cfc04
in memory.
Packit 7cfc04
The advantage of using
Packit 7cfc04
.BR remap_file_pages ()
Packit 7cfc04
over using repeated calls to
Packit 7cfc04
.BR mmap (2)
Packit 7cfc04
is that the former approach does not require the kernel to create
Packit 7cfc04
additional VMA (Virtual Memory Area) data structures.
Packit 7cfc04
.PP
Packit 7cfc04
To create a nonlinear mapping we perform the following steps:
Packit 7cfc04
.TP 3
Packit 7cfc04
1.
Packit 7cfc04
Use
Packit 7cfc04
.BR mmap (2)
Packit 7cfc04
to create a mapping (which is initially linear).
Packit 7cfc04
This mapping must be created with the
Packit 7cfc04
.B MAP_SHARED
Packit 7cfc04
flag.
Packit 7cfc04
.TP
Packit 7cfc04
2.
Packit 7cfc04
Use one or more calls to
Packit 7cfc04
.BR remap_file_pages ()
Packit 7cfc04
to rearrange the correspondence between the pages of the mapping
Packit 7cfc04
and the pages of the file.
Packit 7cfc04
It is possible to map the same page of a file
Packit 7cfc04
into multiple locations within the mapped region.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I pgoff
Packit 7cfc04
and
Packit 7cfc04
.I size
Packit 7cfc04
arguments specify the region of the file that is to be relocated
Packit 7cfc04
within the mapping:
Packit 7cfc04
.I pgoff
Packit 7cfc04
is a file offset in units of the system page size;
Packit 7cfc04
.I size
Packit 7cfc04
is the length of the region in bytes.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I addr
Packit 7cfc04
argument serves two purposes.
Packit 7cfc04
First, it identifies the mapping whose pages we want to rearrange.
Packit 7cfc04
Thus,
Packit 7cfc04
.I addr
Packit 7cfc04
must be an address that falls within
Packit 7cfc04
a region previously mapped by a call to
Packit 7cfc04
.BR mmap (2).
Packit 7cfc04
Second,
Packit 7cfc04
.I addr
Packit 7cfc04
specifies the address at which the file pages
Packit 7cfc04
identified by
Packit 7cfc04
.I pgoff
Packit 7cfc04
and
Packit 7cfc04
.I size
Packit 7cfc04
will be placed.
Packit 7cfc04
.PP
Packit 7cfc04
The values specified in
Packit 7cfc04
.I addr
Packit 7cfc04
and
Packit 7cfc04
.I size
Packit 7cfc04
should be multiples of the system page size.
Packit 7cfc04
If they are not, then the kernel rounds
Packit 7cfc04
.I both
Packit 7cfc04
values
Packit 7cfc04
.I down
Packit 7cfc04
to the nearest multiple of the page size.
Packit 7cfc04
.\" This rounding is weird, and not consistent with the treatment of
Packit 7cfc04
.\" the analogous arguments for munmap()/mprotect() and for mlock().
Packit 7cfc04
.\" MTK, 14 Sep 2005
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I prot
Packit 7cfc04
argument must be specified as 0.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I flags
Packit 7cfc04
argument has the same meaning as for
Packit 7cfc04
.BR mmap (2),
Packit 7cfc04
but all flags other than
Packit 7cfc04
.B MAP_NONBLOCK
Packit 7cfc04
are ignored.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success,
Packit 7cfc04
.BR remap_file_pages ()
Packit 7cfc04
returns 0.
Packit 7cfc04
On error, \-1 is returned, and
Packit 7cfc04
.I errno
Packit 7cfc04
is set appropriately.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.I addr
Packit 7cfc04
does not refer to a valid mapping
Packit 7cfc04
created with the
Packit 7cfc04
.B MAP_SHARED
Packit 7cfc04
flag.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.IR addr ,
Packit 7cfc04
.IR size ,
Packit 7cfc04
.IR prot ,
Packit 7cfc04
or
Packit 7cfc04
.I pgoff
Packit 7cfc04
is invalid.
Packit 7cfc04
.\" And possibly others from vma->vm_ops->populate()
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
The
Packit 7cfc04
.BR remap_file_pages ()
Packit 7cfc04
system call appeared in Linux 2.5.46;
Packit 7cfc04
glibc support was added in version 2.3.3.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
The
Packit 7cfc04
.BR remap_file_pages ()
Packit 7cfc04
system call is Linux-specific.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Since Linux 2.6.23,
Packit 7cfc04
.\" commit 3ee6dafc677a68e461a7ddafc94a580ebab80735
Packit 7cfc04
.BR remap_file_pages ()
Packit 7cfc04
creates non-linear mappings only
Packit 7cfc04
on in-memory filesystems such as
Packit 7cfc04
.BR tmpfs (5),
Packit 7cfc04
hugetlbfs or ramfs.
Packit 7cfc04
On filesystems with a backing store,
Packit 7cfc04
.BR remap_file_pages ()
Packit 7cfc04
is not much more efficient than using
Packit 7cfc04
.BR mmap (2)
Packit 7cfc04
to adjust which parts of the file are mapped to which addresses.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR getpagesize (2),
Packit 7cfc04
.BR mmap (2),
Packit 7cfc04
.BR mmap2 (2),
Packit 7cfc04
.BR mprotect (2),
Packit 7cfc04
.BR mremap (2),
Packit 7cfc04
.BR msync (2)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.