From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754507AbcEZPfg (ORCPT ); Thu, 26 May 2016 11:35:36 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36415 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754129AbcEZPff (ORCPT ); Thu, 26 May 2016 11:35:35 -0400 Date: Thu, 26 May 2016 17:35:32 +0200 From: Michal Hocko To: Tetsuo Handa Cc: linux-mm@kvack.org, rientjes@google.com, oleg@redhat.com, vdavydov@parallels.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/6] mm, oom: do not loop over all tasks if there are noexternal tasks sharing mm Message-ID: <20160526153532.GG23675@dhcp22.suse.cz> References: <1464266415-15558-1-git-send-email-mhocko@kernel.org> <1464266415-15558-2-git-send-email-mhocko@kernel.org> <201605262330.EEB52182.OtMFOJHFLOSFVQ@I-love.SAKURA.ne.jp> <20160526145930.GF23675@dhcp22.suse.cz> <201605270025.IAC48454.QSHOOMFOLtFJFV@I-love.SAKURA.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201605270025.IAC48454.QSHOOMFOLtFJFV@I-love.SAKURA.ne.jp> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 27-05-16 00:25:23, Tetsuo Handa wrote: > Michal Hocko wrote: > > On Thu 26-05-16 23:30:06, Tetsuo Handa wrote: > > > Michal Hocko wrote: > > > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > > > > index 5bb2f7698ad7..0e33e912f7e4 100644 > > > > --- a/mm/oom_kill.c > > > > +++ b/mm/oom_kill.c > > > > @@ -820,6 +820,13 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p, > > > > task_unlock(victim); > > > > > > > > /* > > > > + * skip expensive iterations over all tasks if we know that there > > > > + * are no users outside of threads in the same thread group > > > > + */ > > > > + if (atomic_read(&mm->mm_users) <= get_nr_threads(victim)) > > > > + goto oom_reap; > > > > > > Is this really safe? Isn't it possible that victim thread's thread group has > > > more than atomic_read(&mm->mm_users) threads which are past exit_mm() and blocked > > > at exit_task_work() which are before __exit_signal() from release_task() from > > > exit_notify()? > > > > You are right. The race window between exit_mm and __exit_signal is > > really large. I thought about == check instead but that wouldn't work > > for the same reason, dang, it looked so promissing. > > > > Scratch this patch then. > > > > I think that remembering whether this mm might be shared between > multiple thread groups at clone() time (i.e. whether > clone(CLONE_VM without CLONE_SIGHAND) was ever requested on this mm) > is safe (given that that thread already got SIGKILL or is exiting). I was already playing with that idea but I didn't want to add anything to the fork path which is really hot. This patch is not really needed for the rest. It just felt like a nice optimization. I do not think it is worth deeper changes in the fast paths. > By the way, in oom_kill_process(), how (p->flags & PF_KTHREAD) case can > become true when process_shares_mm() is true? not sure I understand. But the PF_KTHREAD check is there to catch use_mm() usage by kernel threads. > Even if it can become true, > why can't we reap that mm? Is (p->flags & PF_KTHREAD) case only for > not to send SIGKILL rather than not to reap that mm? If we reaped the mm then the kernel thread could blow up when accessing a memory. -- Michal Hocko SUSE Labs