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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0A9BC433F5 for ; Mon, 30 May 2022 22:28:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 349BE6B0071; Mon, 30 May 2022 18:28:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31CF56B0073; Mon, 30 May 2022 18:28:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C00D6B0074; Mon, 30 May 2022 18:28:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 094546B0071 for ; Mon, 30 May 2022 18:28:40 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id D7EE5120121 for ; Mon, 30 May 2022 22:28:39 +0000 (UTC) X-FDA: 79523849958.19.2E02ECC Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) by imf11.hostedemail.com (Postfix) with ESMTP id 2777E4004E for ; Mon, 30 May 2022 22:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: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=X1hcG5cF1NoC5nq4+hCb0hCmo39XmqfIWCQv7rPcgiY=; b=eWO5aV77vvkJjiIBqgvW710GQg vUFpMDqMEiL6x6ehzs6twDngkNGKUCWf6p0gPNkVCdkYzUw4LohwjCkbeTx8br66JQ7mVPtlFLMAi xQcE5BjaQXarYfxDsH9yBV6dUpkSOMYJDs3BtWTQ4SSfUqnhd6to3hN2nDYg0iCK1Krd9LT4iFvjg Ik0agmYKrpsdks9sCll0o0GWDMKu4hL9tSGpQYAEFCRiExWDQVcXArLgj2GXuayL4xHkmOik3D3ZQ 9qVxLOOoUoADGIZLeIqMaBNrZhrWx0nOuXrU8ztpJxaIADUreCyUV7juN+/yevGYx+EE3X+fJsrQS sKNCXHqw==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:60894) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nvnqW-0004Nv-OC; Mon, 30 May 2022 23:26:44 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1nvnpx-0001lw-PQ; Mon, 30 May 2022 23:26:09 +0100 Date: Mon, 30 May 2022 23:26:09 +0100 From: "Russell King (Oracle)" To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ingo Molnar , Vasily Gorbik , linuxppc-dev@lists.ozlabs.org, Stafford Horne , "David S . Miller" , Johannes Berg , Brian Cain , x86@kernel.org, linux-parisc@vger.kernel.org, Richard Henderson , Christian Borntraeger , Richard Weinberger , linux-hexagon@vger.kernel.org, Benjamin Herrenschmidt , Thomas Gleixner , Janosch Frank , Albert Ou , Anton Ivanov , Dave Hansen , linux-ia64@vger.kernel.org, Borislav Petkov , Sven Schnelle , Andrea Arcangeli , "James E . J . Bottomley" , Al Viro , Alexander Gordeev , Peter Zijlstra , Alistair Popple , Jonas Bonn , sparclinux@vger.kernel.org, linux-csky@vger.kernel.org, Will Deacon , Andrew Morton , Vlastimil Babka , linux-um@lists.infradead.org, Michal Simek , Matt Turner , linux-m68k@lists.linux-m68k.org, Paul Mackerras , linux-xtensa@linux-xtensa.org, Geert Uytterhoeven , David Hildenbrand , openrisc@lists.librecores.org, linux-arm-kernel@lists.infradead.org, Nicholas Piggin , Palmer Dabbelt , Michael Ellerman , Stefan Kristiansson , Paul Walmsley , Ivan Kokshaysky , Chris Zankel , Hugh Dickins , Vineet Gupta , Dinh Nguyen , Catalin Marinas , Rich Felker , "H . Peter Anvin" , linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-riscv@lists.infradead.org, Heiko Carstens , Johannes Weiner , Andy Lutomirski , Max Filippov , Guo Ren , Thomas Bogendoerfer , linux-snps-arc@lists.infradead.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, Helge Deller , Yoshinori Sato , Ingo Molnar Subject: Re: [PATCH v5] mm: Avoid unnecessary page fault retires on shared memory types Message-ID: References: <20220530183450.42886-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220530183450.42886-1-peterx@redhat.com> X-Rspam-User: X-Rspamd-Queue-Id: 2777E4004E X-Stat-Signature: 91cbr5piwfkrn861r586czmp549b1n1q Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=armlinux.org.uk header.s=pandora-2019 header.b=eWO5aV77; spf=none (imf11.hostedemail.com: domain of "linux+linux-mm=kvack.org@armlinux.org.uk" has no SPF policy when checking 78.32.30.218) smtp.mailfrom="linux+linux-mm=kvack.org@armlinux.org.uk"; dmarc=pass (policy=none) header.from=armlinux.org.uk X-Rspamd-Server: rspam09 X-HE-Tag: 1653949711-110129 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 Mon, May 30, 2022 at 02:34:50PM -0400, Peter Xu wrote: > I observed that for each of the shared file-backed page faults, we're very > likely to retry one more time for the 1st write fault upon no page. It's > because we'll need to release the mmap lock for dirty rate limit purpose > with balance_dirty_pages_ratelimited() (in fault_dirty_shared_page()). > > Then after that throttling we return VM_FAULT_RETRY. > > We did that probably because VM_FAULT_RETRY is the only way we can return > to the fault handler at that time telling it we've released the mmap lock. > > However that's not ideal because it's very likely the fault does not need > to be retried at all since the pgtable was well installed before the > throttling, so the next continuous fault (including taking mmap read lock, > walk the pgtable, etc.) could be in most cases unnecessary. > > It's not only slowing down page faults for shared file-backed, but also add > more mmap lock contention which is in most cases not needed at all. > > To observe this, one could try to write to some shmem page and look at > "pgfault" value in /proc/vmstat, then we should expect 2 counts for each > shmem write simply because we retried, and vm event "pgfault" will capture > that. > > To make it more efficient, add a new VM_FAULT_COMPLETED return code just to > show that we've completed the whole fault and released the lock. It's also > a hint that we should very possibly not need another fault immediately on > this page because we've just completed it. > > This patch provides a ~12% perf boost on my aarch64 test VM with a simple > program sequentially dirtying 400MB shmem file being mmap()ed and these are > the time it needs: > > Before: 650.980 ms (+-1.94%) > After: 569.396 ms (+-1.38%) > > I believe it could help more than that. > > We need some special care on GUP and the s390 pgfault handler (for gmap > code before returning from pgfault), the rest changes in the page fault > handlers should be relatively straightforward. > > Another thing to mention is that mm_account_fault() does take this new > fault as a generic fault to be accounted, unlike VM_FAULT_RETRY. > > I explicitly didn't touch hmm_vma_fault() and break_ksm() because they do > not handle VM_FAULT_RETRY even with existing code, so I'm literally keeping > them as-is. > > Acked-by: Geert Uytterhoeven > Acked-by: Peter Zijlstra (Intel) > Acked-by: Johannes Weiner > Acked-by: Vineet Gupta > Acked-by: Guo Ren > Acked-by: Max Filippov > Acked-by: Christian Borntraeger > Acked-by: Michael Ellerman (powerpc) > Acked-by: Catalin Marinas > Reviewed-by: Alistair Popple > Reviewed-by: Ingo Molnar > Signed-off-by: Peter Xu For: > diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c > index a062e07516dd..46cccd6bf705 100644 > --- a/arch/arm/mm/fault.c > +++ b/arch/arm/mm/fault.c > @@ -322,6 +322,10 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) > return 0; > } > > + /* The fault is fully completed (including releasing mmap lock) */ > + if (fault & VM_FAULT_COMPLETED) > + return 0; > + > if (!(fault & VM_FAULT_ERROR)) { > if (fault & VM_FAULT_RETRY) { > flags |= FAULT_FLAG_TRIED; Acked-by: Russell King (Oracle) Thanks! -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!