linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* linux-next: manual merge of the folio tree with the maple tree
@ 2022-02-17  6:44 Stephen Rothwell
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Rothwell @ 2022-02-17  6:44 UTC (permalink / raw)
  To: Matthew Wilcox, Liam Howlett
  Cc: Hugh Dickins, Linux Kernel Mailing List, Linux Next Mailing List

[-- Attachment #1: Type: text/plain, Size: 1178 bytes --]

Hi all,

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

  mm/oom_kill.c

between commit:

  4a9727878b42 ("mm/oom_kill: Use maple tree iterators instead of vma linked list")

from the maple tree and commit:

  ad56e23dec9a ("mm/munlock: delete munlock_vma_pages_all(), allow oomreap")

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.

-- 
Cheers,
Stephen Rothwell

diff --cc mm/oom_kill.c
index 9cbc05fa356c,6b875acabd1e..000000000000
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@@ -526,8 -525,8 +526,8 @@@ bool __oom_reap_task_mm(struct mm_struc
  	 */
  	set_bit(MMF_UNSTABLE, &mm->flags);
  
 -	for (vma = mm->mmap ; vma; vma = vma->vm_next) {
 +	for_each_vma(vmi, vma) {
- 		if (!can_madv_lru_vma(vma))
+ 		if (vma->vm_flags & (VM_HUGETLB|VM_PFNMAP))
  			continue;
  
  		/*

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: linux-next: manual merge of the folio tree with the maple tree
  2022-02-24  1:16 broonie
@ 2022-02-24  2:02 ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2022-02-24  2:02 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Hugh Dickins, Liam R . Howlett, Linux Kernel Mailing List,
	Linux Next Mailing List

[-- Attachment #1: Type: text/plain, Size: 6163 bytes --]

On Thu, Feb 24, 2022 at 01:16:53AM +0000, broonie@kernel.org wrote:

> I have absolutely no confindence in this resolution.

Pretty sure that the resolution is bogus and I've broken boot (at least
from some quick testing).  Not confirmed that this merge is the cause
though, I'll take a closer look tomorrow.  Any help from someone who's
looked at this code before would be much appreciated.

> diff --cc mm/mmap.c
> index 1b3600152f6f5,64b5985b5295c..0000000000000
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@@ -2286,32 -2780,38 +2286,37 @@@ int split_vma(struct mm_struct *mm, str
>   	return __split_vma(mm, vma, addr, new_below);
>   }
>   
>  -/* Munmap is split into 2 main parts -- this part which finds
>  +/*
>  + * do_mas_align_munmap() - munmap the aligned region from @start to @end.
>  + * @mas: The maple_state, ideally set up to alter the correct tree location.
>  + * @vma: The starting vm_area_struct
>  + * @mm: The mm_struct
>  + * @start: The aligned start address to munmap.
>  + * @end: The aligned end address to munmap.
>  + * @uf: The userfaultfd list_head
>  + * @downgrade: Set to true to attempt a write downgrade of the mmap_sem
>  + *
>  + * If @downgrade is true, check return code for potential release of the lock.
> ++ *
> ++ * Munmap is split into 2 main parts -- this part which finds
> +  * what needs doing, and the areas themselves, which do the
> +  * work.  This now handles partial unmappings.
> +  * Jeremy Fitzhardinge <jeremy@goop.org>
>    */
>  -int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len,
>  -		struct list_head *uf, bool downgrade)
>  -{
>  -	unsigned long end;
>  -	struct vm_area_struct *vma, *prev, *last;
>  -
>  -	if ((offset_in_page(start)) || start > TASK_SIZE || len > TASK_SIZE-start)
>  -		return -EINVAL;
>  -
>  -	len = PAGE_ALIGN(len);
>  -	end = start + len;
>  -	if (len == 0)
>  -		return -EINVAL;
>  -
>  -	/*
>  -	 * arch_unmap() might do unmaps itself.  It must be called
>  -	 * and finish any rbtree manipulation before this code
>  -	 * runs and also starts to manipulate the rbtree.
>  -	 */
>  -	arch_unmap(mm, start, end);
>  -
>  -	/* Find the first overlapping VMA where start < vma->vm_end */
>  -	vma = find_vma_intersection(mm, start, end);
>  -	if (!vma)
>  -		return 0;
>  -	prev = vma->vm_prev;
>  -
>  +static int
>  +do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
>  +		    struct mm_struct *mm, unsigned long start,
>  +		    unsigned long end, struct list_head *uf, bool downgrade)
>  +{
>  +	struct vm_area_struct *prev, *next;
>  +	struct maple_tree mt_detach;
>  +	int count = 0;
>  +	MA_STATE(mas_detach, &mt_detach, start, end - 1);
>  +	mt_init_flags(&mt_detach, MM_MT_FLAGS);
>  +	mt_set_external_lock(&mt_detach, &mm->mmap_lock);
>  +
>  +	mas->last = end - 1;
>  +	prev = next = NULL;
>   	/*
>   	 * If we need to split any vma, do it now to save pain later.
>   	 *
> @@@ -3107,13 -3127,8 +3112,12 @@@ void exit_mmap(struct mm_struct *mm
>   		 * Nothing can be holding mm->mmap_lock here and the above call
>   		 * to mmu_notifier_release(mm) ensures mmu notifier callbacks in
>   		 * __oom_reap_task_mm() will not block.
>  +		 *
>  +		 * This needs to be done before unlocking the VMAs in the loop
>  +		 * below which clears VM_LOCKED, otherwise the oom reaper cannot
>  +		 * reliably test it.
>   		 */
>   		(void)__oom_reap_task_mm(mm);
> - 
>   		set_bit(MMF_OOM_SKIP, &mm->flags);
>   	}
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 2ddf1caf90488..d469555df0a21 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2373,10 +2373,8 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
>  		BUG_ON(next->vm_start > end);
>  #endif
>  		vma_mas_store(next, &mas_detach);
> -		if (next->vm_flags & VM_LOCKED) {
> +		if (next->vm_flags & VM_LOCKED)
>  			mm->locked_vm -= vma_pages(next);
> -			munlock_vma_pages_all(next);
> -		}
>  	}
>  
>  	next = mas_find(mas, ULONG_MAX);
> @@ -2906,10 +2904,8 @@ static int do_brk_munmap(struct ma_state *mas, struct vm_area_struct *vma,
>  	}
>  
>  	unmap_pages = vma_pages(&unmap);
> -	if (vma->vm_flags & VM_LOCKED) {
> +	if (vma->vm_flags & VM_LOCKED)
>  		mm->locked_vm -= unmap_pages;
> -		munlock_vma_pages_range(&unmap, newbrk, oldbrk);
> -	}
>  
>  	next = mas_next(mas, ULONG_MAX);
>  	mmap_write_downgrade(mm);
> @@ -3130,10 +3126,8 @@ void exit_mmap(struct mm_struct *mm)
>  	rwsem_acquire(&mm->mmap_lock.dep_map, 0, 0, _THIS_IP_);
>  	if (mm->locked_vm) {
>  		mas_for_each(&mas, vma, ULONG_MAX) {
> -			if (vma->vm_flags & VM_LOCKED) {
> +			if (vma->vm_flags & VM_LOCKED)
>  				mm->locked_vm -= vma_pages(vma);
> -				munlock_vma_pages_all(vma);
> -			}
>  		}
>  		mas_set(&mas, 0);
>  	}
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 2ddf1caf90488..d469555df0a21 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2373,10 +2373,8 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
>  		BUG_ON(next->vm_start > end);
>  #endif
>  		vma_mas_store(next, &mas_detach);
> -		if (next->vm_flags & VM_LOCKED) {
> +		if (next->vm_flags & VM_LOCKED)
>  			mm->locked_vm -= vma_pages(next);
> -			munlock_vma_pages_all(next);
> -		}
>  	}
>  
>  	next = mas_find(mas, ULONG_MAX);
> @@ -2906,10 +2904,8 @@ static int do_brk_munmap(struct ma_state *mas, struct vm_area_struct *vma,
>  	}
>  
>  	unmap_pages = vma_pages(&unmap);
> -	if (vma->vm_flags & VM_LOCKED) {
> +	if (vma->vm_flags & VM_LOCKED)
>  		mm->locked_vm -= unmap_pages;
> -		munlock_vma_pages_range(&unmap, newbrk, oldbrk);
> -	}
>  
>  	next = mas_next(mas, ULONG_MAX);
>  	mmap_write_downgrade(mm);
> @@ -3130,10 +3126,8 @@ void exit_mmap(struct mm_struct *mm)
>  	rwsem_acquire(&mm->mmap_lock.dep_map, 0, 0, _THIS_IP_);
>  	if (mm->locked_vm) {
>  		mas_for_each(&mas, vma, ULONG_MAX) {
> -			if (vma->vm_flags & VM_LOCKED) {
> +			if (vma->vm_flags & VM_LOCKED)
>  				mm->locked_vm -= vma_pages(vma);
> -				munlock_vma_pages_all(vma);
> -			}
>  		}
>  		mas_set(&mas, 0);
>  	}

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* linux-next: manual merge of the folio tree with the maple tree
@ 2022-02-24  1:16 broonie
  2022-02-24  2:02 ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: broonie @ 2022-02-24  1:16 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Hugh Dickins, Liam R . Howlett, Liam R . Howlett,
	Linux Kernel Mailing List, Linux Next Mailing List

Hi all,

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

  mm/mmap.c

between commit:

  f0b1293f7ebbb ("mm/mmap: Reorganize munmap to use maple states")

from the maple tree and commit:

  a213e5cf71cbc ("mm/munlock: delete munlock_vma_pages_all(), allow oomreap")

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.

I have absolutely no confindence in this resolution.

diff --cc mm/mmap.c
index 1b3600152f6f5,64b5985b5295c..0000000000000
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@@ -2286,32 -2780,38 +2286,37 @@@ int split_vma(struct mm_struct *mm, str
  	return __split_vma(mm, vma, addr, new_below);
  }
  
 -/* Munmap is split into 2 main parts -- this part which finds
 +/*
 + * do_mas_align_munmap() - munmap the aligned region from @start to @end.
 + * @mas: The maple_state, ideally set up to alter the correct tree location.
 + * @vma: The starting vm_area_struct
 + * @mm: The mm_struct
 + * @start: The aligned start address to munmap.
 + * @end: The aligned end address to munmap.
 + * @uf: The userfaultfd list_head
 + * @downgrade: Set to true to attempt a write downgrade of the mmap_sem
 + *
 + * If @downgrade is true, check return code for potential release of the lock.
++ *
++ * Munmap is split into 2 main parts -- this part which finds
+  * what needs doing, and the areas themselves, which do the
+  * work.  This now handles partial unmappings.
+  * Jeremy Fitzhardinge <jeremy@goop.org>
   */
 -int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len,
 -		struct list_head *uf, bool downgrade)
 -{
 -	unsigned long end;
 -	struct vm_area_struct *vma, *prev, *last;
 -
 -	if ((offset_in_page(start)) || start > TASK_SIZE || len > TASK_SIZE-start)
 -		return -EINVAL;
 -
 -	len = PAGE_ALIGN(len);
 -	end = start + len;
 -	if (len == 0)
 -		return -EINVAL;
 -
 -	/*
 -	 * arch_unmap() might do unmaps itself.  It must be called
 -	 * and finish any rbtree manipulation before this code
 -	 * runs and also starts to manipulate the rbtree.
 -	 */
 -	arch_unmap(mm, start, end);
 -
 -	/* Find the first overlapping VMA where start < vma->vm_end */
 -	vma = find_vma_intersection(mm, start, end);
 -	if (!vma)
 -		return 0;
 -	prev = vma->vm_prev;
 -
 +static int
 +do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
 +		    struct mm_struct *mm, unsigned long start,
 +		    unsigned long end, struct list_head *uf, bool downgrade)
 +{
 +	struct vm_area_struct *prev, *next;
 +	struct maple_tree mt_detach;
 +	int count = 0;
 +	MA_STATE(mas_detach, &mt_detach, start, end - 1);
 +	mt_init_flags(&mt_detach, MM_MT_FLAGS);
 +	mt_set_external_lock(&mt_detach, &mm->mmap_lock);
 +
 +	mas->last = end - 1;
 +	prev = next = NULL;
  	/*
  	 * If we need to split any vma, do it now to save pain later.
  	 *
@@@ -3107,13 -3127,8 +3112,12 @@@ void exit_mmap(struct mm_struct *mm
  		 * Nothing can be holding mm->mmap_lock here and the above call
  		 * to mmu_notifier_release(mm) ensures mmu notifier callbacks in
  		 * __oom_reap_task_mm() will not block.
 +		 *
 +		 * This needs to be done before unlocking the VMAs in the loop
 +		 * below which clears VM_LOCKED, otherwise the oom reaper cannot
 +		 * reliably test it.
  		 */
  		(void)__oom_reap_task_mm(mm);
- 
  		set_bit(MMF_OOM_SKIP, &mm->flags);
  	}

