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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B12EFC43219 for ; Mon, 30 May 2022 22:27:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241138AbiE3W1U (ORCPT ); Mon, 30 May 2022 18:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232789AbiE3W1R (ORCPT ); Mon, 30 May 2022 18:27:17 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E132043EFF; Mon, 30 May 2022 15:27:15 -0700 (PDT) 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> Sender: Russell King (Oracle) Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org 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! 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF725C433F5 for ; Mon, 30 May 2022 22:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eedAN89QL9anzFA7qUHm5VkiTgS12juZN8FZhUgkOlU=; b=o7m99R4g/lkCKM Z8mZDDZ7nAmKL9pw1WnUvEHmrIpgJ1NbMa8CSTe95sMygV6B9UIVg4sOajvTNldiIR6zXxWSTOJCx tK1KM3d/zfhN6RrgToFVAGP9mf3Sb4qaZnMi+DhahMXTjP3NZ5SVmhypApjk94jRDx2eiJHBGa6yw cv/ZQIOzKll9LHPqLBPAjef3v7H+NJF8eA+IUtDutQV7aIHgoGWcky4Yd1dUTGmucNVupusrEqNtS pi/IST0JPdRaPrh02zvebkM5dp5uYUtanb1e7ecR7A4JzrXunV4bFl9zCB71bWOmuLZ1NHn9+tMZo ygJLLQbfoXZeErVV2OhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nvnrF-008W0W-UQ; Mon, 30 May 2022 22:27:29 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nvnrB-008Vyp-HF; Mon, 30 May 2022 22:27:27 +0000 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-Disposition: inline In-Reply-To: <20220530183450.42886-1-peterx@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220530_152725_746947_E6749A39 X-CRM114-Status: GOOD ( 34.91 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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! _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 382ACC433F5 for ; Mon, 30 May 2022 22:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NUIibvSSyQlz3Rvdy7nCqjUlXeFz1bGNmUspVL1I+d0=; b=XiBwtu6sgSnck+ rWRov09x6JlZmE3WeAPqb9p95auJMC750sEf9FB1igmqZwznR4XJ8208tAoGOiAtnExQ5mU0dLzzm fwv01DLMAThCHqqPvYySo46E+CZtoX1FBaKCrJWYV5jqBMjnHShzL8rXNOgWbReHQDbFGFFxpWTB+ SCgau89oc8bF1PnQRfHLUML0qb2WT+gy/kE9r1iSwhO0JLIs+1C39G7EO2CjBiNNMttp0T+AW/Znq qJ4TwJUyDzTS2JGOOsxixBR/sBigYlLCaUerSFXNG2LWBhHDfnl/OxWDc8GxvIrqnc6pTHFMnq3Jy 85Y2+iDR8auCcxrhEhYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nvnrH-008W0n-Br; Mon, 30 May 2022 22:27:31 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nvnrB-008Vyp-HF; Mon, 30 May 2022 22:27:27 +0000 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-Disposition: inline In-Reply-To: <20220530183450.42886-1-peterx@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220530_152725_746947_E6749A39 X-CRM114-Status: GOOD ( 34.91 ) X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.org 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! _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc 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 mail.librecores.org (lists.librecores.org [88.198.125.70]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E1D6C433EF for ; Mon, 30 May 2022 22:27:45 +0000 (UTC) Received: from [172.31.1.100] (localhost.localdomain [127.0.0.1]) by mail.librecores.org (Postfix) with ESMTP id 069E6205C5; Tue, 31 May 2022 00:27:44 +0200 (CEST) Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) by mail.librecores.org (Postfix) with ESMTPS id 3950A240FC for ; Tue, 31 May 2022 00:27:42 +0200 (CEST) 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 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-BeenThere: openrisc@lists.librecores.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Discussion around the OpenRISC processor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Popple , linux-ia64@vger.kernel.org, linux-xtensa@linux-xtensa.org, Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , David Hildenbrand , linux-mips@vger.kernel.org, "James E . J . Bottomley" , linux-mm@kvack.org, Rich Felker , Paul Mackerras , Michael Ellerman , "H . Peter Anvin" , sparclinux@vger.kernel.org, Alexander Gordeev , Will Deacon , Anton Ivanov , Andrea Arcangeli , linux-s390@vger.kernel.org, linux-snps-arc@lists.infradead.org, Janosch Frank , Yoshinori Sato , linux-sh@vger.kernel.org, Richard Weinberger , Helge Deller , x86@kernel.org, Hugh Dickins , linux-csky@vger.kernel.org, Ingo Molnar , linux-alpha@vger.kernel.org, Ingo Molnar , linux-arm-kernel@lists.infradead.org, Vineet Gupta , Matt Turner , Christian Borntraeger , Catalin Marinas , Jonas Bonn , Albert Ou , Vasily Gorbik , Chris Zankel , Heiko Carstens , Johannes Weiner , linux-um@lists.infradead.org, Nicholas Piggin , linux-m68k@lists.linux-m68k.org, openrisc@lists.librecores.org, Borislav Petkov , Al Viro , Andy Lutomirski , Paul Walmsley , Thomas Gleixner , Andrew Morton , Vlastimil Babka , Richard Henderson , Brian Cain , Michal Simek , Thomas Bogendoerfer , linux-parisc@vger.kernel.org, Max Filippov , linux-kernel@vger.kernel.org, Dinh Nguyen , linux-riscv@lists.infradead.org, Palmer Dabbelt , Sven Schnelle , Guo Ren , linux-hexagon@vger.kernel.org, Ivan Kokshaysky , Johannes Berg , linuxppc-dev@lists.ozlabs.org, "David S . Miller" Errors-To: openrisc-bounces@lists.librecores.org Sender: "OpenRISC" 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! 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D40B7C433F5 for ; Tue, 31 May 2022 21:48:54 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4LCQs124Q7z3bkm for ; Wed, 1 Jun 2022 07:48:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.a=rsa-sha256 header.s=pandora-2019 header.b=eWO5aV77; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=armlinux.org.uk (client-ip=2001:4d48:ad52:32c8:5054:ff:fe00:142; helo=pandora.armlinux.org.uk; envelope-from=linux+linuxppc-dev=lists.ozlabs.org@armlinux.org.uk; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.a=rsa-sha256 header.s=pandora-2019 header.b=eWO5aV77; dkim-atps=neutral Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4LBqnf47ZZz3dwC for ; Tue, 31 May 2022 08:28:49 +1000 (AEST) 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 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-Mailman-Approved-At: Wed, 01 Jun 2022 07:48:20 +1000 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Popple , linux-ia64@vger.kernel.org, linux-xtensa@linux-xtensa.org, Peter Zijlstra , Dave Hansen , David Hildenbrand , linux-mips@vger.kernel.org, "James E . J . Bottomley" , linux-mm@kvack.org, Rich Felker , Paul Mackerras , "H . Peter Anvin" , sparclinux@vger.kernel.org, Alexander Gordeev , Will Deacon , Stafford Horne , Anton Ivanov , Andrea Arcangeli , linux-s390@vger.kernel.org, linux-snps-arc@lists.infradead.org, Janosch Frank , Yoshinori Sato , linux-sh@vger.kernel.org, Richard Weinberger , Helge Deller , x86@kernel.org, Hugh Dickins , linux-csky@vger.kernel.org, Ingo Molnar , linux-alpha@vger.kernel.org, Ingo Molnar , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, Vineet Gupta , Matt Turner , Christian Borntraeger , Catalin Marinas , Jonas Bonn , Albert Ou , Vasily Gorbik , Chris Zankel , Heiko Carstens , Johannes Weiner , linux-um@lists.infradead.org, Nicholas Piggin , Stefan Kristiansson , linux-m68k@lists.linux-m68k.org, openrisc@lists.librecores.org, Borislav Petkov , Al Viro , Andy Lutomirski , Paul Walmsley , Thomas Gleixner , Andrew Morton , Vlastimil Babka , Richard Henderson , Brian Cain , Micha l Simek , Thomas Bogendoerfer , linux-parisc@vger.kernel.org, Max Filippov , linux-kernel@vger.kernel.org, Dinh Nguyen , linux-riscv@lists.infradead.org, Palmer Dabbelt , Sven Schnelle , Guo Ren , linux-hexagon@vger.kernel.org, Ivan Kokshaysky , Johannes Berg , linuxppc-dev@lists.ozlabs.org, "David S . Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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! From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 30 May 2022 23:26:09 +0100 From: "Russell King (Oracle)" 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-Disposition: inline In-Reply-To: <20220530183450.42886-1-peterx@redhat.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-um" Errors-To: linux-um-bounces+geert=linux-m68k.org@lists.infradead.org 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 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! _______________________________________________ linux-um mailing list linux-um@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-um From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Russell King (Oracle)" Date: Mon, 30 May 2022 22:26:09 +0000 Subject: Re: [PATCH v5] mm: Avoid unnecessary page fault retires on shared memory types Message-Id: List-Id: References: <20220530183450.42886-1-peterx@redhat.com> In-Reply-To: <20220530183450.42886-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 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! From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Russell King (Oracle)" Subject: Re: [PATCH v5] mm: Avoid unnecessary page fault retires on shared memory types Date: Mon, 30 May 2022 23:26:09 +0100 Message-ID: References: <20220530183450.42886-1-peterx@redhat.com> Mime-Version: 1.0 Return-path: 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 Content-Disposition: inline In-Reply-To: <20220530183450.42886-1-peterx@redhat.com> Sender: Russell King (Oracle) List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 , linu 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!