linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()
@ 2020-10-16  3:39 Xianting Tian
  2020-10-16 12:07 ` Michal Hocko
  0 siblings, 1 reply; 7+ messages in thread
From: Xianting Tian @ 2020-10-16  3:39 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Xianting Tian

In shrink_slab(), it directly goes to 'out' label only when it
can't get the lock of shrinker_rwsew. In this case, it doesn't
do the real work of shrinking slab, so we don't need trigger a
reschedule by cond_resched().

Signed-off-by: Xianting Tian <tian.xianting@h3c.com>
---
 mm/vmscan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 466fc3144..676e97b28 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -687,8 +687,9 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
 	}
 
 	up_read(&shrinker_rwsem);
-out:
+
 	cond_resched();
+out:
 	return freed;
 }
 
-- 
2.17.1



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

* Re: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()
  2020-10-16  3:39 [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab() Xianting Tian
@ 2020-10-16 12:07 ` Michal Hocko
  2020-10-16 12:48   ` Tianxianting
  0 siblings, 1 reply; 7+ messages in thread
From: Michal Hocko @ 2020-10-16 12:07 UTC (permalink / raw)
  To: Xianting Tian; +Cc: akpm, linux-mm, linux-kernel

On Fri 16-10-20 11:39:52, Xianting Tian wrote:
> In shrink_slab(), it directly goes to 'out' label only when it
> can't get the lock of shrinker_rwsew. In this case, it doesn't
> do the real work of shrinking slab, so we don't need trigger a
> reschedule by cond_resched().

Your changelog doesn't explain why this is not needed or undesirable. Do
you see any actual problem?

The point of this code is to provide a deterministic scheduling point
regardless of the shrinker_rwsew.

> 
> Signed-off-by: Xianting Tian <tian.xianting@h3c.com>
> ---
>  mm/vmscan.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 466fc3144..676e97b28 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -687,8 +687,9 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
>  	}
>  
>  	up_read(&shrinker_rwsem);
> -out:
> +
>  	cond_resched();
> +out:
>  	return freed;
>  }
>  
> -- 
> 2.17.1
> 

-- 
Michal Hocko
SUSE Labs


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

* RE: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()
  2020-10-16 12:07 ` Michal Hocko
@ 2020-10-16 12:48   ` Tianxianting
  2020-10-16 13:02     ` Michal Hocko
  0 siblings, 1 reply; 7+ messages in thread
From: Tianxianting @ 2020-10-16 12:48 UTC (permalink / raw)
  To: Michal Hocko; +Cc: akpm, linux-mm, linux-kernel

Thanks, my understanding is,
In shrink_slab(), do_shrink_slab() will do the real reclaim work, which will occupy current cpu and consume more cpu time, so we need to trigger a reschedule after reclaim.
But if it jumps to 'out' label, that means we don't do the reclaim work at this time, it won't cause other thread getting starvation, so we don't need to call cond_resched() in this case.
Is it right?

-----Original Message-----
From: Michal Hocko [mailto:mhocko@suse.com] 
Sent: Friday, October 16, 2020 8:08 PM
To: tianxianting (RD) <tian.xianting@h3c.com>
Cc: akpm@linux-foundation.org; linux-mm@kvack.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()

On Fri 16-10-20 11:39:52, Xianting Tian wrote:
> In shrink_slab(), it directly goes to 'out' label only when it can't 
> get the lock of shrinker_rwsew. In this case, it doesn't do the real 
> work of shrinking slab, so we don't need trigger a reschedule by 
> cond_resched().

Your changelog doesn't explain why this is not needed or undesirable. Do you see any actual problem?

The point of this code is to provide a deterministic scheduling point regardless of the shrinker_rwsew.

> 
> Signed-off-by: Xianting Tian <tian.xianting@h3c.com>
> ---
>  mm/vmscan.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c index 466fc3144..676e97b28 
> 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -687,8 +687,9 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
>  	}
>  
>  	up_read(&shrinker_rwsem);
> -out:
> +
>  	cond_resched();
> +out:
>  	return freed;
>  }
>  
> --
> 2.17.1
> 

-- 
Michal Hocko
SUSE Labs


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

