public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: Linux killed Kenny, bastard!
@ 2009-01-13 10:58 Tomasz Chmielewski
  2009-01-13 12:20 ` Evgeniy Polyakov
  0 siblings, 1 reply; 57+ messages in thread
From: Tomasz Chmielewski @ 2009-01-13 10:58 UTC (permalink / raw)
  To: LKML, zbr

>> On Tue, 13 Jan 2009, Evgeniy Polyakov wrote:
>> 
>> > Like anything that spawns a thread or process per request/client, or
>> > preallocates set of them which connect to the huge object like database.
>> > Most of the time database/server is killed first instead of comparably
>> > small clients.
>> 
>> No, the reverse is true: when a task is chosen for oom kill based on the 
>> badness heuristic, the oom killer first attempts to kill any child task 
>> that isn't attached to the same mm.  If the child shares an mm, both tasks 
>> must die before memory freeing can occur.
> 
> It is a theory, not a practice. OOM-killer most of time starts from ssh,
> database and lighttpd on the tested machines, when it could start in
> the reverse order and do not touch ssh at all. Better not from daemon
> itself, but its fastcgi spawned processes.

How does this feature relate to:

config ANDROID_LOW_MEMORY_KILLER
         bool "Android Low Memory Killer"
         default N
         ---help---
           Register processes to be killed when memory is low

available in Staging drivers / Android?


-- 
Tomasz Chmielewski
http://wpkg.org


^ permalink raw reply	[flat|nested] 57+ messages in thread
* Linux killed Kenny, bastard!
@ 2009-01-12 15:33 Evgeniy Polyakov
  2009-01-12 15:44 ` Dave Jones
                   ` (2 more replies)
  0 siblings, 3 replies; 57+ messages in thread
From: Evgeniy Polyakov @ 2009-01-12 15:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Linus Torvalds

Hi.

Do you want to own a tame killer? Do you want to control the world?

Start with your computer now and own the planet next: you already have
an OOM-killer in the Linux to kill for you. But to date it was quite
berserk and usually killed not what you would like him to murder.

Now you can add a name of the victims, which will be checked by the
oom-killer, who select the process to kill first among the ones which
have given string in their executable name.

By default the process to be killed is called 'Kenny', and if you like
him, change then name by calling

echo Java > /proc/sys/vm/oom_victim

Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 3d56fe7..26d4361 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -68,6 +68,7 @@ extern int print_fatal_signals;
 extern int sysctl_overcommit_memory;
 extern int sysctl_overcommit_ratio;
 extern int sysctl_panic_on_oom;
+extern char oom_victim_name[];
 extern int sysctl_oom_kill_allocating_task;
 extern int sysctl_oom_dump_tasks;
 extern int max_threads;
@@ -1185,6 +1186,15 @@ static struct ctl_table vm_table[] = {
 		.extra2		= &one,
 	},
 #endif
+	{
+		.ctl_name	= CTL_UNNUMBERED,
+		.procname	= "oom_victim",
+		.data		= oom_victim_name,
+		.maxlen		= TASK_COMM_LEN,
+		.mode		= 0644,
+		.proc_handler	= &proc_dostring,
+		.strategy	= &sysctl_string,
+	},
 /*
  * NOTE: do not add new entries to this table unless you have read
  * Documentation/sysctl/ctl_unnumbered.txt
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index a0a0190..12419f5 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -28,6 +28,8 @@
 #include <linux/memcontrol.h>
 #include <linux/security.h>
 
+char oom_victim_name[TASK_COMM_LEN] = "Kenny";
+
 int sysctl_panic_on_oom;
 int sysctl_oom_kill_allocating_task;
 int sysctl_oom_dump_tasks;
@@ -205,8 +207,10 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
 	struct task_struct *g, *p;
 	struct task_struct *chosen = NULL;
 	struct timespec uptime;
+	char *name = oom_victim_name;
 	*ppoints = 0;
 
+again:
 	do_posix_clock_monotonic_gettime(&uptime);
 	do_each_thread(g, p) {
 		unsigned long points;
@@ -223,6 +227,9 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
 		if (mem && !task_in_mem_cgroup(p, mem))
 			continue;
 
+		if (name && !strstr(p->comm, name))
+			continue;
+
 		/*
 		 * This task already has access to memory reserves and is
 		 * being killed. Don't allow any other task access to the
@@ -263,6 +270,15 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
 		}
 	} while_each_thread(g, p);
 
+	/*
+	 * We did not find the process with requested string in its name,
+	 * so lets search for the usual victim.
+	 */
+	if (name && !chosen) {
+		name = NULL;
+		goto again;
+	}
+
 	return chosen;
 }
 


-- 
	Evgeniy Polyakov

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

end of thread, other threads:[~2009-01-18 13:17 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <bTxPW-1lH-13@gated-at.bofh.it>
     [not found] ` <bTE53-5LJ-13@gated-at.bofh.it>
     [not found]   ` <bTEeI-5Y0-15@gated-at.bofh.it>
     [not found]     ` <bTGTe-1K5-3@gated-at.bofh.it>
     [not found]       ` <bTNi6-3kb-9@gated-at.bofh.it>
     [not found]         ` <bTOea-4QT-1@gated-at.bofh.it>
     [not found]           ` <bTQ6f-7Qs-1@gated-at.bofh.it>
     [not found]             ` <bTQpv-5o-3@gated-at.bofh.it>
     [not found]               ` <bTQzd-iK-5@gated-at.bofh.it>
     [not found]                 ` <bTXhp-2IA-31@gated-at.bofh.it>
     [not found]                   ` <bTZjb-62D-25@gated-at.bofh.it>
2009-01-17 15:21                     ` Linux killed Kenny, bastard! Bodo Eggert
2009-01-17 15:41                       ` Evgeniy Polyakov
2009-01-18 12:49                         ` Bodo Eggert
2009-01-18 13:17                           ` Evgeniy Polyakov
2009-01-13 10:58 Tomasz Chmielewski
2009-01-13 12:20 ` Evgeniy Polyakov
  -- strict thread matches above, loose matches on Subject: below --
