linux-next: manual merge of the folio tree with the maple tree

From: broonie
Date: Wed Feb 23 2022 - 18:50:13 EST


Hi all,

Today's linux-next merge of the folio tree got a conflict in:

mm/internal.h

between commits:

37f4270132af3 ("mm: Start tracking VMAs with maple tree")
b3d7ba3cdf23c ("mm: Remove the vma linked list")

from the maple tree and commit:

522387590ac22 ("mm: Turn page_anon_vma() into folio_anon_vma()")

from the folio tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging. You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

diff --cc mm/internal.h
index 2d3ede05cd7bf,0e95bc2130c4d..0000000000000
--- a/mm/internal.h
+++ b/mm/internal.h
@@@ -66,17 -67,12 +67,13 @@@ static inline void wake_throttle_isolat
vm_fault_t do_swap_page(struct vm_fault *vmf);
void folio_rotate_reclaimable(struct folio *folio);
bool __folio_end_writeback(struct folio *folio);
+ void deactivate_file_folio(struct folio *folio);

-void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
- unsigned long floor, unsigned long ceiling);
+void free_pgtables(struct mmu_gather *tlb, struct maple_tree *mt,
+ struct vm_area_struct *start_vma, unsigned long floor,
+ unsigned long ceiling);
void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte);

- static inline bool can_madv_lru_vma(struct vm_area_struct *vma)
- {
- return !(vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP));
- }
-
struct zap_details;
void unmap_page_range(struct mmu_gather *tlb,
struct vm_area_struct *vma,
@@@ -387,76 -388,12 +389,79 @@@ static inline bool is_data_mapping(vm_f
return (flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE;
}

+/* Maple tree operations using VMAs */
+/*
+ * vma_mas_store() - Store a VMA in the maple tree.
+ * @vma: The vm_area_struct
+ * @mas: The maple state
+ *
+ * Efficient way to store a VMA in the maple tree when the @mas has already
+ * walked to the correct location.
+ *
+ * Note: the end address is inclusive in the maple tree.
+ */
+static inline int vma_mas_store(struct vm_area_struct *vma, struct ma_state *mas)
+{
+#ifdef CONFIG_DEBUG_VM_MAPLE_TREE
+ /* Make sure no VMAs are about to be lost. */
+ MA_STATE(test, mas->tree, vma->vm_start, vma->vm_end - 1);
+ struct vm_area_struct *vma_mas;
+ int count = 0;
+
+ mas_for_each(&test, vma_mas, vma->vm_end - 1) {
+ /* Rule out vma_expand */
+ if ((vma->vm_start != vma_mas->vm_start) &&
+ (vma->vm_end != vma_mas->vm_end))
+ count++;
+ }
+
+ /* vma adjust may overwrite a partial entry or remove one */
+ BUG_ON(count > 1);
+
+ BUG_ON(mas->min > vma->vm_start);
+ BUG_ON(mas->index > vma->vm_start);
+#endif
+ mas->index = vma->vm_start;
+ mas->last = vma->vm_end - 1;
+ return mas_store_gfp(mas, vma, GFP_KERNEL);
+}
+
+/*
+ * vma_mas_remove() - Remove a VMA from the maple tree.
+ * @vma: The vm_area_struct
+ * @mas: The maple state
+ *
+ * Efficient way to remove a VMA from the maple tree when the @mas has already
+ * been established and points to the correct location.
+ * Note: the end address is inclusive in the maple tree.
+ */
+static inline int vma_mas_remove(struct vm_area_struct *vma, struct ma_state *mas)
+{
+ int ret;
+
+#ifdef CONFIG_DEBUG_VM_MAPLE_TREE
+ /* Make sure no VMAs are about to be lost. */
+ MA_STATE(test, mas->tree, vma->vm_start, vma->vm_end - 1);
+ struct vm_area_struct *vma_mas;
+ int count = 0;
+
+ mas_for_each(&test, vma_mas, vma->vm_end - 1)
+ count++;
+
+ BUG_ON(count != 1);
+
+ BUG_ON(mas->min > vma->vm_start);
+ BUG_ON(mas->min > mas->index);
+#endif
+ mas->index = vma->vm_start;
+ mas->last = vma->vm_end - 1;
+ ret = mas_store_gfp(mas, NULL, GFP_KERNEL);
+ return ret;
+}
+
+ /* mm/util.c */
-void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
- struct vm_area_struct *prev);
-void __vma_unlink_list(struct mm_struct *mm, struct vm_area_struct *vma);
+ struct anon_vma *folio_anon_vma(struct folio *folio);
+
#ifdef CONFIG_MMU
void unmap_mapping_folio(struct folio *folio);
extern long populate_vma_page_range(struct vm_area_struct *vma,