From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw0-f200.google.com (mail-yw0-f200.google.com [209.85.161.200]) by kanga.kvack.org (Postfix) with ESMTP id B4A936B007E for ; Mon, 30 May 2016 13:35:10 -0400 (EDT) Received: by mail-yw0-f200.google.com with SMTP id i185so187157746ywg.3 for ; Mon, 30 May 2016 10:35:10 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id x44si23451066qtb.108.2016.05.30.10.35.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 10:35:09 -0700 (PDT) Date: Mon, 30 May 2016 19:35:05 +0200 From: Oleg Nesterov Subject: Re: [PATCH 6/6] mm, oom: fortify task_will_free_mem Message-ID: <20160530173505.GA25287@redhat.com> References: <1464613556-16708-1-git-send-email-mhocko@kernel.org> <1464613556-16708-7-git-send-email-mhocko@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1464613556-16708-7-git-send-email-mhocko@kernel.org> Sender: owner-linux-mm@kvack.org List-ID: To: Michal Hocko Cc: linux-mm@kvack.org, Tetsuo Handa , David Rientjes , Vladimir Davydov , Andrew Morton , LKML , Michal Hocko On 05/30, Michal Hocko wrote: > > task_will_free_mem is rather weak. I was thinking about the similar change because I noticed that try_oom_reaper() is very, very wrong. To the point I think that we need another change for stable which simply removes spin_lock_irq(sighand->siglock) from try_oom_reaper(). It buys nothing, we can check signal_group_exit() (which is wrong too ;) lockless, and at the same time the kernel can crash because we can hit ->siglock == NULL. So I do think this change is good in general. I think that task_will_free_mem() should be un-inlined, and __task_will_free_mem() should go into mm/oom-kill.c... but this is minor. > -static inline bool task_will_free_mem(struct task_struct *task) > +static inline bool __task_will_free_mem(struct task_struct *task) > { > struct signal_struct *sig = task->signal; > > @@ -119,16 +119,69 @@ static inline bool task_will_free_mem(struct task_struct *task) > if (sig->flags & SIGNAL_GROUP_COREDUMP) > return false; > > - if (!(task->flags & PF_EXITING)) > + if (!(task->flags & PF_EXITING || fatal_signal_pending(task))) > return false; > > /* Make sure that the whole thread group is going down */ > - if (!thread_group_empty(task) && !(sig->flags & SIGNAL_GROUP_EXIT)) > + if (!thread_group_empty(task) && > + !(sig->flags & SIGNAL_GROUP_EXIT || fatal_signal_pending(task))) > return false; > > return true; > } Well, let me suggest this again. I think it should do if (SIGNAL_GROUP_COREDUMP) return false; if (SIGNAL_GROUP_EXIT) return true; if (thread_group_empty() && PF_EXITING) return true; return false; we do not need fatal_signal_pending(), in this case SIGNAL_GROUP_EXIT should be set (ignoring some bugs with sub-namespaces which we need to fix anyway). At the same time, we do not want to return false if PF_EXITING is not set if SIGNAL_GROUP_EXIT is set. > +static inline bool task_will_free_mem(struct task_struct *task) > +{ > + struct mm_struct *mm = NULL; > + struct task_struct *p; > + bool ret; > + > + /* > + * If the process has passed exit_mm we have to skip it because > + * we have lost a link to other tasks sharing this mm, we do not > + * have anything to reap and the task might then get stuck waiting > + * for parent as zombie and we do not want it to hold TIF_MEMDIE > + */ > + p = find_lock_task_mm(task); > + if (!p) > + return false; > + > + if (!__task_will_free_mem(p)) { > + task_unlock(p); > + return false; > + } > + > + mm = p->mm; > + if (atomic_read(&mm->mm_users) <= 1) { this is sub-optimal, we should probably take signal->live or ->nr_threads into account... but OK, we can do this later. > + rcu_read_lock(); > + for_each_process(p) { > + ret = __task_will_free_mem(p); > + if (!ret) > + break; > + } > + rcu_read_unlock(); Yes, I agree very much. But it seems you forgot to add the process_shares_mm() check into this loop? and perhaps it also makes sense to add if (same_thread_group(tsk, p)) continue; This should not really matter, we know that __task_will_free_mem(p) should return true. Just to make it more clear. And. I think this needs smp_rmb() at the end of the loop (assuming we have the process_shares_mm() check here). We need it to ensure that we read p->mm before we read next_task(), to avoid the race with exit() + clone(CLONE_VM). Oleg. -- 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