From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: CAI Qian <caiqian@redhat.com>,
avagin@gmail.com, Andrey Vagin <avagin@openvz.org>,
Andrew Morton <akpm@linux-foundation.org>,
Mel Gorman <mel@csn.ul.ie>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Minchan Kim <minchan.kim@gmail.com>,
David Rientjes <rientjes@google.com>,
Hugh Dickins <hughd@google.com>, Oleg Nesterov <oleg@redhat.com>
Subject: [PATCH 4/4] oom: don't kill random process
Date: Tue, 10 May 2011 17:16:21 +0900 (JST) [thread overview]
Message-ID: <20110510171800.16B7.A69D9226@jp.fujitsu.com> (raw)
In-Reply-To: <20110510171335.16A7.A69D9226@jp.fujitsu.com>
CAI Qian reported oom-killer killed all system daemons in his
system at first if he ran fork bomb as root. The problem is,
current logic give them bonus of 3% of system ram. Example,
he has 16GB machine, then root processes have ~500MB oom
immune. It bring us crazy bad result. _all_ processes have
oom-score=1 and then, oom killer ignore process memroy usage
and kill random process. This regression is caused by commit
a63d83f427 (oom: badness heuristic rewrite).
This patch changes select_bad_process() slightly. If oom points == 1,
it's a sign that the system have only root privileged processes or
similar. Thus, select_bad_process() calculate oom badness without
root bonus and select eligible process.
Reported-by: CAI Qian <caiqian@redhat.com>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
fs/proc/base.c | 2 +-
include/linux/oom.h | 3 ++-
mm/oom_kill.c | 19 +++++++++++++++----
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index d6b0424..b608b69 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -482,7 +482,7 @@ static int proc_oom_score(struct task_struct *task, char *buffer)
read_lock(&tasklist_lock);
if (pid_alive(task)) {
- points = oom_badness(task, NULL, NULL, totalpages);
+ points = oom_badness(task, NULL, NULL, totalpages, 1);
ratio = points * 1000 / totalpages;
}
read_unlock(&tasklist_lock);
diff --git a/include/linux/oom.h b/include/linux/oom.h
index 0f5b588..3dd3669 100644
--- a/include/linux/oom.h
+++ b/include/linux/oom.h
@@ -42,7 +42,8 @@ enum oom_constraint {
/* The badness from the OOM killer */
extern unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *mem,
- const nodemask_t *nodemask, unsigned long totalpages);
+ const nodemask_t *nodemask, unsigned long totalpages,
+ int protect_root);
extern int try_set_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
extern void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index ba95870..525e1d2 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -133,7 +133,8 @@ static bool oom_unkillable_task(struct task_struct *p,
* task consuming the most memory to avoid subsequent oom failures.
*/
unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *mem,
- const nodemask_t *nodemask, unsigned long totalpages)
+ const nodemask_t *nodemask, unsigned long totalpages,
+ int protect_root)
{
unsigned long points;
unsigned long score_adj = 0;
@@ -186,7 +187,7 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *mem,
*
* XXX: Too large bonus. Example,if the system have tera-bytes memory...
*/
- if (has_capability_noaudit(p, CAP_SYS_ADMIN)) {
+ if (protect_root && has_capability_noaudit(p, CAP_SYS_ADMIN)) {
if (points >= totalpages / 32)
points -= totalpages / 32;
else
@@ -298,8 +299,10 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
{
struct task_struct *g, *p;
struct task_struct *chosen = NULL;
+ int protect_root = 1;
*ppoints = 0;
+ retry:
do_each_thread_reverse(g, p) {
unsigned long points;
@@ -345,13 +348,18 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
}
}
- points = oom_badness(p, mem, nodemask, totalpages);
+ points = oom_badness(p, mem, nodemask, totalpages, protect_root);
if (points > *ppoints) {
chosen = p;
*ppoints = points;
}
} while_each_thread(g, p);
+ if (protect_root && (*ppoints == 1)) {
+ protect_root = 0;
+ goto retry;
+ }
+
return chosen;
}
@@ -470,6 +478,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
struct task_struct *child;
struct task_struct *t = p;
unsigned long victim_points = 0;
+ int admin;
if (printk_ratelimit())
dump_header(p, gfp_mask, order, mem, nodemask);
@@ -494,6 +503,8 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
* parent. This attempts to lose the minimal amount of work done while
* still freeing memory.
*/
+ admin = has_capability_noaudit(victim, CAP_SYS_ADMIN);
+ victim_points = oom_badness(victim, mem, nodemask, totalpages, !admin);
do {
list_for_each_entry(child, &t->children, sibling) {
unsigned long child_points;
@@ -504,7 +515,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
* oom_badness() returns 0 if the thread is unkillable
*/
child_points = oom_badness(child, mem, nodemask,
- totalpages);
+ totalpages, !admin);
if (child_points > victim_points) {
victim = child;
victim_points = child_points;
--
1.7.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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-05-10 8:16 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-05 11:44 [PATCH] mm: check zone->all_unreclaimable in all_unreclaimable() Andrey Vagin
2011-03-05 15:20 ` Minchan Kim
2011-03-05 15:34 ` Andrew Vagin
2011-03-05 15:53 ` Minchan Kim
2011-03-05 16:41 ` Andrew Vagin
2011-03-05 17:07 ` Minchan Kim
2011-03-07 21:58 ` Andrew Morton
2011-03-07 23:45 ` Minchan Kim
2011-03-09 5:37 ` KAMEZAWA Hiroyuki
2011-03-09 5:43 ` KAMEZAWA Hiroyuki
2011-03-10 6:58 ` Minchan Kim
2011-03-10 23:58 ` KAMEZAWA Hiroyuki
2011-03-11 0:18 ` Minchan Kim
2011-03-11 6:08 ` avagin
2011-03-14 1:03 ` Minchan Kim
2011-03-08 0:44 ` KAMEZAWA Hiroyuki
2011-03-08 3:06 ` KOSAKI Motohiro
2011-03-08 19:02 ` avagin
2011-03-09 5:52 ` KAMEZAWA Hiroyuki
2011-03-09 6:17 ` KOSAKI Motohiro
2011-03-10 14:08 ` KOSAKI Motohiro
2011-03-08 8:12 ` Andrew Vagin
2011-03-09 6:06 ` KAMEZAWA Hiroyuki
2011-05-04 1:38 ` CAI Qian
2011-05-09 6:54 ` KOSAKI Motohiro
2011-05-09 8:47 ` CAI Qian
2011-05-09 9:19 ` KOSAKI Motohiro
2011-05-10 8:11 ` OOM Killer don't works at all if the system have >gigabytes memory (was Re: [PATCH] mm: check zone->all_unreclaimable in all_unreclaimable()) KOSAKI Motohiro
2011-05-10 8:14 ` [PATCH 1/4] oom: improve dump_tasks() show items KOSAKI Motohiro
2011-05-10 23:29 ` David Rientjes
2011-05-13 10:14 ` KOSAKI Motohiro
2011-05-10 8:15 ` [PATCH 2/4] oom: kill younger process first KOSAKI Motohiro
2011-05-10 23:31 ` David Rientjes
2011-05-13 10:15 ` KOSAKI Motohiro
2011-05-11 23:33 ` Minchan Kim
2011-05-12 0:52 ` KAMEZAWA Hiroyuki
2011-05-12 1:30 ` Minchan Kim
2011-05-12 1:53 ` KAMEZAWA Hiroyuki
2011-05-12 2:23 ` Minchan Kim
2011-05-12 3:39 ` KAMEZAWA Hiroyuki
2011-05-12 4:17 ` Minchan Kim
2011-05-12 14:38 ` Paul E. McKenney
2011-05-13 10:18 ` KOSAKI Motohiro
2011-05-10 8:15 ` [PATCH 3/4] oom: oom-killer don't use permillage of system-ram internally KOSAKI Motohiro
2011-05-10 23:40 ` David Rientjes
2011-05-13 10:30 ` KOSAKI Motohiro
2011-05-10 8:16 ` KOSAKI Motohiro [this message]
2011-05-10 23:41 ` [PATCH 4/4] oom: don't kill random process David Rientjes
2011-05-10 23:22 ` OOM Killer don't works at all if the system have >gigabytes memory (was Re: [PATCH] mm: check zone->all_unreclaimable in all_unreclaimable()) David Rientjes
2011-05-11 2:30 ` CAI Qian
2011-05-11 20:34 ` David Rientjes
2011-05-12 0:13 ` Minchan Kim
2011-05-12 19:38 ` David Rientjes
2011-05-13 4:16 ` Minchan Kim
2011-05-13 11:04 ` KOSAKI Motohiro
2011-05-16 20:42 ` David Rientjes
2011-05-13 6:53 ` CAI Qian
2011-05-16 20:46 ` David Rientjes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110510171800.16B7.A69D9226@jp.fujitsu.com \
--to=kosaki.motohiro@jp.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@gmail.com \
--cc=avagin@openvz.org \
--cc=caiqian@redhat.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mel@csn.ul.ie \
--cc=minchan.kim@gmail.com \
--cc=oleg@redhat.com \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox