From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2265BC33C8C for ; Tue, 7 Jan 2020 14:27:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B0124222D9 for ; Tue, 7 Jan 2020 14:27:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="W2ESdvTI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0124222D9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 153568E0036; Tue, 7 Jan 2020 09:27:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DD1A8E001E; Tue, 7 Jan 2020 09:27:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBF848E0036; Tue, 7 Jan 2020 09:27:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D26978E001E for ; Tue, 7 Jan 2020 09:27:18 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 7691E4DC3 for ; Tue, 7 Jan 2020 14:27:18 +0000 (UTC) X-FDA: 76351065756.09.ring24_229b106d3a943 X-HE-Tag: ring24_229b106d3a943 X-Filterd-Recvd-Size: 6268 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Jan 2020 14:27:17 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id m26so52460695ljc.13 for ; Tue, 07 Jan 2020 06:27:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FMTxUTdpVr9PbE4uzNGcEta0D//FW4aZKREXh8uWcDU=; b=W2ESdvTINYmOLhasFiqbq+yXfBxyxG1CxG2Ri3h3L34yREshTNrCwhitXQj8NmBDwX 7tuZpuL79r66ckNl79BSq7EqHD3Myir0U2ChsCRGYasn56EtYWjb8ieh/7Dw4CG+aI6m bNEU5np/cRhwqDIQnpSYMfwemn6ZRgffrbeRioSnjHGrwplPvGsAb4T2c386ASrqHVTd lq3u0gWgsYrz0ki4vN1zDGUlcGbKp6DsbxznbvjNpxPJpaebVyypmhSxuWCOLoMztOSr o8wOE9kUGCzw0dW2It25vmG1kpF4ik6gE2rrSbz7f1zukMDxzCN/BBYwePJahnyzO9aO /+zg== 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:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FMTxUTdpVr9PbE4uzNGcEta0D//FW4aZKREXh8uWcDU=; b=tFgRPQBoP6StrfJjJBTN5IgcRX/p+GI6XZKrmIj0P1DKVC1T2eY7Wj/REFtL2vMNTE kN4sFkSRX4YRiEVrna16A9jyrt1WOLSIXapX3TbSPLpzSgxv4UkFbw4deeYIGGRdddVP zkbdXLSRxV1hxGxPfg3++A648UXj17TJd6Zsf4DCQCPqYoWMOi+A2b2btymmczd/QXiF QhRsYYIyaMvPxWCorbFXBHSiV0lE0S5ESNozk6GRwA3WZG5uy985YRWPXC0KCL51G3T5 zNnasWl+UW/zFCAxJ7Yte/EeX95k5gTNzhfLrCK7RFkvzSoLfz4krJ3YsUjlTenIVavm azpA== X-Gm-Message-State: APjAAAXDryJVPM9wuieBIoTPTw3L1tuc8sU2yemA1qRpvtJ5fnRQP/Tf qknceVFgTQYUSoSMUjhYzkKGms0BIxI= X-Google-Smtp-Source: APXvYqwe8I8Kp+v4bGvG4xK6Bi3d2lIjiHWhIflA9IFJYw5I7TZVdrpQ33QvC2dAOj/hEOytlmM6sQ== X-Received: by 2002:a2e:b017:: with SMTP id y23mr65249646ljk.229.1578407236354; Tue, 07 Jan 2020 06:27:16 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id s9sm26832527ljh.90.2020.01.07.06.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 06:27:15 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 5B9761009CA; Tue, 7 Jan 2020 17:27:14 +0300 (+03) Date: Tue, 7 Jan 2020 17:27:14 +0300 From: "Kirill A. Shutemov" To: Matthew Wilcox Cc: linux-mm@kvack.org Subject: Re: Splitting the mmap_sem Message-ID: <20200107142714.gjkdcikbbwfbvl2r@box> References: <20191203222147.GV20752@bombadil.infradead.org> <20191212142457.zqp4mawjz7frpyvk@box> <20191212154002.GR32169@bombadil.infradead.org> <20200106220910.GK6788@bombadil.infradead.org> <20200107123415.gqklwca4qilva2yr@box> <20200107135459.GL6788@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200107135459.GL6788@bombadil.infradead.org> User-Agent: NeoMutt/20180716 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jan 07, 2020 at 05:54:59AM -0800, Matthew Wilcox wrote: > On Tue, Jan 07, 2020 at 03:34:15PM +0300, Kirill A. Shutemov wrote: > > On Mon, Jan 06, 2020 at 02:09:10PM -0800, Matthew Wilcox wrote: > > > On Thu, Dec 12, 2019 at 07:40:02AM -0800, Matthew Wilcox wrote: > > > > > > We currently only have one ->map_pages() callback, and it's > > > > > > filemap_map_pages(). It only needs to sleep in one place -- to allocate > > > > > > a PTE table. I think that can be allocated ahead of time if needed. > > > > > > > > > > No, filemap_map_pages() doesn't sleep. It cannot. Whole body of the > > > > > function is under rcu_read_lock(). It uses pre-allocated page table. > > > > > See do_fault_around(). > > > > > > > > Oh, thank you! That makes the ->map_pages() optimisation already workable > > > > with no changes. > > > > > > I've been thinking about this some more, and we have a bit of a tough time > > > allocating page table entries while holding the RCU read lock. There's > > > no GFP flags to the p??_alloc() functions, so we can't specify GFP_NOWAIT. > > > > > > Option 1: Add 'prealloc_pmd' and 'prealloc_pud' to the vm_fault (to go > > > with prealloc_pte). Allocate them before taking the RCU lock to walk > > > the VMA tree. This will be a bit of reordering as we currently take > > > the mmap_sem, walk the VMA tree, then walk the page tables once we know > > > we have a good VMA. I don't see a problem with doing that, but others > > > may differ. > > > > I expect preallocating all these page tables just-in-case would have > > measuable performance impact. Current code only preallocates PTE page > > table if sees pmd_none(). > > Right, and we'd only preallocate those tables if we see pud_none() and > p4d_none(). Which is why we'd need to walk the page tables before > walking the VMA tree. > > > We may first check if this branch of the tree is present. But I'm not sure > > how efficient it can be. And we still need to protect from freeing > > these page tables from under us. > > Do we free page tables once they've been inserted, other than at > process exit? Yes. munmap() would free them. See free_pgtables() in unmap_region() > > > Option 2: Add a memalloc_nowait_save/restore API to go along > > > with nofs and noio. That way, we can take the RCU read lock, call > > > memalloc_nowait_save(), and walk the VMA tree and the page tables in > > > the current order. There's an increased chance of memory allocation of > > > page tables failing, so we'll have to risk that and do a retry with the > > > reference count held on the VMA if we need to sleep to allocate memory. > > > > > > Option 3: Variant of 2 where we add GFP flags to the p??_alloc() > > > functions. > > > > I think this is the most reasonable way. If we are low of memory, latency > > is not on the top of priorities. > > You prefer adding GFP flags over adding a memalloc_nowait_save()? I don't have strong preference here. -- Kirill A. Shutemov