xref: /OK3568_Linux_fs/kernel/Documentation/vm/remap_file_pages.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. _remap_file_pages:
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun==============================
4*4882a593Smuzhiyunremap_file_pages() system call
5*4882a593Smuzhiyun==============================
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunThe remap_file_pages() system call is used to create a nonlinear mapping,
8*4882a593Smuzhiyunthat is, a mapping in which the pages of the file are mapped into a
9*4882a593Smuzhiyunnonsequential order in memory. The advantage of using remap_file_pages()
10*4882a593Smuzhiyunover using repeated calls to mmap(2) is that the former approach does not
11*4882a593Smuzhiyunrequire the kernel to create additional VMA (Virtual Memory Area) data
12*4882a593Smuzhiyunstructures.
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunSupporting of nonlinear mapping requires significant amount of non-trivial
15*4882a593Smuzhiyuncode in kernel virtual memory subsystem including hot paths. Also to get
16*4882a593Smuzhiyunnonlinear mapping work kernel need a way to distinguish normal page table
17*4882a593Smuzhiyunentries from entries with file offset (pte_file). Kernel reserves flag in
18*4882a593SmuzhiyunPTE for this purpose. PTE flags are scarce resource especially on some CPU
19*4882a593Smuzhiyunarchitectures. It would be nice to free up the flag for other usage.
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunFortunately, there are not many users of remap_file_pages() in the wild.
22*4882a593SmuzhiyunIt's only known that one enterprise RDBMS implementation uses the syscall
23*4882a593Smuzhiyunon 32-bit systems to map files bigger than can linearly fit into 32-bit
24*4882a593Smuzhiyunvirtual address space. This use-case is not critical anymore since 64-bit
25*4882a593Smuzhiyunsystems are widely available.
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunThe syscall is deprecated and replaced it with an emulation now. The
28*4882a593Smuzhiyunemulation creates new VMAs instead of nonlinear mappings. It's going to
29*4882a593Smuzhiyunwork slower for rare users of remap_file_pages() but ABI is preserved.
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunOne side effect of emulation (apart from performance) is that user can hit
32*4882a593Smuzhiyunvm.max_map_count limit more easily due to additional VMAs. See comment for
33*4882a593SmuzhiyunDEFAULT_MAX_MAP_COUNT for more details on the limit.
34