18c2ecf20Sopenharmony_ci.. _remap_file_pages:
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci==============================
48c2ecf20Sopenharmony_ciremap_file_pages() system call
58c2ecf20Sopenharmony_ci==============================
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciThe remap_file_pages() system call is used to create a nonlinear mapping,
88c2ecf20Sopenharmony_cithat is, a mapping in which the pages of the file are mapped into a
98c2ecf20Sopenharmony_cinonsequential order in memory. The advantage of using remap_file_pages()
108c2ecf20Sopenharmony_ciover using repeated calls to mmap(2) is that the former approach does not
118c2ecf20Sopenharmony_cirequire the kernel to create additional VMA (Virtual Memory Area) data
128c2ecf20Sopenharmony_cistructures.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciSupporting of nonlinear mapping requires significant amount of non-trivial
158c2ecf20Sopenharmony_cicode in kernel virtual memory subsystem including hot paths. Also to get
168c2ecf20Sopenharmony_cinonlinear mapping work kernel need a way to distinguish normal page table
178c2ecf20Sopenharmony_cientries from entries with file offset (pte_file). Kernel reserves flag in
188c2ecf20Sopenharmony_ciPTE for this purpose. PTE flags are scarce resource especially on some CPU
198c2ecf20Sopenharmony_ciarchitectures. It would be nice to free up the flag for other usage.
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciFortunately, there are not many users of remap_file_pages() in the wild.
228c2ecf20Sopenharmony_ciIt's only known that one enterprise RDBMS implementation uses the syscall
238c2ecf20Sopenharmony_cion 32-bit systems to map files bigger than can linearly fit into 32-bit
248c2ecf20Sopenharmony_civirtual address space. This use-case is not critical anymore since 64-bit
258c2ecf20Sopenharmony_cisystems are widely available.
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciThe syscall is deprecated and replaced it with an emulation now. The
288c2ecf20Sopenharmony_ciemulation creates new VMAs instead of nonlinear mappings. It's going to
298c2ecf20Sopenharmony_ciwork slower for rare users of remap_file_pages() but ABI is preserved.
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciOne side effect of emulation (apart from performance) is that user can hit
328c2ecf20Sopenharmony_civm.max_map_count limit more easily due to additional VMAs. See comment for
338c2ecf20Sopenharmony_ciDEFAULT_MAX_MAP_COUNT for more details on the limit.
34