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