]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/remap_file_pages.2
sched_setattr.2: tfix
[thirdparty/man-pages.git] / man2 / remap_file_pages.2
CommitLineData
616c2730 1.\" Copyright (C) 2003, Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
12.\"
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
10d76543
MK
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
fea681da
MK
20.\"
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da 24.\"
c11b1abf 25.\" 2003-12-10 Initial creation, Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
26.\" 2004-10-28 aeb, corrected prototype, prot must be 0
27.\"
4b8c67d9 28.TH REMAP_FILE_PAGES 2 2017-09-15 "Linux" "Linux Programmer's Manual"
fea681da 29.SH NAME
fb0e9c48 30remap_file_pages \- create a nonlinear file mapping
fea681da 31.SH SYNOPSIS
e743a184 32.nf
b80f966b 33.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
fea681da 34.B #include <sys/mman.h>
68e4db0a 35.PP
14f5ae6d 36.BI "int remap_file_pages(void *" addr ", size_t " size ", int " prot ,
aff9c307 37.BI " size_t " pgoff ", int " flags );
e743a184 38.fi
fea681da 39.SH DESCRIPTION
85c984a1
MK
40.BR Note :
41.\" commit 33041a0d76d3c3e0aff28ac95a2ffdedf1282dbc
42.\" http://lwn.net/Articles/597632/
94d76e41
MK
43this system call was marked as deprecated starting with Linux 3.16.
44In Linux 4.0, the implementation was replaced
45.\" commit c8d78c1823f46519473949d33f0d1d33fe21ea16
46by a slower in-kernel emulation.
85c984a1
MK
47Those few applications that use this system call should
48consider migrating to alternatives.
94d76e41
MK
49This change was made because the kernel code for this system call was complex,
50and it is believed to be little used or perhaps even completely unused.
51While it had some use cases in database applications on 32-bit systems,
52those use cases don't exist on 64-bit systems.
efeece04 53.PP
fea681da 54The
63aa9df0 55.BR remap_file_pages ()
fb0e9c48 56system call is used to create a nonlinear mapping, that is, a mapping
24b74457 57in which the pages of the file are mapped into a nonsequential order
fea681da
MK
58in memory.
59The advantage of using
63aa9df0 60.BR remap_file_pages ()
fea681da
MK
61over using repeated calls to
62.BR mmap (2)
63is that the former approach does not require the kernel to create
64additional VMA (Virtual Memory Area) data structures.
efeece04 65.PP
fb0e9c48 66To create a nonlinear mapping we perform the following steps:
218dfacd
MK
67.TP 3
681.
fea681da 69Use
0bfa087b 70.BR mmap (2)
fea681da
MK
71to create a mapping (which is initially linear).
72This mapping must be created with the
c13182ef 73.B MAP_SHARED
16fd68e1 74flag.
fea681da 75.TP
218dfacd 762.
fea681da 77Use one or more calls to
63aa9df0 78.BR remap_file_pages ()
fea681da
MK
79to rearrange the correspondence between the pages of the mapping
80and the pages of the file.
81It is possible to map the same page of a file
82into multiple locations within the mapped region.
dd3568a1 83.PP
fea681da
MK
84The
85.I pgoff
86and
87.I size
88arguments specify the region of the file that is to be relocated
89within the mapping:
90.I pgoff
91is a file offset in units of the system page size;
92.I size
93is the length of the region in bytes.
efeece04 94.PP
fea681da 95The
14f5ae6d 96.I addr
fea681da
MK
97argument serves two purposes.
98First, it identifies the mapping whose pages we want to rearrange.
99Thus,
14f5ae6d 100.I addr
fea681da
MK
101must be an address that falls within
102a region previously mapped by a call to
0bfa087b 103.BR mmap (2).
fea681da 104Second,
14f5ae6d 105.I addr
fea681da
MK
106specifies the address at which the file pages
107identified by
108.I pgoff
109and
110.I size
111will be placed.
efeece04 112.PP
22b6a68b 113The values specified in
14f5ae6d 114.I addr
22b6a68b
MK
115and
116.I size
117should be multiples of the system page size.
118If they are not, then the kernel rounds
c13182ef
MK
119.I both
120values
22b6a68b
MK
121.I down
122to the nearest multiple of the page size.
c13182ef
MK
123.\" This rounding is weird, and not consistent with the treatment of
124.\" the analogous arguments for munmap()/mprotect() and for mlock().
22b6a68b 125.\" MTK, 14 Sep 2005
efeece04 126.PP
fea681da
MK
127The
128.I prot
129argument must be specified as 0.
efeece04 130.PP
fea681da
MK
131The
132.I flags
133argument has the same meaning as for
0bfa087b 134.BR mmap (2),
c13182ef
MK
135but all flags other than
136.B MAP_NONBLOCK
16fd68e1 137are ignored.
47297adb 138.SH RETURN VALUE
fea681da 139On success,
63aa9df0 140.BR remap_file_pages ()
fea681da
MK
141returns 0.
142On error, \-1 is returned, and
143.I errno
144is set appropriately.
fea681da
MK
145.SH ERRORS
146.TP
147.B EINVAL
14f5ae6d 148.I addr
fea681da 149does not refer to a valid mapping
c13182ef
MK
150created with the
151.B MAP_SHARED
16fd68e1 152flag.
fea681da
MK
153.TP
154.B EINVAL
14f5ae6d 155.IR addr ,
fea681da
MK
156.IR size ,
157.IR prot ,
158or
159.I pgoff
160is invalid.
161.\" And possibly others from vma->vm_ops->populate()
a1d5f77c
MK
162.SH VERSIONS
163The
164.BR remap_file_pages ()
deec2da3
MK
165system call appeared in Linux 2.5.46;
166glibc support was added in version 2.3.3.
47297adb 167.SH CONFORMING TO
fea681da 168The
63aa9df0 169.BR remap_file_pages ()
8382f16d 170system call is Linux-specific.
8fd1fd30 171.SH NOTES
7a085379
MK
172Since Linux 2.6.23,
173.\" commit 3ee6dafc677a68e461a7ddafc94a580ebab80735
8fd1fd30 174.BR remap_file_pages ()
ea38fc5c 175creates non-linear mappings only
5991f44e 176on in-memory filesystems such as
4e07c70f
MK
177.BR tmpfs (5),
178hugetlbfs or ramfs.
76f26660
MK
179On filesystems with a backing store,
180.BR remap_file_pages ()
181is not much more efficient than using
8fd1fd30 182.BR mmap (2)
76f26660 183to adjust which parts of the file are mapped to which addresses.
47297adb 184.SH SEE ALSO
fea681da
MK
185.BR getpagesize (2),
186.BR mmap (2),
187.BR mmap2 (2),
188.BR mprotect (2),
189.BR mremap (2),
0a4f8b7b 190.BR msync (2)