public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -mm] select_bad_process: cleanup 'releasing' check
@ 2006-08-27 18:25 Oleg Nesterov
  2006-08-28 10:44 ` Nick Piggin
  0 siblings, 1 reply; 3+ messages in thread
From: Oleg Nesterov @ 2006-08-27 18:25 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Nick Piggin, linux-kernel

On top of "select_bad_process: kill a bogus PF_DEAD/TASK_DEAD check"

No logic changes, but imho easier to read.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- 2.6.18-rc4/mm/oom_kill.c~	2006-08-27 20:56:23.000000000 +0400
+++ 2.6.18-rc4/mm/oom_kill.c	2006-08-27 21:58:32.000000000 +0400
@@ -205,7 +205,6 @@ static struct task_struct *select_bad_pr
 	do_posix_clock_monotonic_gettime(&uptime);
 	do_each_thread(g, p) {
 		unsigned long points;
-		int releasing;
 
 		/*
 		 * skip kernel threads and tasks which have already released
@@ -227,16 +226,15 @@ static struct task_struct *select_bad_pr
 		 * the process of exiting and releasing its resources.
 		 * Otherwise we could get an OOM deadlock.
 		 */
-		releasing = test_tsk_thread_flag(p, TIF_MEMDIE) ||
-						p->flags & PF_EXITING;
-		if (releasing) {
-			if (p->flags & PF_EXITING && p == current) {
-				chosen = p;
-				*ppoints = ULONG_MAX;
-				break;
-			}
-			return ERR_PTR(-1UL);
-		}
+		if ((p->flags & PF_EXITING) && p == current) {
+			chosen = p;
+			*ppoints = ULONG_MAX;
+			break;
+		}
+		if ((p->flags & PF_EXITING) ||
+				test_tsk_thread_flag(p, TIF_MEMDIE))
+			return ERR_PTR(-1UL);
+
 		if (p->oomkilladj == OOM_DISABLE)
 			continue;
 
@@ -246,6 +244,7 @@ static struct task_struct *select_bad_pr
 			*ppoints = points;
 		}
 	} while_each_thread(g, p);
+
 	return chosen;
 }
 


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

* Re: [PATCH -mm] select_bad_process: cleanup 'releasing' check
  2006-08-27 18:25 [PATCH -mm] select_bad_process: cleanup 'releasing' check Oleg Nesterov
@ 2006-08-28 10:44 ` Nick Piggin
  2006-08-28 15:00   ` Oleg Nesterov
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Piggin @ 2006-08-28 10:44 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Andrew Morton, linux-kernel

On Sun, Aug 27, 2006 at 10:25:38PM +0400, Oleg Nesterov wrote:
> On top of "select_bad_process: kill a bogus PF_DEAD/TASK_DEAD check"
> 
> No logic changes, but imho easier to read.
> 
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
> 
> --- 2.6.18-rc4/mm/oom_kill.c~	2006-08-27 20:56:23.000000000 +0400
> +++ 2.6.18-rc4/mm/oom_kill.c	2006-08-27 21:58:32.000000000 +0400
> @@ -205,7 +205,6 @@ static struct task_struct *select_bad_pr
>  	do_posix_clock_monotonic_gettime(&uptime);
>  	do_each_thread(g, p) {
>  		unsigned long points;
> -		int releasing;
>  
>  		/*
>  		 * skip kernel threads and tasks which have already released
> @@ -227,16 +226,15 @@ static struct task_struct *select_bad_pr
>  		 * the process of exiting and releasing its resources.
>  		 * Otherwise we could get an OOM deadlock.
>  		 */
> -		releasing = test_tsk_thread_flag(p, TIF_MEMDIE) ||
> -						p->flags & PF_EXITING;
> -		if (releasing) {
> -			if (p->flags & PF_EXITING && p == current) {
> -				chosen = p;
> -				*ppoints = ULONG_MAX;
> -				break;
> -			}
> -			return ERR_PTR(-1UL);
> -		}
> +		if ((p->flags & PF_EXITING) && p == current) {
> +			chosen = p;
> +			*ppoints = ULONG_MAX;
> +			break;
> +		}
> +		if ((p->flags & PF_EXITING) ||
> +				test_tsk_thread_flag(p, TIF_MEMDIE))
> +			return ERR_PTR(-1UL);
> +

Hmm, actually I think I spot a bug in the original logic: we don't want
to have more than 1 task with TIF_MEMDIE at once, becaues that gives it
access to memory reserves (but I saw it first in the new formulation, so
maybe that does suggest it is more readable ;)

What I think should be done is the check for TIF_MEMDIE (and return -1)
first, and then the PF_EXITING test. At which point, if current is found to
be exiting, it should be chosen but not break... that way a subsequent MEMDIE
or EXITING task has the chance to trigger the -1 return.

Anyway, if you don't want to do all that, I will when my hand gets better.
Otherwise the 3 patches you sent look good, they could all have an

Acked-by: Nick Piggin <npiggin@suse.de>

Thanks,
Nick

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

* Re: [PATCH -mm] select_bad_process: cleanup 'releasing' check
  2006-08-28 10:44 ` Nick Piggin
@ 2006-08-28 15:00   ` Oleg Nesterov
  0 siblings, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2006-08-28 15:00 UTC (permalink / raw)
  To: Nick Piggin; +Cc: Andrew Morton, linux-kernel

On 08/28, Nick Piggin wrote:
>
> On Sun, Aug 27, 2006 at 10:25:38PM +0400, Oleg Nesterov wrote:
> > 
> > -		releasing = test_tsk_thread_flag(p, TIF_MEMDIE) ||
> > -						p->flags & PF_EXITING;
> > -		if (releasing) {
> > -			if (p->flags & PF_EXITING && p == current) {
> > -				chosen = p;
> > -				*ppoints = ULONG_MAX;
> > -				break;
> > -			}
> > -			return ERR_PTR(-1UL);
> > -		}
> > +		if ((p->flags & PF_EXITING) && p == current) {
> > +			chosen = p;
> > +			*ppoints = ULONG_MAX;
> > +			break;
> > +		}
> > +		if ((p->flags & PF_EXITING) ||
> > +				test_tsk_thread_flag(p, TIF_MEMDIE))
> > +			return ERR_PTR(-1UL);
> > +
> 
> Hmm, actually I think I spot a bug in the original logic: we don't want
> to have more than 1 task with TIF_MEMDIE at once, becaues that gives it
> access to memory reserves (but I saw it first in the new formulation, so
> maybe that does suggest it is more readable ;)
> 
> What I think should be done is the check for TIF_MEMDIE (and return -1)
> first, and then the PF_EXITING test. At which point, if current is found to
> be exiting, it should be chosen but not break... that way a subsequent MEMDIE
> or EXITING task has the chance to trigger the -1 return.

Aha! The logic looked somewhat strange to me, but ...

> Anyway, if you don't want to do all that, I will when my hand gets better.

I have little understanding of this magic, i'd better not to try to fix it.

> Otherwise the 3 patches you sent look good, they could all have an
> 
> Acked-by: Nick Piggin <npiggin@suse.de>

Thanks!

Oleg.


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

end of thread, other threads:[~2006-08-28 11:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-27 18:25 [PATCH -mm] select_bad_process: cleanup 'releasing' check Oleg Nesterov
2006-08-28 10:44 ` Nick Piggin
2006-08-28 15:00   ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox