OSDN Git Service

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