From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal Hocko Subject: Re: [patch v3] oom, memcg: fix exclusion of memcg threads after they have detached their mm Date: Fri, 16 Dec 2011 09:31:26 +0100 Message-ID: <20111216083126.GA3122@tiehlicka.suse.cz> References: <20111214102942.GA11786@tiehlicka.suse.cz> <20111215155926.GA22819@tiehlicka.suse.cz> Mime-Version: 1.0 Return-path: Content-Disposition: inline In-Reply-To: Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: David Rientjes Cc: Andrew Morton , Johannes Weiner , Balbir Singh , KAMEZAWA Hiroyuki , cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org On Thu 15-12-11 13:36:11, David Rientjes wrote: > 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. > > Acked-by: KOSAKI Motohiro > Signed-off-by: David Rientjes Yes, looks good. Thanks Acked-by: Michal Hocko > --- > mm/memcontrol.c | 19 +++++++++++++++---- > 1 files changed, 15 insertions(+), 4 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -1109,10 +1109,21 @@ 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. > + */ > + task_lock(task); > + curr = mem_cgroup_from_task(task); > + if (curr) > + css_get(&curr->css); > + task_unlock(task); > + } > if (!curr) > return 0; > /* > -- > 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 -- Michal Hocko SUSE Labs SUSE LINUX s.r.o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic -- 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