RFC mm/rmap: index MAP_PRIVATE file-backed folios by virt pgoff
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest10 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/10 | mm/vma: introduce VMA virtual page offset field and add helpersinclude/ include/ mm/ +2 more | +104 | 0 replies | |
| 2/10 | mm: introduce linear_virt_page_index()include/ include/ tools/ | +64 | 0 replies | |
| 3/10 | mm: abstract vma_address() and introduce vma_anon_address()mm/ | +37 | 0 replies | |
| 4/10 | mm: update print_bad_page_map() to show virtual page indexmm/ | +5 | 0 replies | |
| 5/10 | mm: introduce and use vma_filebacked_address()mm/ mm/ mm/ +1 more | +31 | 0 replies | |
| 6/10 | mm: propagate VMA virtual page offset on map, remap, split + mergemm/ mm/ mm/ +5 more | +152 | 0 replies | |
| 7/10 | mm/rmap: track whether the page VMA mapped walk is anonymousinclude/ mm/ mm/ | +13 | 0 replies | |
| 8/10 | mm: introduce and use linear_folio_page_index()include/ mm/ mm/ +1 more | +28 | 0 replies | |
| 9/10 | mm/rmap: use virt pgoff for MAP_PRIVATE file-backed anon foliosinclude/ mm/ mm/ +4 more | +37 | 0 replies | |
| 10/10 | tools/testing/vma: expand VMA merge tests to assert virt pgofftools/ | +18 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC PATCH 00/10] mm/rmap: index MAP_PRIVATE file-backed folios by virt pgoff
In memory management we've managed to manufacture a great deal of confusion around the concept of anonymous memory. We have:
1. 'Pure anon' memory - anonymous VMAs whose folios are anonymous and swap-backed (thus for reclaim purposes, treated as anonymous). These are simple enough.
2. shmem - file-backed VMAs, file-backed folios (from rmap perspective) so present in the page cache and mapped by an address_space object, but whose folios are also swap-backed (thus treated as anonymous for reclaim purposes).
3. MAP_PRIVATE-mapped /dev/zero - a strange beast whose VMAs have vma->vm_file set, but whose mmap_prepare callback clears vma->vm_ops to satisfy vma_is_anonymous(), which results in VMAs that were mmap()'d referencing a file and whose VMAs reference a file, but are in every other sense anonymous, including the folios.
4. Other MAP_PRIVATE-file backed mappings - These possess file-backed VMAs and have file-backed folios until CoW'd, at which point those CoW'd folios are anonymous.
This series focuses upon issue 4.
In order for us to traverse VMAs using the reverse mapping, we require two fields - folio->mapping and folio->index. The first tells the rmap code where to look for VMAs, and the second tells it at which offset the folio starts within the referenced object.
For anonymous folios, folio->mapping points at an anon_vma object. For file-backed folios, it points at an address_space. And:
* For file-backed folios folio->index is simply the page offset of the start of the folio within the file.
* For anonymous folios belonging to pure anon mappings, folio->index is equal to the virtual page offset of the folio.
* For anonymous folios belonging to file-backed mappings (i.e. CoW'd folios of a MAP_PRIVATE file-backed mapping), folio->index is equal to the file page offset.
This series establishes a new virtual page offset property of VMAs to allow us to map anonymous folios at their virtual page offset, consistent with pure anon.
The purpose of doing so is to lay the foundations for the scalable CoW work. This is necessary because firstly the approach first looks in the maple tree for the VMA located at folio->index << PAGE_SHIFT, before falling back to looking up tracked remaps if necessary.
The MAP_PRIVATE file-backed case means that folio indices will very often conflict with one another and this remap tracking becomes substantially more contended, and of course the fast path can never be used.
This also makes it possible, in future, to unshare anonymously mapped folios with deep fork hierarchies on remap, eliminating the need for remap tracking in the vast majority of cases.
Simlar to page offset of pure anonymous VMAs, we update the virtual page offset of unfaulted file-backed VMAs on remap, but do not once CoW'd (i.e. vma->anon_vma is non-NULL).
Overall, there is little impact on mergeability - for shared file-backed mappings, we treat the anonymous page offset as equal to the file-backed one (via vma_start_anon_pgoff()), so merge behaviour remains the same there.
The only impact is on MAP_PRIVATE-mapped file-backed mappings, which must now match on virtual page offset as well as file page offset to be merged.
To fail to merge like this would require CoW'ing the mapping then remapping in such a way as to eliminate compatibility, but this is very much an edge case that should very little impact (and which scalable CoW may very well address in any case).
REVIEWER/MERGER NOTE: This is dependent on [0], which must be merged before this.
[0]:https://lore.kernel.org/linux-mm/[email protected]/
Lorenzo Stoakes (10):
mm/vma: introduce VMA virtual page offset field and add helpers
mm: introduce linear_virt_page_index()
mm: abstract vma_address() and introduce vma_anon_address()
mm: update print_bad_page_map() to show virtual page index
mm: introduce and use vma_filebacked_address()
mm: propagate VMA virtual page offset on map, remap, split + merge mm/rmap: track whether the page VMA mapped walk is anonymous
mm: introduce and use linear_folio_page_index() mm/rmap: use virt pgoff for MAP_PRIVATE file-backed anon folios tools/testing/vma: expand VMA merge tests to assert virt pgoff
include/linux/mm.h | 61 ++++++++++++- include/linux/mm_types.h | 4 + include/linux/pagemap.h | 66 +++++++++++++++ include/linux/rmap.h | 2 + mm/huge_memory.c | 3 +- mm/internal.h | 69 +++++++++++---- mm/interval_tree.c | 4 +- mm/ksm.c | 2 +- mm/memory-failure.c | 4 +- mm/memory.c | 8 +- mm/migrate.c | 6 +- mm/mremap.c | 6 +- mm/page_vma_mapped.c | 6 +- mm/rmap.c | 23 +++-- mm/userfaultfd.c | 6 +- mm/vma.c | 70 +++++++++++---- mm/vma.h | 141 ++++++++++++++++++++++++------- mm/vma_exec.c | 2 +- mm/vma_init.c | 1 + tools/testing/vma/include/dup.h | 48 +++++++++++ tools/testing/vma/shared.c | 3 +- tools/testing/vma/tests/merge.c | 22 ++++- tools/testing/vma/tests/vma.c | 4 +- tools/testing/vma/vma_internal.h | 1 + 24 files changed, 468 insertions(+), 94 deletions(-)
--
2.54.0