diff --git a/mm/mmap.c b/mm/mmap.c
index 2ddf1caf90488..d469555df0a21 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2373,10 +2373,8 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
 		BUG_ON(next->vm_start > end);
 #endif
 		vma_mas_store(next, &mas_detach);
-		if (next->vm_flags & VM_LOCKED) {
+		if (next->vm_flags & VM_LOCKED)
 			mm->locked_vm -= vma_pages(next);
-			munlock_vma_pages_all(next);
-		}
 	}
 
 	next = mas_find(mas, ULONG_MAX);
@@ -2906,10 +2904,8 @@ static int do_brk_munmap(struct ma_state *mas, struct vm_area_struct *vma,
 	}
 
 	unmap_pages = vma_pages(&unmap);
-	if (vma->vm_flags & VM_LOCKED) {
+	if (vma->vm_flags & VM_LOCKED)
 		mm->locked_vm -= unmap_pages;
-		munlock_vma_pages_range(&unmap, newbrk, oldbrk);
-	}
 
 	next = mas_next(mas, ULONG_MAX);
 	mmap_write_downgrade(mm);
@@ -3130,10 +3126,8 @@ void exit_mmap(struct mm_struct *mm)
 	rwsem_acquire(&mm->mmap_lock.dep_map, 0, 0, _THIS_IP_);
 	if (mm->locked_vm) {
 		mas_for_each(&mas, vma, ULONG_MAX) {
-			if (vma->vm_flags & VM_LOCKED) {
+			if (vma->vm_flags & VM_LOCKED)
 				mm->locked_vm -= vma_pages(vma);
-				munlock_vma_pages_all(vma);
-			}
 		}
 		mas_set(&mas, 0);
 	}

