From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751379AbbJERjS (ORCPT ); Mon, 5 Oct 2015 13:39:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57061 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750737AbbJERjR (ORCPT ); Mon, 5 Oct 2015 13:39:17 -0400 Date: Mon, 5 Oct 2015 19:36:01 +0200 From: Oleg Nesterov To: Andrew Morton Cc: David Rientjes , Kyle Walker , Michal Hocko , Stanislav Kozina , Tetsuo Handa , linux-kernel@vger.kernel.org Subject: Re: [PATCH -mm] mm/oom_kill: change oom_kill_process() to bump ->mm_count rather than ->mm_users Message-ID: <20151005173601.GA23150@redhat.com> References: <20151005163427.GA20595@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151005163427.GA20595@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/05, Oleg Nesterov wrote: > > oom_kill_process() does atomic_inc(&mm->mm_users) to ensure that > this ->mm can't go away and this is wrong, change it to rely on > ->mm_count and mmdrop(). > > Firstly, we do not want to delay exit_mmap/etc if the victim exits > before we do mmput(), but this is minor. > > More importantly, we simply can not do mmput() in oom_kill_process(), > this can deadlock. For example, suppose that access_process_vm(tsk) > triggers OOM and oom-killer decides to kill this "tsk". If it exits > and does mmput() before us, ksm_exit() called by us may want to want > to take the same mmap_sem for writing. Self nack to the changelog ;) I still think the patch is fine, I'll resend it. But the changelog is wrong, in the case above access_process_vm() adds another reference to ->mm_users, so mmput() can never lead to mm_users == 0. > Signed-off-by: Oleg Nesterov > --- > mm/oom_kill.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > index 034d219..52abb78 100644 > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -571,7 +571,7 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p, > > /* Get a reference to safely compare mm after task_unlock(victim) */ > mm = victim->mm; > - atomic_inc(&mm->mm_users); > + atomic_inc(&mm->mm_count); > /* > * We should send SIGKILL before setting TIF_MEMDIE in order to prevent > * the OOM victim from depleting the memory reserves from the user > @@ -609,7 +609,7 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p, > } > rcu_read_unlock(); > > - mmput(mm); > + mmdrop(mm); > put_task_struct(victim); > } > #undef K > -- > 2.4.3 >