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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 D23DFC33C8C for ; Tue, 7 Jan 2020 13:55:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 92DB22072A for ; Tue, 7 Jan 2020 13:55:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="X/d7Gb5L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92DB22072A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 255C18E0034; Tue, 7 Jan 2020 08:55:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 206538E001E; Tue, 7 Jan 2020 08:55:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 142A68E0034; Tue, 7 Jan 2020 08:55:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0142.hostedemail.com [216.40.44.142]) by kanga.kvack.org (Postfix) with ESMTP id F16408E001E for ; Tue, 7 Jan 2020 08:55:08 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 9766C181AEF0B for ; Tue, 7 Jan 2020 13:55:08 +0000 (UTC) X-FDA: 76350984696.24.shoe54_2cc259fc1cc2b X-HE-Tag: shoe54_2cc259fc1cc2b X-Filterd-Recvd-Size: 4566 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Jan 2020 13:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=CfRAWf2YP1Yr1rOoU8yCV6s7Z4HSs1ZwrZFCcb0M2YY=; b=X/d7Gb5L8bvXZxCpQZU+ZV05R K3JrfavhUVQRR67afFF6uG8138LgtxMEKzIxlVwhhJcXudvwLvpS/VDAANRd9hcxKns3HkKqy3/az v9qvgRjLvrq+TQA8dBxWivS3nh71nNG4VYOc86E7sVUPVaKCMPU5KZESNr1Cfant4wENhjr/gSLTP pwbU1uL57lCzgJxNHXTHuWIQwwgyt7UxGFXQxOJ0w9EvV868P3HqTSejB7Od+dbe60vDffXDZVdWU z3cOlWfYej23XLKVHVXBt6AX34E6iCEgY8kNshF3T6IS1uW0ehTgTth/fHnHK81vTDylH9NDxPk8m 4PieVipuw==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1iopJz-0003cU-Cv; Tue, 07 Jan 2020 13:54:59 +0000 Date: Tue, 7 Jan 2020 05:54:59 -0800 From: Matthew Wilcox To: "Kirill A. Shutemov" Cc: linux-mm@kvack.org Subject: Re: Splitting the mmap_sem Message-ID: <20200107135459.GL6788@bombadil.infradead.org> References: <20191203222147.GV20752@bombadil.infradead.org> <20191212142457.zqp4mawjz7frpyvk@box> <20191212154002.GR32169@bombadil.infradead.org> <20200106220910.GK6788@bombadil.infradead.org> <20200107123415.gqklwca4qilva2yr@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200107123415.gqklwca4qilva2yr@box> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 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? > > 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()?