Skip to contentSkip to conversation

oom: do not kill tasks with oom_score_adj OOM_SCORE_ADJ_MIN

PATCH Superseded Michal Hocko 3 participants 4 messages Nov 4, 2011 – Nov 7, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oom: do not kill tasks with oom_score_adj OOM_SCORE_ADJ_MIN

c9f01245 (oom: remove oom_disable_count) has removed oom_disable_count counter which has been used for early break out from oom_badness so we could never select a task with oom_score_adj set to OOM_SCORE_ADJ_MIN (oom disabled).

Now that the counter is gone we are always going through heuristics calculation and we always return a non zero positive value. This means that we can end up killing a task with OOM disabled because it is indistinguishable from regular tasks with 1% resp. CAP_SYS_ADMIN tasks with 3% usage of memory or tasks with oom_score_adj set but OOM enabled.

Let's break out early if the task should have OOM disabled.

---
 mm/oom_kill.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
mm/oom_kill.c +3 -0
index e916168..4883514 100644
@@ -185,6 +185,9 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
 	if (!p)
 		return 0;
 
+	if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
+		return 0;
+
 	/*
 	 * The memory controller may have a limit of 0 bytes, so avoid a divide
 	 * by zero, if necessary.
Signature · 8 lines
1.7.7

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  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:"[email protected]"> [email protected] </a>
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Michal Hocko
mm/oom_kill.c +0 -0
index e916168..4883514 100644

mm/oom_kill.c unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem, · line 193

Quoted 9 lines
mm/oom_kill.c +3 -0
@@ -185,6 +185,9 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
 	if (!p)
 		return 0;
 
+	if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
+		return 0;
+
 	/*
 	 * The memory controller may have a limit of 0 bytes, so avoid a divide
 	 * by zero, if necessary.

This leaves p locked, you need to do task_unlock(p) first.

Once that's fixed, please add my

and resubmit to Andrew for the 3.2 rc series. Thanks!

author Acked-by David Rientjes
#2 lore raw
Quoted 10 lines · David Rientjes
Quoted 8 lines · Michal Hocko
mm/oom_kill.c +0 -0
index e916168..4883514 100644
@@ -185,6 +185,9 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
 	if (!p)
 		return 0;
 
Quoted 8 lines

mm/oom_kill.c unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem, · line 193

Quoted 6 lines
mm/oom_kill.c +3 -0
+	if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
+		return 0;
+
 	/*
 	 * The memory controller may have a limit of 0 bytes, so avoid a divide
 	 * by zero, if necessary.

This leaves p locked, you need to do task_unlock(p) first.

Yes, right you are. Thanks for spotting this out.

Quoted 4 lines

Once that's fixed, please add my

Thanks.

Quoted 1 line

and resubmit to Andrew for the 3.2 rc series. Thanks!

Andrew, could you push this for 3.2 (bugfix for post 3.1 kernel).

---

Quoted 1 line

From 10e06e7c0682af58236055ed38bfab58f7935253 Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Fri, 4 Nov 2011 12:59:44 +0100
Subject: [PATCH] oom: do not kill tasks with oom_score_adj OOM_SCORE_ADJ_MIN
To: David Rientjes <[email protected]>
Cc: [email protected],
[email protected],
Oleg Nesterov <[email protected]>,
Ying Han <[email protected]>,
KOSAKI Motohiro <[email protected]>,
Andrew Morton <[email protected]>

c9f01245 (oom: remove oom_disable_count) has removed oom_disable_count counter which has been used for early break out from oom_badness so we could never select a task with oom_score_adj set to OOM_SCORE_ADJ_MIN (oom disabled).

Now that the counter is gone we are always going through heuristics calculation and we always return a non zero positive value. This means that we can end up killing a task with OOM disabled because it is indistinguishable from regular tasks with 1% resp. CAP_SYS_ADMIN tasks with 3% usage of memory or tasks with oom_score_adj set but OOM enabled.

Let's break out early if the task should have OOM disabled.

---
 mm/oom_kill.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
mm/oom_kill.c +5 -0
index e916168..4465fb8 100644
@@ -185,6 +185,11 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
 	if (!p)
 		return 0;
 
+	if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN) {
+		task_unlock(p);
+		return 0;
+	}
+
 	/*
 	 * The memory controller may have a limit of 0 bytes, so avoid a divide
 	 * by zero, if necessary.
Signature · 9 lines
1.7.7.1

-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic
#3 lore raw
In reply to David Rientjes
Quoted 19 lines · David Rientjes
Quoted 5 lines · Michal Hocko
mm/oom_kill.c +0 -0
index e916168..4883514 100644

mm/oom_kill.c unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem, · line 193

Quoted 9 lines
mm/oom_kill.c +3 -0
@@ -185,6 +185,9 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
 	if (!p)
 		return 0;
 
+	if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
+		return 0;
+
 	/*
 	 * The memory controller may have a limit of 0 bytes, so avoid a divide
 	 * by zero, if necessary.

This leaves p locked, you need to do task_unlock(p) first.

Quoted 3 lines

Once that's fixed, please add my

Agreed.