* Re: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()
  2020-10-16 12:48   ` Tianxianting
@ 2020-10-16 13:02     ` Michal Hocko
  2020-10-16 13:20       ` Tianxianting
  0 siblings, 1 reply; 7+ messages in thread
From: Michal Hocko @ 2020-10-16 13:02 UTC (permalink / raw)
  To: Tianxianting; +Cc: akpm, linux-mm, linux-kernel

On Fri 16-10-20 12:48:23, Tianxianting wrote:
> Thanks, my understanding is,
> In shrink_slab(), do_shrink_slab() will do the real reclaim work, which will occupy current cpu and consume more cpu time, so we need to trigger a reschedule after reclaim.
> But if it jumps to 'out' label, that means we don't do the reclaim work at this time, it won't cause other thread getting starvation, so we don't need to call cond_resched() in this case.
> Is it right?

You are almost right. But consider situation when the lock is taken for
quite some time. do_shrink_slab cannot make any forward progress and
effectivelly busy loop. Unless the caller does cond_resched it might
cause soft lockups.

Anyway let me try to ask again. Why does would this be any problem that
deserves a fix?

> 
> -----Original Message-----
> From: Michal Hocko [mailto:mhocko@suse.com] 
> Sent: Friday, October 16, 2020 8:08 PM
> To: tianxianting (RD) <tian.xianting@h3c.com>
> Cc: akpm@linux-foundation.org; linux-mm@kvack.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()
> 
> On Fri 16-10-20 11:39:52, Xianting Tian wrote:
> > In shrink_slab(), it directly goes to 'out' label only when it can't 
> > get the lock of shrinker_rwsew. In this case, it doesn't do the real 
> > work of shrinking slab, so we don't need trigger a reschedule by 
> > cond_resched().
> 
> Your changelog doesn't explain why this is not needed or undesirable. Do you see any actual problem?
> 
> The point of this code is to provide a deterministic scheduling point regardless of the shrinker_rwsew.
> 
> > 
> > Signed-off-by: Xianting Tian <tian.xianting@h3c.com>
> > ---
> >  mm/vmscan.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/mm/vmscan.c b/mm/vmscan.c index 466fc3144..676e97b28 
> > 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -687,8 +687,9 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
> >  	}
> >  
> >  	up_read(&shrinker_rwsem);
> > -out:
> > +
> >  	cond_resched();
> > +out:
> >  	return freed;
> >  }
> >  
> > --
> > 2.17.1
> > 
> 
> -- 
> Michal Hocko
> SUSE Labs

-- 
Michal Hocko
SUSE Labs


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

* RE: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()
  2020-10-16 13:02     ` Michal Hocko
@ 2020-10-16 13:20       ` Tianxianting
  2020-10-16 13:44         ` Michal Hocko
  0 siblings, 1 reply; 7+ messages in thread
From: Tianxianting @ 2020-10-16 13:20 UTC (permalink / raw)
  To: Michal Hocko; +Cc: akpm, linux-mm, linux-kernel

Thanks
I understood what you said :)
But whether it is proper to check reschedule in every loop when lock is taken? 

By the way, I did not met a issue for this , I just learn this code and come up with one possible optimization based my understanding.

-----Original Message-----
From: Michal Hocko [mailto:mhocko@suse.com] 
Sent: Friday, October 16, 2020 9:02 PM
To: tianxianting (RD) <tian.xianting@h3c.com>
Cc: akpm@linux-foundation.org; linux-mm@kvack.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()

On Fri 16-10-20 12:48:23, Tianxianting wrote:
> Thanks, my understanding is,
> In shrink_slab(), do_shrink_slab() will do the real reclaim work, which will occupy current cpu and consume more cpu time, so we need to trigger a reschedule after reclaim.
> But if it jumps to 'out' label, that means we don't do the reclaim work at this time, it won't cause other thread getting starvation, so we don't need to call cond_resched() in this case.
> Is it right?

You are almost right. But consider situation when the lock is taken for quite some time. do_shrink_slab cannot make any forward progress and effectivelly busy loop. Unless the caller does cond_resched it might cause soft lockups.

