From mboxrd@z Thu Jan 1 00:00:00 1970 From: KOSAKI Motohiro Subject: Re: [patch v2] oom, memcg: fix exclusion of memcg threads after they have detached their mm Date: Thu, 15 Dec 2011 09:19:33 -0500 Message-ID: <4EEA01F5.6080301@jp.fujitsu.com> References: <20111214102942.GA11786@tiehlicka.suse.cz> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" To: rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org Cc: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org, hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org, bsingharora-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org, mhocko-AlSwsSmVLrQ@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org On 12/14/2011 9:39 PM, David Rientjes wrote: > oom, memcg: fix exclusion of memcg threads after they have detached their mm > > The oom killer relies on logic that identifies threads that have already > been oom killed when scanning the tasklist and, if found, deferring until > such threads have exited. This is done by checking for any candidate > threads that have the TIF_MEMDIE bit set. > > For memcg ooms, candidate threads are first found by calling > task_in_mem_cgroup() since the oom killer should not defer if there's an > oom killed thread in another memcg. > > Unfortunately, task_in_mem_cgroup() excludes threads if they have > detached their mm in the process of exiting so TIF_MEMDIE is never > detected for such conditions. This is different for global, mempolicy, > and cpuset oom conditions where a detached mm is only excluded after > checking for TIF_MEMDIE and deferring, if necessary, in > select_bad_process(). > > The fix is to return true if a task has a detached mm but is still in the > memcg or its hierarchy that is currently oom. This will allow the oom > killer to appropriately defer rather than kill unnecessarily or, in the > worst case, panic the machine if nothing else is available to kill. > > Signed-off-by: David Rientjes > --- > mm/memcontrol.c | 17 +++++++++++++---- > 1 files changed, 13 insertions(+), 4 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -1109,10 +1109,19 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg) > struct task_struct *p; > > p = find_lock_task_mm(task); > - if (!p) > - return 0; > - curr = try_get_mem_cgroup_from_mm(p->mm); > - task_unlock(p); > + if (p) { > + curr = try_get_mem_cgroup_from_mm(p->mm); > + task_unlock(p); > + } else { > + /* > + * All threads may have already detached their mm's, but the oom > + * killer still needs to detect if they have already been oom > + * killed to prevent needlessly killing additional tasks. > + */ > + curr = mem_cgroup_from_task(task); > + if (curr) > + css_get(&curr->css); > + } Acked-by: KOSAKI Motohiro -- To unsubscribe from this list: send the line "unsubscribe cgroups" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx144.postini.com [74.125.245.144]) by kanga.kvack.org (Postfix) with SMTP id 3663E6B0080 for ; Thu, 15 Dec 2011 09:19:49 -0500 (EST) Message-ID: <4EEA01F5.6080301@jp.fujitsu.com> Date: Thu, 15 Dec 2011 09:19:33 -0500 From: KOSAKI Motohiro MIME-Version: 1.0 Subject: Re: [patch v2] oom, memcg: fix exclusion of memcg threads after they have detached their mm References: <20111214102942.GA11786@tiehlicka.suse.cz> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: rientjes@google.com Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, bsingharora@gmail.com, kamezawa.hiroyu@jp.fujitsu.com, mhocko@suse.cz, cgroups@vger.kernel.org, linux-mm@kvack.org On 12/14/2011 9:39 PM, David Rientjes wrote: > oom, memcg: fix exclusion of memcg threads after they have detached their mm > > The oom killer relies on logic that identifies threads that have already > been oom killed when scanning the tasklist and, if found, deferring until > such threads have exited. This is done by checking for any candidate > threads that have the TIF_MEMDIE bit set. > > For memcg ooms, candidate threads are first found by calling > task_in_mem_cgroup() since the oom killer should not defer if there's an > oom killed thread in another memcg. > > Unfortunately, task_in_mem_cgroup() excludes threads if they have > detached their mm in the process of exiting so TIF_MEMDIE is never > detected for such conditions. This is different for global, mempolicy, > and cpuset oom conditions where a detached mm is only excluded after > checking for TIF_MEMDIE and deferring, if necessary, in > select_bad_process(). > > The fix is to return true if a task has a detached mm but is still in the > memcg or its hierarchy that is currently oom. This will allow the oom > killer to appropriately defer rather than kill unnecessarily or, in the > worst case, panic the machine if nothing else is available to kill. > > Signed-off-by: David Rientjes > --- > mm/memcontrol.c | 17 +++++++++++++---- > 1 files changed, 13 insertions(+), 4 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -1109,10 +1109,19 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg) > struct task_struct *p; > > p = find_lock_task_mm(task); > - if (!p) > - return 0; > - curr = try_get_mem_cgroup_from_mm(p->mm); > - task_unlock(p); > + if (p) { > + curr = try_get_mem_cgroup_from_mm(p->mm); > + task_unlock(p); > + } else { > + /* > + * All threads may have already detached their mm's, but the oom > + * killer still needs to detect if they have already been oom > + * killed to prevent needlessly killing additional tasks. > + */ > + curr = mem_cgroup_from_task(task); > + if (curr) > + css_get(&curr->css); > + } Acked-by: KOSAKI Motohiro -- 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