diff --git a/mm/mmap.c b/mm/mmap.c
index 2ddf1caf90488..d469555df0a21 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2373,10 +2373,8 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
 		BUG_ON(next->vm_start > end);
 #endif
 		vma_mas_store(next, &mas_detach);
-		if (next->vm_flags & VM_LOCKED) {
+		if (next->vm_flags & VM_LOCKED)
 			mm->locked_vm -= vma_pages(next);
-			munlock_vma_pages_all(next);
-		}
 	}
 
 	next = mas_find(mas, ULONG_MAX);
@@ -2906,10 +2904,8 @@ static int do_brk_munmap(struct ma_state *mas, struct vm_area_struct *vma,
 	}
 
 	unmap_pages = vma_pages(&unmap);
-	if (vma->vm_flags & VM_LOCKED) {
+	if (vma->vm_flags & VM_LOCKED)
 		mm->locked_vm -= unmap_pages;
-		munlock_vma_pages_range(&unmap, newbrk, oldbrk);
-	}
 
 	next = mas_next(mas, ULONG_MAX);
 	mmap_write_downgrade(mm);
@@ -3130,10 +3126,8 @@ void exit_mmap(struct mm_struct *mm)
 	rwsem_acquire(&mm->mmap_lock.dep_map, 0, 0, _THIS_IP_);
 	if (mm->locked_vm) {
 		mas_for_each(&mas, vma, ULONG_MAX) {
-			if (vma->vm_flags & VM_LOCKED) {
+			if (vma->vm_flags & VM_LOCKED)
 				mm->locked_vm -= vma_pages(vma);
-				munlock_vma_pages_all(vma);
-			}
 		}
 		mas_set(&mas, 0);
 	}

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* linux-next: manual merge of the folio tree with the maple tree
@ 2022-02-23 23:54 broonie
  0 siblings, 0 replies; 6+ messages in thread
