From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751078AbdGZFqB (ORCPT ); Wed, 26 Jul 2017 01:46:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:49437 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750813AbdGZFqA (ORCPT ); Wed, 26 Jul 2017 01:46:00 -0400 Date: Wed, 26 Jul 2017 07:45:57 +0200 From: Michal Hocko To: Andrea Arcangeli Cc: "Kirill A. Shutemov" , Andrew Morton , David Rientjes , Tetsuo Handa , Oleg Nesterov , Hugh Dickins , linux-mm@kvack.org, LKML Subject: Re: [PATCH] mm, oom: allow oom reaper to race with exit_mmap Message-ID: <20170726054557.GB960@dhcp22.suse.cz> References: <20170724140008.sd2n6af6izjyjtda@node.shutemov.name> <20170724141526.GM25221@dhcp22.suse.cz> <20170724145142.i5xqpie3joyxbnck@node.shutemov.name> <20170724161146.GQ25221@dhcp22.suse.cz> <20170725142626.GJ26723@dhcp22.suse.cz> <20170725151754.3txp44a2kbffsxdg@node.shutemov.name> <20170725152300.GM26723@dhcp22.suse.cz> <20170725153110.qzfz7wpnxkjwh5bc@node.shutemov.name> <20170725160359.GO26723@dhcp22.suse.cz> <20170725191952.GR29716@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170725191952.GR29716@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 25-07-17 21:19:52, Andrea Arcangeli wrote: > On Tue, Jul 25, 2017 at 06:04:00PM +0200, Michal Hocko wrote: > > - down_write(&mm->mmap_sem); > > + if (tsk_is_oom_victim(current)) > > + down_write(&mm->mmap_sem); > > free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); > > tlb_finish_mmu(&tlb, 0, -1); > > > > @@ -3012,7 +3014,8 @@ void exit_mmap(struct mm_struct *mm) > > } > > mm->mmap = NULL; > > vm_unacct_memory(nr_accounted); > > - up_write(&mm->mmap_sem); > > + if (tsk_is_oom_victim(current)) > > + up_write(&mm->mmap_sem); > > How is this possibly safe? mark_oom_victim can run while exit_mmap is > running. I believe it cannot. We always call mark_oom_victim (on !current) with task_lock held and check task->mm != NULL and we call do_exit->mmput after mm is set to NULL under the same lock. -- Michal Hocko SUSE Labs