2009-01-12 15:33 Evgeniy Polyakov
2009-01-12 15:44 ` Dave Jones
2009-01-12 15:48   ` Evgeniy Polyakov
2009-01-12 15:51     ` Alan Cox
2009-01-12 15:52       ` Evgeniy Polyakov
2009-01-12 21:29         ` Chris Snook
2009-01-12 21:42           ` Evgeniy Polyakov
2009-01-12 15:49 ` Alan Cox
2009-01-12 15:50   ` Evgeniy Polyakov
2009-01-12 15:52     ` Alan Cox
2009-01-12 15:56       ` Evgeniy Polyakov
2009-01-12 16:19         ` Alan Cox
2009-01-12 16:29           ` Evgeniy Polyakov
2009-01-12 23:00             ` Bill Davidsen
2009-01-12 23:17               ` Evgeniy Polyakov
2009-01-13  1:53                 ` David Rientjes
2009-01-13  8:52                   ` Evgeniy Polyakov
2009-01-13  9:54                     ` David Rientjes
2009-01-13 11:54                       ` Evgeniy Polyakov
2009-01-13 12:15                         ` Alan Cox
2009-01-13 12:29                           ` Evgeniy Polyakov
2009-01-13 13:19                             ` Theodore Tso
2009-01-13 13:35                               ` Evgeniy Polyakov
2009-01-14  0:24                                 ` Bill Davidsen
2009-01-14  0:35                                   ` Evgeniy Polyakov
2009-01-13 13:47                               ` Alan Cox
2009-01-13 19:36                             ` David Rientjes
2009-01-13 21:46                               ` Evgeniy Polyakov
2009-01-13 22:49                                 ` Theodore Tso
2009-01-13 23:02                                   ` Evgeniy Polyakov
2009-01-14  1:11                                     ` Theodore Tso
2009-01-14  1:20                                       ` Evgeniy Polyakov
2009-01-14  4:06                                         ` Theodore Tso
2009-01-13 23:10                                 ` David Rientjes
2009-01-13 23:35                                   ` Evgeniy Polyakov
2009-01-13 23:43                                     ` David Rientjes
2009-01-13 23:55                                       ` Evgeniy Polyakov
2009-01-14  0:32                                         ` David Rientjes
2009-01-14  0:53                                           ` Evgeniy Polyakov
2009-01-14  4:23                                     ` Valdis.Kletnieks
2009-01-14  9:07                                       ` Evgeniy Polyakov
2009-01-13 19:15                         ` David Rientjes
2009-01-13 22:00                           ` Evgeniy Polyakov
2009-01-13 23:26                         ` Valdis.Kletnieks
2009-01-13 23:36                           ` Evgeniy Polyakov
2009-01-13 13:41                       ` Jan-Frode Myklebust
2009-01-13 13:59                         ` Alan Cox
2009-01-12 16:22         ` Dave Jones
2009-01-12 16:28           ` Evgeniy Polyakov
2009-01-13 16:35 ` KOSAKI Motohiro
2009-01-13 22:04   ` Evgeniy Polyakov

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