From: broonie @ 2022-02-23 23:54 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Hugh Dickins, Liam R . Howlett, Liam R . Howlett,
	Linux Kernel Mailing List, Linux Next Mailing List

Hi all,

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

  mm/oom_kill.c

between commit:

  91a14015304fe ("mm/oom_kill: Use maple tree iterators instead of vma linked list")

from the maple tree and commit:

  a213e5cf71cbc ("mm/munlock: delete munlock_vma_pages_all(), allow oomreap")

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/oom_kill.c
index 0e7effe225e59,6b875acabd1e7..0000000000000
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@@ -555,8 -525,8 +555,8 @@@ bool __oom_reap_task_mm(struct mm_struc
  	 */
  	set_bit(MMF_UNSTABLE, &mm->flags);
  
 -	for (vma = mm->mmap ; vma; vma = vma->vm_next) {
 +	for_each_vma(vmi, vma) {
- 		if (!can_madv_lru_vma(vma))
+ 		if (vma->vm_flags & (VM_HUGETLB|VM_PFNMAP))
  			continue;
  
  		/*

^ permalink raw reply	[flat|nested] 6+ messages in thread

* linux-next: manual merge of the folio tree with the maple tree
@ 2022-02-23 23:49 broonie
  0 siblings, 0 replies; 6+ messages in thread
From: broonie @ 2022-02-23 23:49 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Liam R . Howlett, Liam R . Howlett, Linux Kernel Mailing List,
	Linux Next Mailing List

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,

^ permalink raw reply	[flat|nested] 6+ messages in thread

* linux-next: manual merge of the folio tree with the maple tree
@ 2022-02-17  7:11 Stephen Rothwell
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Rothwell @ 2022-02-17  7:11 UTC (permalink / raw)
  To: Matthew Wilcox, Liam Howlett
  Cc: Hugh Dickins, Linux Kernel Mailing List, Linux Next Mailing List

[-- Attachment #1: Type: text/plain, Size: 1791 bytes --]

Hi all,

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

  mm/mmap.c

between commit:

  b09e8361a4c3 ("mm: Remove the vma linked list")

from the maple tree and commit:

  ad56e23dec9a ("mm/munlock: delete munlock_vma_pages_all(), allow oomreap")

from the folio tree.

I fixed it up (I think - 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.

-- 
Cheers,
Stephen Rothwell

diff --cc mm/mmap.c
index 1b3600152f6f,64b5985b5295..000000000000
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@@ -3116,30 -3132,13 +3112,19 @@@ void exit_mmap(struct mm_struct *mm
  		set_bit(MMF_OOM_SKIP, &mm->flags);
  	}
  
 -	mmap_write_lock(mm);
 +	/*
 +	 * Actually taking the mmap semaphore here costs 3% performance on
 +	 * a large machine:
 +	 * https://lore.kernel.org/lkml/20170725151754.3txp44a2kbffsxdg@node.shutemov.name/
 +	 * Lockdep will complain about not holding the mmap_lock, so we lie.
 +	 */
 +	rwsem_acquire(&mm->mmap_lock.dep_map, 0, 0, _THIS_IP_);
- 	if (mm->locked_vm) {
- 		mas_for_each(&mas, vma, ULONG_MAX) {
- 			if (vma->vm_flags & VM_LOCKED) {
- 				mm->locked_vm -= vma_pages(vma);
- 				munlock_vma_pages_all(vma);
- 			}
- 		}
- 		mas_set(&mas, 0);
- 	}
- 
  	arch_exit_mmap(mm);
  
 -	vma = mm->mmap;
 +	vma = mas_find(&mas, ULONG_MAX);
  	if (!vma) {
  		/* Can happen if dup_mmap() received an OOM */
 -		mmap_write_unlock(mm);
 +		rwsem_release(&mm->mmap_lock.dep_map, _THIS_IP_);
  		return;
  	}
  

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-02-24  2:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-17  6:44 linux-next: manual merge of the folio tree with the maple tree Stephen Rothwell
2022-02-17  7:11 Stephen Rothwell
2022-02-23 23:49 broonie
2022-02-23 23:54 broonie
2022-02-24  1:16 broonie
2022-02-24  2:02 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).