[PATCH 2/2] oom: give bonus to frozen processes

From: Michal Hocko
Date: Fri Sep 16 2011 - 09:51:25 EST


We do not want to kill frozen processes if there are some processes that
could be killed instead. Frozen tasks are in uninterruptible sleep and
somebody might rely on that.
Let's give those tasks a bonus so that they would be selected only when
really necessary. The size of the bonus is questionable but let's start
with the same bonus we give to root processes.

Signed-off-by: Michal Hocko <mhocko@xxxxxxx>
---
include/linux/oom.h | 6 ++++++
mm/oom_kill.c | 10 +++++++++-
2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/include/linux/oom.h b/include/linux/oom.h
index 13b7b02e..960e2de 100644
--- a/include/linux/oom.h
+++ b/include/linux/oom.h
@@ -13,6 +13,12 @@
#define OOM_ADJUST_MAX 15

/*
+ * Bonus (3%) for a task that shouldn't be killed unless necessary.
+ * We give this bonus to root and frozen tasks currently.
+ */
+#define OOM_BONUS 30
+
+/*
* /proc/<pid>/oom_score_adj set to OOM_SCORE_ADJ_MIN disables oom killing for
* pid.
*/
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index b9774f3..4aea1b3 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -205,7 +205,15 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
* implementation used by LSMs.
*/
if (has_capability_noaudit(p, CAP_SYS_ADMIN))
- points -= 30;
+ points -= OOM_BONUS;
+
+ /*
+ * Do not try to kill frozen tasks unless there is nothing else to kill.
+ * We do not want to give it 1 point because we still want to select a good
+ * candidate among all frozen tasks. Let's give it a reasonable bonus.
+ */
+ if (frozen(p))
+ points -= OOM_BONUS;

/*
* /proc/pid/oom_score_adj ranges from -1000 to +1000 such that it may
--
1.7.5.4


--
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/