public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] oom_kill fix
@ 2005-03-14 18:14 Coywolf Qi Hunt
  2005-03-15  2:02 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Coywolf Qi Hunt @ 2005-03-14 18:14 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel


Hello,

This oom_kill fix is to do mmput(mm) a bit earlier and returning 0 or 1
to indicate success or failure instead of returning mm_struct pointer. 

	Coywolf


Signed-off-by: Coywolf Qi Hunt <coywolf@gmail.com>
 oom_kill.c |   23 +++++++++--------------
 1 files changed, 9 insertions(+), 14 deletions(-)
diff -Nrup 2.6.11/mm/oom_kill.c 2.6.11-cy/mm/oom_kill.c
--- 2.6.11/mm/oom_kill.c	2005-03-03 17:12:18.000000000 +0800
+++ 2.6.11-cy/mm/oom_kill.c	2005-03-15 00:28:32.000000000 +0800
@@ -202,16 +202,16 @@ static void __oom_kill_task(task_t *p)
 	force_sig(SIGKILL, p);
 }
 
-static struct mm_struct *oom_kill_task(task_t *p)
+static int oom_kill_task(task_t *p)
 {
 	struct mm_struct *mm = get_task_mm(p);
 	task_t * g, * q;
 
 	if (!mm)
-		return NULL;
+		return 0;
 	if (mm == &init_mm) {
 		mmput(mm);
-		return NULL;
+		return 0;
 	}
 
 	__oom_kill_task(p);
@@ -224,12 +224,12 @@ static struct mm_struct *oom_kill_task(t
 			__oom_kill_task(q);
 	while_each_thread(g, q);
 
-	return mm;
+	mmput(mm);
+	return 1;
 }
 
-static struct mm_struct *oom_kill_process(struct task_struct *p)
+static int oom_kill_process(struct task_struct *p)
 {
- 	struct mm_struct *mm;
 	struct task_struct *c;
 	struct list_head *tsk;
 
@@ -238,9 +238,8 @@ static struct mm_struct *oom_kill_proces
 		c = list_entry(tsk, struct task_struct, sibling);
 		if (c->mm == p->mm)
 			continue;
-		mm = oom_kill_task(c);
-		if (mm)
-			return mm;
+		if (oom_kill_task(c))
+			return 1;
 	}
 	return oom_kill_task(p);
 }
@@ -255,7 +254,6 @@ static struct mm_struct *oom_kill_proces
  */
 void out_of_memory(int gfp_mask)
 {
-	struct mm_struct *mm = NULL;
 	task_t * p;
 
 	read_lock(&tasklist_lock);
@@ -274,14 +272,11 @@ retry:
 
 	printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
 	show_free_areas();
-	mm = oom_kill_process(p);
-	if (!mm)
+	if (!oom_kill_process(p))
 		goto retry;
 
  out:
 	read_unlock(&tasklist_lock);
-	if (mm)
-		mmput(mm);
 
 	/*
 	 * Give "p" a good chance of killing itself before we

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

* Re: [patch] oom_kill fix
  2005-03-14 18:14 [patch] oom_kill fix Coywolf Qi Hunt
@ 2005-03-15  2:02 ` Andrew Morton
  2005-03-15 18:44   ` Coywolf Qi Hunt
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2005-03-15  2:02 UTC (permalink / raw)
  To: coywolf; +Cc: coywolf, linux-kernel

Coywolf Qi Hunt <coywolf@sosdg.org> wrote:
>
>  This oom_kill fix is to do mmput(mm) a bit earlier and returning 0 or 1
>  to indicate success or failure instead of returning mm_struct pointer. 

Why is this a "fix"?  What bug is it fixing?

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

* Re: [patch] oom_kill fix
  2005-03-15  2:02 ` Andrew Morton
@ 2005-03-15 18:44   ` Coywolf Qi Hunt
  0 siblings, 0 replies; 3+ messages in thread
From: Coywolf Qi Hunt @ 2005-03-15 18:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: coywolf, linux-kernel

On Mon, 14 Mar 2005 18:02:58 -0800, Andrew Morton <akpm@osdl.org> wrote:
> Coywolf Qi Hunt <coywolf@sosdg.org> wrote:
> >
> >  This oom_kill fix is to do mmput(mm) a bit earlier and returning 0 or 1
> >  to indicate success or failure instead of returning mm_struct pointer.
> 
> Why is this a "fix"?  What bug is it fixing?
> 

It's at least a coding style improvement and lets the code be less obfuscated.
It increases the system survival possibilities by doing mmput immediately
and reduces the chances of oom killing another process unnecessarily, IMHO.

Or rather rename "fix" to "cleanup".

-- 
Coywolf Qi Hunt
http://sosdg.org/~coywolf/

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

end of thread, other threads:[~2005-03-15 18:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-14 18:14 [patch] oom_kill fix Coywolf Qi Hunt
2005-03-15  2:02 ` Andrew Morton
2005-03-15 18:44   ` Coywolf Qi Hunt

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