public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2.6.11-rc4] oom_kill.c: Kill obvious processes first
@ 2005-02-25  5:24 Parag Warudkar
  2005-02-28 22:30 ` Bill Davidsen
  0 siblings, 1 reply; 3+ messages in thread
From: Parag Warudkar @ 2005-02-25  5:24 UTC (permalink / raw)
  To: linux-kernel, Andrew Morton

[-- Attachment #1: Type: text/plain, Size: 1104 bytes --]


oom_kill.c misses very obvious targets - For example, a process occupying > 
80% memory, not superuser and not having hardware access gets ignored by it. 
Logically, such a process, if killed , is going to make things return to 
normal thereby eliminating the need for oom killer to further scan for more 
processes.

This patch calculates the approximate integer percentage of memory occupied by 
the process by looking at num_physpages and p->mm->total_vm. If this process 
is not super user and doesn't have hardware access, and the percentage of 
occupied memory is more than 60%, it immediately selects this process for 
killing by returning unusually high points from badness().

Without this patch, when KDevelop running as non root user gobbles up 90% 
memory, the OOM killer kills many other irrelevant processes but not KDevelop 
And machine never recovers.. (Pls see LKML for my previous message with 
subject "2.6.11-rc4 OOM Killer - Kill the Innocent".) 

With this patch OOM killer immediately kills kdevelop and machine recovers.

Signed-off-by: Parag Warudkar <kernel-stuff@comcast.net>

[-- Attachment #2: oom_kill.c.patch --]
[-- Type: text/x-diff, Size: 1924 bytes --]

--- linux-orig/mm/oom_kill.c	2005-02-23 20:03:11.000000000 -0500
+++ linux-2.6.10/mm/oom_kill.c	2005-02-25 00:21:20.000000000 -0500
@@ -44,8 +44,10 @@
 
 unsigned long badness(struct task_struct *p, unsigned long uptime)
 {
-	unsigned long points, cpu_time, run_time, s;
+	unsigned long points, cpu_time, run_time, s, pct_occ;
+	extern unsigned long num_physpages;
 	struct list_head *tsk;
+	int is_superuser=0, has_hwaccess=0;
 
 	if (!p->mm)
 		return 0;
@@ -55,6 +57,39 @@
 	 */
 	points = p->mm->total_vm;
 
+	if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_ADMIN) ||
+				p->uid == 0 || p->euid == 0) 
+	{
+		is_superuser=1;
+
+	}
+	
+	if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_RAWIO)) {
+		has_hwaccess=1;
+	}
+	
+	if(is_superuser || has_hwaccess)
+		goto skip_pct_chk;
+
+	/* If the process 
+	 * a. Does not belong to superuser
+	 * b. Does not have hardware access, and
+	 * c. Occupies more than or equal to 50% memory 
+	 * it is a very likely candidate to kill.
+	 */
+	pct_occ = points*100 / num_physpages;
+
+	if (pct_occ >= 60) {
+#ifdef DEBUG	
+		printk(KERN_DEBUG "Process %s with PID %d occupied more
+				 than 60% memory\n", p->comm, p->pid);
+#endif
+		/* Return unusually high number to make sure this process
+		 * gets killed
+		 */
+		return points*pct_occ;
+	}
+	skip_pct_chk:	
 	/*
 	 * Processes which fork a lot of child processes are likely
 	 * a good choice. We add the vmsize of the childs if they
@@ -99,8 +134,7 @@
 	 * Superuser processes are usually more important, so we make it
 	 * less likely that we kill those.
 	 */
-	if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_ADMIN) ||
-				p->uid == 0 || p->euid == 0)
+	if (is_superuser)
 		points /= 4;
 
 	/*
@@ -109,7 +143,7 @@
 	 * tend to only have this flag set on applications they think
 	 * of as important.
 	 */
-	if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_RAWIO))
+	if (has_hwaccess)
 		points /= 4;
 
 	/*

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

* Re: [PATCH 2.6.11-rc4] oom_kill.c: Kill obvious processes first
  2005-02-25  5:24 [PATCH 2.6.11-rc4] oom_kill.c: Kill obvious processes first Parag Warudkar
@ 2005-02-28 22:30 ` Bill Davidsen
  0 siblings, 0 replies; 3+ messages in thread
From: Bill Davidsen @ 2005-02-28 22:30 UTC (permalink / raw)
  To: linux-kernel, Parag Warudkar; +Cc: linux-kernel, Andrew Morton

