From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail203.messagelabs.com (mail203.messagelabs.com [216.82.254.243]) by kanga.kvack.org (Postfix) with SMTP id 2B1E26B007B for ; Sun, 14 Feb 2010 22:08:39 -0500 (EST) Received: from m4.gw.fujitsu.co.jp ([10.0.50.74]) by fgwmail7.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id o1F38aaa017972 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Mon, 15 Feb 2010 12:08:36 +0900 Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 3714D45DE7C for ; Mon, 15 Feb 2010 12:08:36 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id F259545DE6E for ; Mon, 15 Feb 2010 12:08:35 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id CD5D11DB8040 for ; Mon, 15 Feb 2010 12:08:35 +0900 (JST) Received: from m105.s.css.fujitsu.com (m105.s.css.fujitsu.com [10.249.87.105]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 73B021DB803A for ; Mon, 15 Feb 2010 12:08:35 +0900 (JST) From: KOSAKI Motohiro Subject: Re: [patch 2/7 -mm] oom: sacrifice child with highest badness score for parent In-Reply-To: References: Message-Id: <20100215120645.727E.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Mon, 15 Feb 2010 12:08:34 +0900 (JST) Sender: owner-linux-mm@kvack.org To: David Rientjes Cc: kosaki.motohiro@jp.fujitsu.com, Andrew Morton , Rik van Riel , KAMEZAWA Hiroyuki , Nick Piggin , Andrea Arcangeli , Balbir Singh , Lubos Lunak , linux-kernel@vger.kernel.org, linux-mm@kvack.org List-ID: > When a task is chosen for oom kill, the oom killer first attempts to > sacrifice a child not sharing its parent's memory instead. > Unfortunately, this often kills in a seemingly random fashion based on > the ordering of the selected task's child list. Additionally, it is not > guaranteed at all to free a large amount of memory that we need to > prevent additional oom killing in the very near future. > > Instead, we now only attempt to sacrifice the worst child not sharing its > parent's memory, if one exists. The worst child is indicated with the > highest badness() score. This serves two advantages: we kill a > memory-hogging task more often, and we allow the configurable > /proc/pid/oom_adj value to be considered as a factor in which child to > kill. > > Reviewers may observe that the previous implementation would iterate > through the children and attempt to kill each until one was successful > and then the parent if none were found while the new code simply kills > the most memory-hogging task or the parent. Note that the only time > oom_kill_task() fails, however, is when a child does not have an mm or > has a /proc/pid/oom_adj of OOM_DISABLE. badness() returns 0 for both > cases, so the final oom_kill_task() will always succeed. > > Signed-off-by: David Rientjes Probably, kamezawa-san talked about right thing. but this patch is enough small and it have no regression risk. So, we can choice step-by-step development. Reviewed-by: KOSAKI Motohiro > --- > mm/oom_kill.c | 23 +++++++++++++++++------ > 1 files changed, 17 insertions(+), 6 deletions(-) > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -432,7 +432,10 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, > unsigned long points, struct mem_cgroup *mem, > const char *message) > { > + struct task_struct *victim = p; > struct task_struct *c; > + unsigned long victim_points = 0; > + struct timespec uptime; > > if (printk_ratelimit()) > dump_header(p, gfp_mask, order, mem); > @@ -446,17 +449,25 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, > return 0; > } > > - printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n", > - message, task_pid_nr(p), p->comm, points); > + pr_err("%s: Kill process %d (%s) with score %lu or sacrifice child\n", > + message, task_pid_nr(p), p->comm, points); > > - /* Try to kill a child first */ > + /* Try to sacrifice the worst child first */ > + do_posix_clock_monotonic_gettime(&uptime); > list_for_each_entry(c, &p->children, sibling) { > + unsigned long cpoints; > + > if (c->mm == p->mm) > continue; > - if (!oom_kill_task(c)) > - return 0; > + > + /* badness() returns 0 if the thread is unkillable */ > + cpoints = badness(c, uptime.tv_sec); > + if (cpoints > victim_points) { > + victim = c; > + victim_points = cpoints; > + } > } > - return oom_kill_task(p); > + return oom_kill_task(victim); > } > > #ifdef CONFIG_CGROUP_MEM_RES_CTLR > > -- > 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: email@kvack.org -- 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: email@kvack.org