linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] oom_reaper: avoid pointless atomic_inc_not_zero usage.
@ 2016-06-04  7:19 Tetsuo Handa
  2016-06-06  7:18 ` Michal Hocko
  2016-06-06 21:13 ` Andrew Morton
  0 siblings, 2 replies; 5+ messages in thread
From: Tetsuo Handa @ 2016-06-04  7:19 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, Tetsuo Handa, Michal Hocko, Arnd Bergmann

Since commit 36324a990cf578b5 ("oom: clear TIF_MEMDIE after oom_reaper
managed to unmap the address space") changed to use find_lock_task_mm()
for finding a mm_struct to reap, it is guaranteed that mm->mm_users > 0
because find_lock_task_mm() returns a task_struct with ->mm != NULL.
Therefore, we can safely use atomic_inc().

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 mm/oom_kill.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index dfb1ab6..8050fa0 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -474,13 +474,8 @@ static bool __oom_reap_task(struct task_struct *tsk)
 	p = find_lock_task_mm(tsk);
 	if (!p)
 		goto unlock_oom;
-
 	mm = p->mm;
-	if (!atomic_inc_not_zero(&mm->mm_users)) {
-		task_unlock(p);
-		goto unlock_oom;
-	}
-
+	atomic_inc(&mm->mm_users);
 	task_unlock(p);
 
 	if (!down_read_trylock(&mm->mmap_sem)) {
-- 
1.8.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] oom_reaper: avoid pointless atomic_inc_not_zero usage.
  2016-06-04  7:19 [PATCH] oom_reaper: avoid pointless atomic_inc_not_zero usage Tetsuo Handa
@ 2016-06-06  7:18 ` Michal Hocko
  2016-06-06 21:13 ` Andrew Morton
  1 sibling, 0 replies; 5+ messages in thread
From: Michal Hocko @ 2016-06-06  7:18 UTC (permalink / raw)
  To: Tetsuo Handa; +Cc: akpm, linux-mm, Arnd Bergmann

On Sat 04-06-16 16:19:19, Tetsuo Handa wrote:
> Since commit 36324a990cf578b5 ("oom: clear TIF_MEMDIE after oom_reaper
> managed to unmap the address space") changed to use find_lock_task_mm()
> for finding a mm_struct to reap, it is guaranteed that mm->mm_users > 0
> because find_lock_task_mm() returns a task_struct with ->mm != NULL.
> Therefore, we can safely use atomic_inc().
> 
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>

Acked-by: Michal Hocko <mhocko@suse.com>

Thanks!

> ---
>  mm/oom_kill.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index dfb1ab6..8050fa0 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -474,13 +474,8 @@ static bool __oom_reap_task(struct task_struct *tsk)
>  	p = find_lock_task_mm(tsk);
>  	if (!p)
>  		goto unlock_oom;
> -
>  	mm = p->mm;
> -	if (!atomic_inc_not_zero(&mm->mm_users)) {
> -		task_unlock(p);
> -		goto unlock_oom;
> -	}
> -
> +	atomic_inc(&mm->mm_users);
>  	task_unlock(p);
>  
>  	if (!down_read_trylock(&mm->mmap_sem)) {
> -- 
> 1.8.3.1
> 

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] oom_reaper: avoid pointless atomic_inc_not_zero usage.
  2016-06-04  7:19 [PATCH] oom_reaper: avoid pointless atomic_inc_not_zero usage Tetsuo Handa
  2016-06-06  7:18 ` Michal Hocko
@ 2016-06-06 21:13 ` Andrew Morton
  2016-06-08 17:04   ` Andrew Morton
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2016-06-06 21:13 UTC (permalink / raw)
  To: Tetsuo Handa; +Cc: linux-mm, Michal Hocko, Arnd Bergmann

On Sat,  4 Jun 2016 16:19:19 +0900 Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:

> Since commit 36324a990cf578b5 ("oom: clear TIF_MEMDIE after oom_reaper
> managed to unmap the address space") changed to use find_lock_task_mm()
> for finding a mm_struct to reap, it is guaranteed that mm->mm_users > 0
> because find_lock_task_mm() returns a task_struct with ->mm != NULL.
> Therefore, we can safely use atomic_inc().
> 
> ...
>
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -474,13 +474,8 @@ static bool __oom_reap_task(struct task_struct *tsk)
>  	p = find_lock_task_mm(tsk);
>  	if (!p)
>  		goto unlock_oom;
> -
>  	mm = p->mm;
> -	if (!atomic_inc_not_zero(&mm->mm_users)) {
> -		task_unlock(p);
> -		goto unlock_oom;
> -	}
> -
> +	atomic_inc(&mm->mm_users);
>  	task_unlock(p);
>  
>  	if (!down_read_trylock(&mm->mmap_sem)) {

In an off-list email (please don't do that!) you asked me to replace
mmoom_reaper-dont-call-mmput_async-without-atomic_inc_not_zero.patch
with this above patch.

But the
mmoom_reaper-dont-call-mmput_async-without-atomic_inc_not_zero.patch
changelog is pretty crappy:

: Commit e2fe14564d3316d1 ("oom_reaper: close race with exiting task")
: reduced frequency of needlessly selecting next OOM victim, but was
: calling mmput_async() when atomic_inc_not_zero() failed.

because it doesn't explain that the patch potentially fixes a kernel
crash.

And the changelog for this above patch is similarly crappy - it fails
to described the end-user visible effects of the bug which is being
fixed.  Please *always* do this.  Always always always.

Please send me a complete changelog for this patch, thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] oom_reaper: avoid pointless atomic_inc_not_zero usage.
  2016-06-06 21:13 ` Andrew Morton
@ 2016-06-08 17:04   ` Andrew Morton
  2016-06-08 22:27     ` Tetsuo Handa
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2016-06-08 17:04 UTC (permalink / raw)
  To: Tetsuo Handa, linux-mm, Michal Hocko, Arnd Bergmann

On Mon, 6 Jun 2016 14:13:40 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:

> On Sat,  4 Jun 2016 16:19:19 +0900 Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> 
> > Since commit 36324a990cf578b5 ("oom: clear TIF_MEMDIE after oom_reaper
> > managed to unmap the address space") changed to use find_lock_task_mm()
> > for finding a mm_struct to reap, it is guaranteed that mm->mm_users > 0
> > because find_lock_task_mm() returns a task_struct with ->mm != NULL.
> > Therefore, we can safely use atomic_inc().
> > 
> > ...
> >
> > --- a/mm/oom_kill.c
> > +++ b/mm/oom_kill.c
> > @@ -474,13 +474,8 @@ static bool __oom_reap_task(struct task_struct *tsk)
> >  	p = find_lock_task_mm(tsk);
> >  	if (!p)
> >  		goto unlock_oom;
> > -
> >  	mm = p->mm;
> > -	if (!atomic_inc_not_zero(&mm->mm_users)) {
> > -		task_unlock(p);
> > -		goto unlock_oom;
> > -	}
> > -
> > +	atomic_inc(&mm->mm_users);
> >  	task_unlock(p);
> >  
> >  	if (!down_read_trylock(&mm->mmap_sem)) {
> 
> In an off-list email (please don't do that!) you asked me to replace
> mmoom_reaper-dont-call-mmput_async-without-atomic_inc_not_zero.patch
> with this above patch.
> 
> But the
> mmoom_reaper-dont-call-mmput_async-without-atomic_inc_not_zero.patch
> changelog is pretty crappy:
> 
> : Commit e2fe14564d3316d1 ("oom_reaper: close race with exiting task")
> : reduced frequency of needlessly selecting next OOM victim, but was
> : calling mmput_async() when atomic_inc_not_zero() failed.
> 
> because it doesn't explain that the patch potentially fixes a kernel
> crash.
> 
> And the changelog for this above patch is similarly crappy - it fails
> to described the end-user visible effects of the bug which is being
> fixed.  Please *always* do this.  Always always always.
> 
> Please send me a complete changelog for this patch, thanks.

Ping?  Can we have a better changelog on this one?

That changelog will help us to decide whether to backport this into
4.6.x.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] oom_reaper: avoid pointless atomic_inc_not_zero usage.
  2016-06-08 17:04   ` Andrew Morton
@ 2016-06-08 22:27     ` Tetsuo Handa
  0 siblings, 0 replies; 5+ messages in thread
From: Tetsuo Handa @ 2016-06-08 22:27 UTC (permalink / raw)
  To: akpm, linux-mm, mhocko, arnd

Andrew Morton wrote:
> On Mon, 6 Jun 2016 14:13:40 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> > On Sat,  4 Jun 2016 16:19:19 +0900 Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> > 
> > > Since commit 36324a990cf578b5 ("oom: clear TIF_MEMDIE after oom_reaper
> > > managed to unmap the address space") changed to use find_lock_task_mm()
> > > for finding a mm_struct to reap, it is guaranteed that mm->mm_users > 0
> > > because find_lock_task_mm() returns a task_struct with ->mm != NULL.
> > > Therefore, we can safely use atomic_inc().
> > > 
> > > ...
> > >
> > > --- a/mm/oom_kill.c
> > > +++ b/mm/oom_kill.c
> > > @@ -474,13 +474,8 @@ static bool __oom_reap_task(struct task_struct *tsk)
> > >  	p = find_lock_task_mm(tsk);
> > >  	if (!p)
> > >  		goto unlock_oom;
> > > -
> > >  	mm = p->mm;
> > > -	if (!atomic_inc_not_zero(&mm->mm_users)) {
> > > -		task_unlock(p);
> > > -		goto unlock_oom;
> > > -	}
> > > -
> > > +	atomic_inc(&mm->mm_users);
> > >  	task_unlock(p);
> > >  
> > >  	if (!down_read_trylock(&mm->mmap_sem)) {
> > 
> > In an off-list email (please don't do that!) you asked me to replace
> > mmoom_reaper-dont-call-mmput_async-without-atomic_inc_not_zero.patch
> > with this above patch.
> > 
> > But the
> > mmoom_reaper-dont-call-mmput_async-without-atomic_inc_not_zero.patch
> > changelog is pretty crappy:
> > 
> > : Commit e2fe14564d3316d1 ("oom_reaper: close race with exiting task")
> > : reduced frequency of needlessly selecting next OOM victim, but was
> > : calling mmput_async() when atomic_inc_not_zero() failed.
> > 
> > because it doesn't explain that the patch potentially fixes a kernel
> > crash.
> > 
> > And the changelog for this above patch is similarly crappy - it fails
> > to described the end-user visible effects of the bug which is being
> > fixed.  Please *always* do this.  Always always always.
> > 
> > Please send me a complete changelog for this patch, thanks.
> 
> Ping?  Can we have a better changelog on this one?
> 
> That changelog will help us to decide whether to backport this into
> 4.6.x.
> 
No need to backport. There was no possibility of kernel crash from the
beginning. What I thought it might cause a problem did not exist.
We just forgot to convert atomic_inc_not_zero() to atomic_inc().

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2016-06-08 22:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-04  7:19 [PATCH] oom_reaper: avoid pointless atomic_inc_not_zero usage Tetsuo Handa
2016-06-06  7:18 ` Michal Hocko
2016-06-06 21:13 ` Andrew Morton
2016-06-08 17:04   ` Andrew Morton
2016-06-08 22:27     ` Tetsuo Handa

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