Parag Warudkar wrote:
> oom_kill.c misses very obvious targets - For example, a process occupying > 
> 80% memory, not superuser and not having hardware access gets ignored by it. 
> Logically, such a process, if killed , is going to make things return to 
> normal thereby eliminating the need for oom killer to further scan for more 
> processes.
> 
> This patch calculates the approximate integer percentage of memory occupied by 
> the process by looking at num_physpages and p->mm->total_vm. If this process 
> is not super user and doesn't have hardware access, and the percentage of 
> occupied memory is more than 60%, it immediately selects this process for 
> killing by returning unusually high points from badness().
> 
> Without this patch, when KDevelop running as non root user gobbles up 90% 
> memory, the OOM killer kills many other irrelevant processes but not KDevelop 
> And machine never recovers.. (Pls see LKML for my previous message with 
> subject "2.6.11-rc4 OOM Killer - Kill the Innocent".) 
> 
> With this patch OOM killer immediately kills kdevelop and machine recovers.

Thank you for the patch, I'm in agreement with the idea, and I'll give 
it a try after I look at the code a bit. The current code frequently 
seems bit... non-deterministic.

-- 
    -bill davidsen (davidsen@tmr.com)
"The secret to procrastination is to put things off until the
  last possible moment - but no longer"  -me

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

* Re: [PATCH 2.6.11-rc4] oom_kill.c: Kill obvious processes first
@ 2005-03-01  0:55 Parag Warudkar
  0 siblings, 0 replies; 3+ messages in thread
From: Parag Warudkar @ 2005-03-01  0:55 UTC (permalink / raw)
  To: Bill Davidsen, linux-kernel; +Cc: linux-kernel, Andrew Morton

One person pointed out (rightly so) that this patch might end up killing a Oracle process for example since it occupies more than 60% memory - which is not good. While that may be case for a server, I think for a desktop this patch is right - it allows the user to gain control on the machine which has gone OOM.

> Thank you for the patch, I'm in agreement with the idea, and I'll give 
> it a try after I look at the code a bit. The current code frequently 
> seems bit... non-deterministic.
> 
> -- 
>     -bill davidsen (davidsen@tmr.com)
> "The secret to procrastination is to put things off until the
>   last possible moment - but no longer"  -me

I think oom_kill.c needs more intelligence and customizability. It should evaluate the per process rate of memory allocation for example. With that, it can determine if a process has had a steady VM size and give it less badness since there is a good possibility that some other process(es) might have gone bad  doing fork bombs or leaking memory. In short less badness for processes behaving well for a long time and not taking all the memory and not asking for more.

OTOH we need more configurability - Desktop settings might depict A)Dont kill X B) Don't kill KDE for example. Then OOM killer then can spare those processes to see if killing other processes is going to benefit. (If X / KDE went bad and gobbled up memory, may be it might still kill it - again rate of allocation matters.) Server admins might specify no killing of a database process until unless it is occupying all memory etc..


Parag


> Parag Warudkar wrote:
> > oom_kill.c misses very obvious targets - For example, a process occupying > 
> > 80% memory, not superuser and not having hardware access gets ignored by it. 
> > Logically, such a process, if killed , is going to make things return to 
> > normal thereby eliminating the need for oom killer to further scan for more 
> > processes.
> > 
> > This patch calculates the approximate integer percentage of memory occupied by 
> > the process by looking at num_physpages and p->mm->total_vm. If this process 
> > is not super user and doesn't have hardware access, and the percentage of 
> > occupied memory is more than 60%, it immediately selects this process for 
> > killing by returning unusually high points from badness().
> > 
> > Without this patch, when KDevelop running as non root user gobbles up 90% 
> > memory, the OOM killer kills many other irrelevant processes but not KDevelop 
> > And machine never recovers.. (Pls see LKML for my previous message with 
> > subject "2.6.11-rc4 OOM Killer - Kill the Innocent".) 
> > 
> > With this patch OOM killer immediately kills kdevelop and machine recovers.
> 

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

end of thread, other threads:[~2005-03-01  0:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-25  5:24 [PATCH 2.6.11-rc4] oom_kill.c: Kill obvious processes first Parag Warudkar
2005-02-28 22:30 ` Bill Davidsen
  -- strict thread matches above, loose matches on Subject: below --
2005-03-01  0:55 Parag Warudkar

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