OSDN Git Service

LDP: Update original to LDP v3.78
[linuxjm/LDP_man-pages.git] / original / 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 2014-05-28 "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 .sp
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 is (since Linux 3.16) deprecated and will
44 eventually be replaced by a slower in-kernel emulation.
45 Those few applications that use this system call should
46 consider migrating to alternatives.
47
48 The
49 .BR remap_file_pages ()
50 system call is used to create a nonlinear mapping, that is, a mapping
51 in which the pages of the file are mapped into a nonsequential order
52 in memory.
53 The advantage of using
54 .BR remap_file_pages ()
55 over using repeated calls to
56 .BR mmap (2)
57 is that the former approach does not require the kernel to create
58 additional VMA (Virtual Memory Area) data structures.
59
60 To create a nonlinear mapping we perform the following steps:
61 .TP 3
62 1.
63 Use
64 .BR mmap (2)
65 to create a mapping (which is initially linear).
66 This mapping must be created with the
67 .B MAP_SHARED
68 flag.
69 .TP
70 2.
71 Use one or more calls to
72 .BR remap_file_pages ()
73 to rearrange the correspondence between the pages of the mapping
74 and the pages of the file.
75 It is possible to map the same page of a file
76 into multiple locations within the mapped region.
77 .LP
78 The
79 .I pgoff
80 and
81 .I size
82 arguments specify the region of the file that is to be relocated
83 within the mapping:
84 .I pgoff
85 is a file offset in units of the system page size;
86 .I size
87 is the length of the region in bytes.
88
89 The
90 .I addr
91 argument serves two purposes.
92 First, it identifies the mapping whose pages we want to rearrange.
93 Thus,
94 .I addr
95 must be an address that falls within
96 a region previously mapped by a call to
97 .BR mmap (2).
98 Second,
99 .I addr
100 specifies the address at which the file pages
101 identified by
102 .I pgoff
103 and
104 .I size
105 will be placed.
106
107 The values specified in
108 .I addr
109 and
110 .I size
111 should be multiples of the system page size.
112 If they are not, then the kernel rounds
113 .I both
114 values
115 .I down
116 to the nearest multiple of the page size.
117 .\" This rounding is weird, and not consistent with the treatment of
118 .\" the analogous arguments for munmap()/mprotect() and for mlock().
119 .\" MTK, 14 Sep 2005
120
121 The
122 .I prot
123 argument must be specified as 0.
124
125 The
126 .I flags
127 argument has the same meaning as for
128 .BR mmap (2),
129 but all flags other than
130 .B MAP_NONBLOCK
131 are ignored.
132 .SH RETURN VALUE
133 On success,
134 .BR remap_file_pages ()
135 returns 0.
136 On error, \-1 is returned, and
137 .I errno
138 is set appropriately.
139 .SH ERRORS
140 .TP
141 .B EINVAL
142 .I addr
143 does not refer to a valid mapping
144 created with the
145 .B MAP_SHARED
146 flag.
147 .TP
148 .B EINVAL
149 .IR addr ,
150 .IR size ,
151 .IR prot ,
152 or
153 .I pgoff
154 is invalid.
155 .\" And possibly others from vma->vm_ops->populate()
156 .SH VERSIONS
157 The
158 .BR remap_file_pages ()
159 system call appeared in Linux 2.5.46;
160 glibc support was added in version 2.3.3.
161 .SH CONFORMING TO
162 The
163 .BR remap_file_pages ()
164 system call is Linux-specific.
165 .SH NOTES
166 Since Linux 2.6.23,
167 .\" commit 3ee6dafc677a68e461a7ddafc94a580ebab80735
168 .BR remap_file_pages ()
169 creates non-linear mappings only
170 on in-memory file systems such as tmpfs, hugetlbfs or ramfs.
171 On filesystems with a backing store,
172 .BR remap_file_pages ()
173 is not much more efficient than using
174 .BR mmap (2)
175 to adjust which parts of the file are mapped to which addresses.
176 .SH SEE ALSO
177 .BR getpagesize (2),
178 .BR mmap (2),
179 .BR mmap2 (2),
180 .BR mprotect (2),
181 .BR mremap (2),
182 .BR msync (2)
183 .SH COLOPHON
184 This page is part of release 3.78 of the Linux
185 .I man-pages
186 project.
187 A description of the project,
188 information about reporting bugs,
189 and the latest version of this page,
190 can be found at
191 \%http://www.kernel.org/doc/man\-pages/.