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