From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail202.messagelabs.com (mail202.messagelabs.com [216.82.254.227]) by kanga.kvack.org (Postfix) with SMTP id AB5B38D003A for ; Sat, 12 Mar 2011 08:53:15 -0500 (EST) Date: Sat, 12 Mar 2011 14:44:33 +0100 From: Oleg Nesterov Subject: [PATCH 2/3] oom: select_bad_process: improve the PF_EXITING check Message-ID: <20110312134433.GC27275@redhat.com> References: <20110303100030.B936.A69D9226@jp.fujitsu.com> <20110308134233.GA26884@redhat.com> <20110309151946.dea51cde.akpm@linux-foundation.org> <20110312123413.GA18351@redhat.com> <20110312134341.GA27275@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110312134341.GA27275@redhat.com> Sender: owner-linux-mm@kvack.org List-ID: To: Andrew Morton Cc: KOSAKI Motohiro , KAMEZAWA Hiroyuki , Hugh Dickins , linux-mm@kvack.org, Andrey Vagin , David Rientjes The current PF_EXITING check in select_bad_process() is very limited, it only works if the task is single-threaded. Add the new helper which tries to handle the mt case. It is not exactly clear what should we actually check in this case. This patch checks PF_EXITING, but perhaps we can take signal_group_exit() into account. In this case select_bad_process() could detect the exiting process even before every thread calls exit(). Note: - "if (p != current)" check is obviously wrong in mt case too. - with or without this change, we should probably check mm->core_state == NULL. We shouldn't assume that is is going to exit "soon" otherwise. But this needs other changes anyway, and in the common case when we do not share ->mm with another process the false positive is not possible. Signed-off-by: Oleg Nesterov --- mm/oom_kill.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) --- 38/mm/oom_kill.c~detect_exiting 2011-03-12 14:20:42.000000000 +0100 +++ 38/mm/oom_kill.c 2011-03-12 14:22:19.000000000 +0100 @@ -282,6 +282,22 @@ static enum oom_constraint constrained_a } #endif +static bool mm_is_exiting(struct task_struct *p) +{ + struct task_struct *t; + bool has_mm = false; + + t = p; + do { + if (!(t->flags & PF_EXITING)) + return false; + if (t->mm) + has_mm = true; + } while_each_thread(p, t); + + return has_mm; +} + /* * Simple selection loop. We chose the process with the highest * number of 'points'. We expect the caller will lock the tasklist. @@ -324,7 +340,7 @@ static struct task_struct *select_bad_pr * the process of exiting and releasing its resources. * Otherwise we could get an easy OOM deadlock. */ - if (thread_group_empty(p) && (p->flags & PF_EXITING) && p->mm) { + if (mm_is_exiting(p)) { if (p != current) return ERR_PTR(-1UL); -- 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: email@kvack.org