diff mbox series

[v4,62/66] mm/swapfile: Use maple tree iterator instead of vma linked list

Message ID 20211201142918.921493-63-Liam.Howlett@oracle.com (mailing list archive)
State New
Headers show
Series Introducing the Maple Tree | expand

Commit Message

Liam R. Howlett Dec. 1, 2021, 2:30 p.m. UTC
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
 mm/swapfile.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Vlastimil Babka Jan. 20, 2022, 12:46 p.m. UTC | #1
On 12/1/21 15:30, Liam Howlett wrote:
> From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
> 
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/swapfile.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index e59e08ef46e1..21c88b0944f9 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2103,15 +2103,18 @@ static int unuse_mm(struct mm_struct *mm, unsigned int type,
>  {
>  	struct vm_area_struct *vma;
>  	int ret = 0;
> +	MA_STATE(mas, &mm->mm_mt, 0, 0);
>  
>  	mmap_read_lock(mm);
> -	for (vma = mm->mmap; vma; vma = vma->vm_next) {
> +	mas_for_each(&mas, vma, ULONG_MAX) {
>  		if (vma->anon_vma) {
>  			ret = unuse_vma(vma, type, frontswap,
>  					fs_pages_to_unuse);
>  			if (ret)
>  				break;
>  		}
> +
> +		mas_pause(&mas);

AFAIU unnecessary for the resched as we don't drop anything and keep the
mmap_lock?
(and without that it could be VMA_ITERATOR?)

>  		cond_resched();
>  	}
>  	mmap_read_unlock(mm);
Liam R. Howlett Jan. 26, 2022, 5:08 p.m. UTC | #2
* Vlastimil Babka <vbabka@suse.cz> [220120 07:46]:
> On 12/1/21 15:30, Liam Howlett wrote:
> > From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
> > 
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>
> 
> > ---
> >  mm/swapfile.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/mm/swapfile.c b/mm/swapfile.c
> > index e59e08ef46e1..21c88b0944f9 100644
> > --- a/mm/swapfile.c
> > +++ b/mm/swapfile.c
> > @@ -2103,15 +2103,18 @@ static int unuse_mm(struct mm_struct *mm, unsigned int type,
> >  {
> >  	struct vm_area_struct *vma;
> >  	int ret = 0;
> > +	MA_STATE(mas, &mm->mm_mt, 0, 0);
> >  
> >  	mmap_read_lock(mm);
> > -	for (vma = mm->mmap; vma; vma = vma->vm_next) {
> > +	mas_for_each(&mas, vma, ULONG_MAX) {
> >  		if (vma->anon_vma) {
> >  			ret = unuse_vma(vma, type, frontswap,
> >  					fs_pages_to_unuse);
> >  			if (ret)
> >  				break;
> >  		}
> > +
> > +		mas_pause(&mas);
> 
> AFAIU unnecessary for the resched as we don't drop anything and keep the
> mmap_lock?
> (and without that it could be VMA_ITERATOR?)

Agreed.  This was missed with the conversion of the locking.  Thanks.

> 
> >  		cond_resched();
> >  	}
> >  	mmap_read_unlock(mm);
>
diff mbox series

Patch

diff --git a/mm/swapfile.c b/mm/swapfile.c
index e59e08ef46e1..21c88b0944f9 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2103,15 +2103,18 @@  static int unuse_mm(struct mm_struct *mm, unsigned int type,
 {
 	struct vm_area_struct *vma;
 	int ret = 0;
+	MA_STATE(mas, &mm->mm_mt, 0, 0);
 
 	mmap_read_lock(mm);
-	for (vma = mm->mmap; vma; vma = vma->vm_next) {
+	mas_for_each(&mas, vma, ULONG_MAX) {
 		if (vma->anon_vma) {
 			ret = unuse_vma(vma, type, frontswap,
 					fs_pages_to_unuse);
 			if (ret)
 				break;
 		}
+
+		mas_pause(&mas);
 		cond_resched();
 	}
 	mmap_read_unlock(mm);