Anyway let me try to ask again. Why does would this be any problem that deserves a fix?

> 
> -----Original Message-----
> From: Michal Hocko [mailto:mhocko@suse.com]
> Sent: Friday, October 16, 2020 8:08 PM
> To: tianxianting (RD) <tian.xianting@h3c.com>
> Cc: akpm@linux-foundation.org; linux-mm@kvack.org; 
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] mm: vmscan: avoid a unnecessary reschedule in 
> shrink_slab()
> 
> On Fri 16-10-20 11:39:52, Xianting Tian wrote:
> > In shrink_slab(), it directly goes to 'out' label only when it can't 
> > get the lock of shrinker_rwsew. In this case, it doesn't do the real 
> > work of shrinking slab, so we don't need trigger a reschedule by 
> > cond_resched().
> 
> Your changelog doesn't explain why this is not needed or undesirable. Do you see any actual problem?
> 
> The point of this code is to provide a deterministic scheduling point regardless of the shrinker_rwsew.
> 
> > 
> > Signed-off-by: Xianting Tian <tian.xianting@h3c.com>
> > ---
> >  mm/vmscan.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/mm/vmscan.c b/mm/vmscan.c index 466fc3144..676e97b28
> > 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -687,8 +687,9 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
> >  	}
> >  
> >  	up_read(&shrinker_rwsem);
> > -out:
> > +
> >  	cond_resched();
> > +out:
> >  	return freed;
> >  }
> >  
> > --
> > 2.17.1
> > 
> 
> --
> Michal Hocko
> SUSE Labs

--
Michal Hocko
SUSE Labs


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

* Re: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()
  2020-10-16 13:20       ` Tianxianting
@ 2020-10-16 13:44         ` Michal Hocko
  2020-10-16 14:33           ` Tianxianting
  0 siblings, 1 reply; 7+ messages in thread
From: Michal Hocko @ 2020-10-16 13:44 UTC (permalink / raw)
  To: Tianxianting; +Cc: akpm, linux-mm, linux-kernel

On Fri 16-10-20 13:20:41, Tianxianting wrote:
> Thanks
> I understood what you said :)
> But whether it is proper to check reschedule in every loop when lock is taken? 

I do not see any actual problem TBH. cond_resched is mostly to increase
interactivity for non preemptible kernel. It can reduce throughput but
this is a memory reclaim path and I do not expect this to contribute to
any moderate hot paths. Direct reclaim doesn't really count as a hot
path.

-- 
Michal Hocko
SUSE Labs


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

* RE: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()
  2020-10-16 13:44         ` Michal Hocko
@ 2020-10-16 14:33           ` Tianxianting
  0 siblings, 0 replies; 7+ messages in thread
From: Tianxianting @ 2020-10-16 14:33 UTC (permalink / raw)
  To: Michal Hocko; +Cc: akpm, linux-mm, linux-kernel

Thanks for the explain.
I got it.

-----Original Message-----
From: Michal Hocko [mailto:mhocko@suse.com] 
Sent: Friday, October 16, 2020 9:45 PM
To: tianxianting (RD) <tian.xianting@h3c.com>
Cc: akpm@linux-foundation.org; linux-mm@kvack.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab()

On Fri 16-10-20 13:20:41, Tianxianting wrote:
> Thanks
> I understood what you said :)
> But whether it is proper to check reschedule in every loop when lock is taken? 

I do not see any actual problem TBH. cond_resched is mostly to increase interactivity for non preemptible kernel. It can reduce throughput but this is a memory reclaim path and I do not expect this to contribute to any moderate hot paths. Direct reclaim doesn't really count as a hot path.

--
Michal Hocko
SUSE Labs


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

end of thread, other threads:[~2020-10-16 15:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16  3:39 [PATCH] mm: vmscan: avoid a unnecessary reschedule in shrink_slab() Xianting Tian
2020-10-16 12:07 ` Michal Hocko
2020-10-16 12:48   ` Tianxianting
2020-10-16 13:02     ` Michal Hocko
2020-10-16 13:20       ` Tianxianting
2020-10-16 13:44         ` Michal Hocko
2020-10-16 14:33           ` Tianxianting

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).