linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V1] oom: avoid selecting threads sharing mm with init
@ 2013-09-26  8:09 Ming Liu
  2013-09-26 18:44 ` David Rientjes
  0 siblings, 1 reply; 4+ messages in thread
From: Ming Liu @ 2013-09-26  8:09 UTC (permalink / raw)
  To: akpm, rientjes, mhocko, rusty, hannes; +Cc: linux-mm, linux-kernel

It won't help free memory for killing tasks sharing mm with init, we should
skip them in oom_unkillable_task(), or we may risk init process getting
killed because after selecting a task to kill, the oom killer iterates all
processes and kills all other user threads that share the same mm_struct
in different thread groups.

In some extreme cases, the selected task happens to be a vfork child of
init process sharing the same mm_struct with it, which causes kernel
panic on init getting killed. This panic is observed in a busybox shell that
busybox itself is init, with a kthread keeps consuming memories.

Signed-off-by: Ming Liu <ming.liu@windriver.com>
---
 mm/oom_kill.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 314e9d2..7e50a95 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -113,11 +113,22 @@ struct task_struct *find_lock_task_mm(struct task_struct *p)
 static bool oom_unkillable_task(struct task_struct *p,
 		const struct mem_cgroup *memcg, const nodemask_t *nodemask)
 {
+	struct task_struct *init_tsk;
+
 	if (is_global_init(p))
 		return true;
 	if (p->flags & PF_KTHREAD)
 		return true;
 
+	/* It won't help free memory if p is sharing mm with init */
+	rcu_read_lock();
+	init_tsk = find_task_by_pid_ns(1, &init_pid_ns);
+	if(p->mm == init_tsk->mm) {
+		rcu_read_unlock();
+		return true;
+	}
+	rcu_read_unlock();
+
 	/* When mem_cgroup_out_of_memory() and p is not member of the group */
 	if (memcg && !task_in_mem_cgroup(p, memcg))
 		return true;
-- 
1.7.0.4

--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2013-10-02  3:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-26  8:09 [PATCH V1] oom: avoid selecting threads sharing mm with init Ming Liu
2013-09-26 18:44 ` David Rientjes
2013-09-27  2:04   ` Ming Liu
2013-10-02  3:52     ` David Rientjes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).