remap_file_pages(2)
π remap_file_pages β create a nonlinear file mapping π
okay bestie, sit down, we gotta talk. this one's a remap_file_pages(2) situation and it's giving legacy, it's giving please migrate, it's giving the kernel said no more. π«Ά
πΈ NAME πΈ
remap_file_pages β create a nonlinear file mapping
π LIBRARY π
Standard C library (libc, -lc)
β¨ SYNOPSIS β¨
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <sys/mman.h>
[[deprecated]] int remap_file_pages(size_t size;
void addr[size], size_t size,
int prot, size_t pgoff, int flags);
π DESCRIPTION π
π¨ bestie listen. this syscall got marked deprecated starting with Linux 3.16. and then in Linux 4.0 the actual implementation got replaced by a slower in-kernel emulation. not a glow-up, a glow-down. π
Those few applications that use this system call should consider migrating to alternatives, fr fr. Why did this happen? Because the kernel code for this system call was complex, and it is believed to be little used or perhaps even completely unused. π It did have some use cases in database applications on 32-bit systems, but those use cases don't exist on 64-bit systems. so likeβ¦ okay. periodt.
So what is remap_file_pages()? The tea is: it's used to create a nonlinear mapping, that is, a mapping in which the pages of the file are mapped into a nonsequential order in memory. π Chaos mapping. The pages said "we're not doing sequential today."
The advantage of using remap_file_pages() over using repeated calls to mmap(2) is that the former approach does not require the kernel to create additional VMA (Virtual Memory Area) data structures. So it's the low-effort route for the kernel. slay efficiency, kinda.
To create a nonlinear mapping we perform the following steps:
- Use
mmap(2)to create a mapping (which is initially linear). This mapping must be created with theMAP_SHAREDflag. β - Use one or more calls to
remap_file_pages()to rearrange the correspondence between the pages of the mapping and the pages of the file. It is possible to map the same page of a file into multiple locations within the mapped region. π iconic behaviour honestly.
The pgoff and size arguments specify the region of the file that is to be relocated within the mapping: pgoff is a file offset in units of the system page size; size is the length of the region in bytes.
The addr argument serves two purposes. First, it identifies the mapping whose pages we want to rearrange. Thus, addr must be an address that falls within a region previously mapped by a call to mmap(2). Second, addr specifies the address at which the file pages identified by pgoff and size will be placed. two jobs, one argument, main character energy π
The values specified in addr and size should be multiples of the system page size. If they are not, then the kernel rounds both values down to the nearest multiple of the page size. (yes bestie, it just rounds down. no warning, no drama, just math. π)
The prot argument must be specified as 0. That's it. Zero. Nothing else. Don't get creative.
The flags argument has the same meaning as for mmap(2), but all flags other than MAP_NONBLOCK are ignored. so basically only MAP_NONBLOCK matters here, everything else gets ghosted. π»
π RETURN VALUE π
On success, remap_file_pages() returns 0. π₯³
On error, -1 is returned, and errno is set to indicate the error. π
π ERRORS π
EINVALβaddrdoes not refer to a valid mapping created with theMAP_SHAREDflag.EINVALβaddr,size,prot, orpgoffis invalid.
(yes, both of them are EINVAL. iconic of it to double up. π)
β STANDARDS β
Linux.
π¦ HISTORY π¦
Linux 2.5.46, glibc 2.3.3. β¨ a vintage, an antique, a relic π
π NOTES π
Since Linux 2.6.23, remap_file_pages() creates non-linear mappings only on in-memory filesystems such as tmpfs(5), hugetlbfs or ramfs. π§ If you're on a filesystem with a backing store, remap_file_pages() is not much more efficient than using mmap(2) to adjust which parts of the file are mapped to which addresses. So likeβ¦ literally just use mmap(2) at that point bestie, no cap.
π₯ SEE ALSO π₯
getpagesize(2), mmap(2), mmap2(2), mprotect(2), mremap(2), msync(2)
and that's the whole page, bestie!! πΈπ this one came from Linux man-pages 6.20, dated 2026-02-08, and honestly it ate. now go use mmap(2) like a good citizen π«Άβ¨π
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2003, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms