Received: by 10.192.165.148 with SMTP id m20csp1949487imm; Sat, 21 Apr 2018 20:26:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx48BKM/+qchJBkFGxqFyZwy4gz9WL+zjjDdAV4j6AAggcSPbSoieRhxP+v6UCQSPtTNJyJpU X-Received: by 2002:a17:902:57c7:: with SMTP id g7-v6mr15618198plj.222.1524367580321; Sat, 21 Apr 2018 20:26:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524367580; cv=none; d=google.com; s=arc-20160816; b=ViXAn141D5pccUVYla3nSx0BhrqiqPGynddB8t3x79ROUFxmcODQDIxgh0aO2T4nWs 0dgOKb3RIxCdf9g8QFz6BCC81M0D0ghLZrBz3egp4xtzoKyBdAgtGKqKTU+WMP/vszxt z+yPBo6DMIqZZrKttLC94BwVmx5zLCEJdpKJnB1wo1yP9B+sZzDeka4iLyWwrALKFm7A zhbbV+4nltNyxVTxvir+wivNLBRx8oqVqWFQB2yS8oPqcvVk8O1A8fvY68FRwtx8CDN1 I7TG/UYx+I+18ysFKRriXLNtfY+TKiwPucsF33IgeriwnH/hbIZJtvVfuuByCMTXrOOK yRxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=+H7bVu6mrlbseM4MJBcn+igKMqzxBzlIfgbBueTeZk0=; b=gRXw0rCfwlHwYb6bmNYbJAHVg+8ASCzfEQgqsmu6kKVfGbsJvVaBim+s8eaXVb+DPw hy7dlG1WL0SM0vY0/ISjktL3HHoWit3AGMEsLEkVAWuMyVkxDQgiLQ40n0rT7VH9zdUd s1pgr1OX8p/OqIbNiI2jcPK+2tNzNgL4fjdS3W6QkAW6yocWwB7J39qwXAFg6C/QLsyY bxSLWOvs6GiDk9N6gunBTuCavUT3QTFZ6Be3CSIHomjPVQvy4RYcMO4mmBshJ0HLXpsR GVvDM6asI1dNNBzgTp0ZlX9bFfK9KbEFPw0G6cwv3tMPsjm0i08Ms7NU37tIpz/Znqj4 kJLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=U34w6Z1u; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3-v6si9044339pld.513.2018.04.21.20.25.43; Sat, 21 Apr 2018 20:26:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=U34w6Z1u; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753385AbeDVDXA (ORCPT + 99 others); Sat, 21 Apr 2018 23:23:00 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34048 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753025AbeDVDW6 (ORCPT ); Sat, 21 Apr 2018 23:22:58 -0400 Received: by mail-pg0-f67.google.com with SMTP id p10so6008753pgn.1 for ; Sat, 21 Apr 2018 20:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=+H7bVu6mrlbseM4MJBcn+igKMqzxBzlIfgbBueTeZk0=; b=U34w6Z1ubjtcKdiDM7aTSqgyc34TD4nhamR4Q51uaqYhffLdETgiPCM07U5zuEdZYY s3IxJXRIl/UV5OX0HASr3h7CMFbS/0kLFPpBNUDRnSlZhNYo5lr3dxD9LKP7CgHhGmTn ZrsrUspcowPsISkFEAU2wbRDfnNnD3Pi6QIXFFFZFIbS+sl6JQX83HjloZz9LCxGxhFF L9fZMMSegyBgbu8VKdoxO8zp/0kP5TWwkFrq5zL00B3BNxoSZk70o6CX6GChcwJXAc91 vKxJ0XhDnk4ohLIyS+xyzIu52z4ExvDPAXUHJPe1qhw8iV3vqaj23MoFG0KK70v0vZjz 5IrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=+H7bVu6mrlbseM4MJBcn+igKMqzxBzlIfgbBueTeZk0=; b=GiAO0nFcdkN29YoLs4f5sA/x3eB8Eh1QZt+kgQBqCXX40zmp0cUoUYMbHVBIMqX5hS Snyx+bwoX88hvAEuWAwJyzAci9T4U7SYrYv+TdXMRJZ3DCNYCM7XKM+Z1X/D/6sDhboG xBMwO9Ub+kfAkx1hJskZlVlOZhYetFG3WfeiKoF50xBW0wmeO0D+/KKqwPh7MzpphJCc 3Dq+j/FT1QO8cVPYbYYncYw94iXxZ+nGr0I9Dbdvn1x5L3dxWCb8iN9NI1EMHM2hj3Ss P7Vh7qQTttimQ9BegQEzt0KsGi2FecG0p4Hr60KqB8hiS+ZF9gL8YMJon5Ei7BfCEOle F22Q== X-Gm-Message-State: ALQs6tCFK8IBbbjqkzG/z4jYy3wi2hFDzW6tXjggpmRpW4M2k2Q3XHYL ipicBHrFwGzfSTQVaRom/Oim0w== X-Received: by 2002:a17:902:9a9:: with SMTP id 38-v6mr16060109pln.114.1524367377669; Sat, 21 Apr 2018 20:22:57 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id b5sm18644625pfc.16.2018.04.21.20.22.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 21 Apr 2018 20:22:56 -0700 (PDT) Date: Sat, 21 Apr 2018 20:22:56 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Michal Hocko cc: Andrew Morton , Tetsuo Handa , Andrea Arcangeli , Roman Gushchin , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [patch v2] mm, oom: fix concurrent munlock and oom reaper unmap In-Reply-To: <20180420124044.GA17484@dhcp22.suse.cz> Message-ID: References: <201804180057.w3I0vieV034949@www262.sakura.ne.jp> <20180418075051.GO17484@dhcp22.suse.cz> <20180419063556.GK17484@dhcp22.suse.cz> <20180420082349.GW17484@dhcp22.suse.cz> <20180420124044.GA17484@dhcp22.suse.cz> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Apr 2018, Michal Hocko wrote: > diff --git a/mm/mmap.c b/mm/mmap.c > index faf85699f1a1..216efa6d9f61 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -3004,10 +3004,21 @@ void exit_mmap(struct mm_struct *mm) > struct mmu_gather tlb; > struct vm_area_struct *vma; > unsigned long nr_accounted = 0; > + bool locked = false; > > /* mm's last user has gone, and its about to be pulled down */ > mmu_notifier_release(mm); > > + /* > + * The mm is not accessible for anybody except for the oom reaper > + * which cannot race with munlocking so make sure we exclude the > + * two. > + */ > + if (unlikely(mm_is_oom_victim(mm))) { > + down_write(&mm->mmap_sem); > + locked = true; > + } > + > if (mm->locked_vm) { > vma = mm->mmap; > while (vma) { > @@ -3021,7 +3032,7 @@ void exit_mmap(struct mm_struct *mm) > > vma = mm->mmap; > if (!vma) /* Can happen if dup_mmap() received an OOM */ > - return; > + goto out_unlock; > > lru_add_drain(); > flush_cache_mm(mm); > @@ -3030,23 +3041,6 @@ 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); > > - 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(). > - * > - * mm_is_oom_victim() cannot be set from under us > - * either because victim->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 victim->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); > - } > free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); > tlb_finish_mmu(&tlb, 0, -1); > > @@ -3060,6 +3054,12 @@ void exit_mmap(struct mm_struct *mm) > vma = remove_vma(vma); > } > vm_unacct_memory(nr_accounted); > + > +out_unlock: > + if (unlikely(locked)) { > + set_bit(MMF_OOM_SKIP, &mm->flags); > + up_write(&mm->mmap_sem); > + } > } > > /* Insert vm structure into process list sorted by address How have you tested this? I'm wondering why you do not see oom killing of many processes if the victim is a very large process that takes a long time to free memory in exit_mmap() as I do because the oom reaper gives up trying to acquire mm->mmap_sem and just sets MMF_OOM_SKIP itself.