1remap_file_pages(2)           System Calls Manual          remap_file_pages(2)
2
3
4

NAME

6       remap_file_pages - create a nonlinear file mapping
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #define _GNU_SOURCE         /* See feature_test_macros(7) */
13       #include <sys/mman.h>
14
15       [[deprecated]] int remap_file_pages(void addr[.size], size_t size,
16                                           int prot, size_t pgoff, int flags);
17

DESCRIPTION

19       Note:  this  system  call  was marked as deprecated starting with Linux
20       3.16.  In Linux 4.0, the implementation was replaced by  a  slower  in-
21       kernel  emulation.   Those  few  applications that use this system call
22       should consider migrating to alternatives.  This change  was  made  be‐
23       cause  the  kernel code for this system call was complex, and it is be‐
24       lieved to be little used or perhaps even completely unused.   While  it
25       had  some  use  cases in database applications on 32-bit systems, those
26       use cases don't exist on 64-bit systems.
27
28       The remap_file_pages() system call is used to create a  nonlinear  map‐
29       ping, that is, a mapping in which the pages of the file are mapped into
30       a  nonsequential   order   in   memory.    The   advantage   of   using
31       remap_file_pages()  over  using  repeated  calls to mmap(2) is that the
32       former approach does not require the kernel to  create  additional  VMA
33       (Virtual Memory Area) data structures.
34
35       To create a nonlinear mapping we perform the following steps:
36
37       1. Use  mmap(2)  to create a mapping (which is initially linear).  This
38          mapping must be created with the MAP_SHARED flag.
39
40       2. Use one or more calls to remap_file_pages() to rearrange the  corre‐
41          spondence  between  the  pages  of  the mapping and the pages of the
42          file.  It is possible to map the same page of a file  into  multiple
43          locations within the mapped region.
44
45       The  pgoff and size arguments specify the region of the file that is to
46       be relocated within the mapping: pgoff is a file offset in units of the
47       system page size; size is the length of the region in bytes.
48
49       The  addr  argument serves two purposes.  First, it identifies the map‐
50       ping whose pages we want to rearrange.  Thus, addr must be  an  address
51       that  falls  within  a  region  previously mapped by a call to mmap(2).
52       Second, addr specifies the address at which the file  pages  identified
53       by pgoff and size will be placed.
54
55       The values specified in addr and size should be multiples of the system
56       page size.  If they are not, then the kernel rounds both values down to
57       the nearest multiple of the page size.
58
59       The prot argument must be specified as 0.
60
61       The  flags  argument has the same meaning as for mmap(2), but all flags
62       other than MAP_NONBLOCK are ignored.
63

RETURN VALUE

65       On success, remap_file_pages() returns 0.  On error,  -1  is  returned,
66       and errno is set to indicate the error.
67

ERRORS

69       EINVAL addr  does  not  refer  to  a  valid  mapping  created  with the
70              MAP_SHARED flag.
71
72       EINVAL addr, size, prot, or pgoff is invalid.
73

STANDARDS

75       Linux.
76

HISTORY

78       Linux 2.5.46, glibc 2.3.3.
79

NOTES

81       Since Linux 2.6.23, remap_file_pages() creates non-linear mappings only
82       on  in-memory  filesystems  such  as  tmpfs(5), hugetlbfs or ramfs.  On
83       filesystems with a backing store, remap_file_pages() is not  much  more
84       efficient  than  using  mmap(2)  to  adjust which parts of the file are
85       mapped to which addresses.
86

SEE ALSO

88       getpagesize(2), mmap(2), mmap2(2), mprotect(2), mremap(2), msync(2)
89
90
91
92Linux man-pages 6.05              2023-03-30               remap_file_pages(2)
Impressum