From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-it0-f70.google.com (mail-it0-f70.google.com [209.85.214.70]) by kanga.kvack.org (Postfix) with ESMTP id 6664E6B026B for ; Fri, 8 Dec 2017 04:26:50 -0500 (EST) Received: by mail-it0-f70.google.com with SMTP id x32so4323784ita.1 for ; Fri, 08 Dec 2017 01:26:50 -0800 (PST) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id e83sor3855498iof.47.2017.12.08.01.26.49 for (Google Transport Security); Fri, 08 Dec 2017 01:26:49 -0800 (PST) Date: Fri, 8 Dec 2017 01:26:46 -0800 (PST) From: David Rientjes Subject: Re: Multiple oom_reaper BUGs: unmap_page_range racing with exit_mmap In-Reply-To: Message-ID: References: <20171207113548.GG20234@dhcp22.suse.cz> <201712080044.BID56711.FFVOLMStJOQHOF@I-love.SAKURA.ne.jp> <20171207163003.GM20234@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-linux-mm@kvack.org List-ID: To: Michal Hocko Cc: Tetsuo Handa , akpm@linux-foundation.org, aarcange@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org On Thu, 7 Dec 2017, David Rientjes wrote: > I'm backporting and testing the following patch against Linus's tree. To > clarify an earlier point, we don't actually have any change from upstream > code that allows for free_pgtables() before the > set_bit(MMF_OOM_SKIP);down_write();up_write() cycle. > > diff --git a/include/linux/oom.h b/include/linux/oom.h > --- a/include/linux/oom.h > +++ b/include/linux/oom.h > @@ -66,6 +66,15 @@ static inline bool tsk_is_oom_victim(struct task_struct * tsk) > return tsk->signal->oom_mm; > } > > +/* > + * Use this helper if tsk->mm != mm and the victim mm needs a special > + * handling. This is guaranteed to stay true after once set. > + */ > +static inline bool mm_is_oom_victim(struct mm_struct *mm) > +{ > + return test_bit(MMF_OOM_VICTIM, &mm->flags); > +} > + > /* > * Checks whether a page fault on the given mm is still reliable. > * This is no longer true if the oom reaper started to reap the > diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h > --- a/include/linux/sched/coredump.h > +++ b/include/linux/sched/coredump.h > @@ -71,6 +71,7 @@ static inline int get_dumpable(struct mm_struct *mm) > #define MMF_HUGE_ZERO_PAGE 23 /* mm has ever used the global huge zero page */ > #define MMF_DISABLE_THP 24 /* disable THP for all VMAs */ > #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP) > +#define MMF_OOM_VICTIM 25 /* mm is the oom victim */ > > #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\ > MMF_DISABLE_THP_MASK) > diff --git a/mm/mmap.c b/mm/mmap.c > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -3019,20 +3019,20 @@ void exit_mmap(struct mm_struct *mm) > /* Use -1 here to ensure all VMAs in the mm are unmapped */ > unmap_vmas(&tlb, vma, 0, -1); > > - set_bit(MMF_OOM_SKIP, &mm->flags); > - if (unlikely(tsk_is_oom_victim(current))) { > + if (unlikely(mm_is_oom_victim(mm))) { > /* > * Wait for oom_reap_task() to stop working on this > * mm. Because MMF_OOM_SKIP is already set before > * calling down_read(), oom_reap_task() will not run > * on this "mm" post up_write(). > * > - * tsk_is_oom_victim() cannot be set from under us > + * mm_is_oom_victim() cannot be set from under us > * either because current->mm is already set to NULL > * under task_lock before calling mmput and oom_mm is > * set not NULL by the OOM killer only if current->mm > * is found not NULL while holding the task_lock. > */ > + set_bit(MMF_OOM_SKIP, &mm->flags); > down_write(&mm->mmap_sem); > up_write(&mm->mmap_sem); > } > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -683,8 +683,10 @@ static void mark_oom_victim(struct task_struct *tsk) > return; > > /* oom_mm is bound to the signal struct life time. */ > - if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) > + if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) { > mmgrab(tsk->signal->oom_mm); > + set_bit(MMF_OOM_VICTIM, &mm->flags); > + } > > /* > * Make sure that the task is woken up from uninterruptible sleep > This passes all functional testing that I have and I can create a synthetic testcase that can trigger at least MMF_OOM_VICTIM getting set while oom_reaper is still working on an mm that this prevents, so feel free to add an Acked-by: David Rientjes with a variant of your previous changelogs. Thanks! I think it would appropriate to cc stable for 4.14 and add a Fixes: 212925802454 ("mm: oom: let oom_reap_task and exit_mmap run concurrently") if nobody disagrees, which I think you may have already done on a previous iteration. We can still discuss if there are any VM_LOCKED subtleties in the this thread, but I have no evidence that it is responsible for any issues. -- 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