Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5867942ioo; Wed, 1 Jun 2022 14:30:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5+nDvzN7yxbjTNOyC1O6T7ItPw3m57U27AvfZb430HJVLvr5d5dvXq5Q1v18ajxr0jKu0 X-Received: by 2002:a63:a23:0:b0:3f5:e1e4:ae3f with SMTP id 35-20020a630a23000000b003f5e1e4ae3fmr1232942pgk.110.1654119007002; Wed, 01 Jun 2022 14:30:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654119006; cv=none; d=google.com; s=arc-20160816; b=lcpS5xbcFHbUlHtgkBJ0kIK5GmPAuhgZP3lV5C9VHw4dvtt2/92FIpMn9OcumlfRlw DTloMC31AZX17tD5X4OLYnG9z1I6UJDvlAOpBnRzheAsF0XHrj6Yj35yr4U5w1+cpXtH 7OeoSnhzLq6g70KpSdqPgUsOkp763tP2QHlZoWcfTERNXXvCCvGSH9S6Il9iQBQ8ul4+ rGQiFc3RRjNgy3txW4hzafdu6sj86cW0p9VRAOw/ABQW2c+Z5V1VlkPsSfM0lWOTSxoM mv6u/N5lmMtsiZ2et9u0dWIaDtjvmKxeHEACWl5A1rXXTed2pCeYVz+9pxbaBTENu7Xz bkFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=X1hcG5cF1NoC5nq4+hCb0hCmo39XmqfIWCQv7rPcgiY=; b=B4bgEvnQ1xN6lD36rOORtMUhC9kx9vVeaB+oi/giTWYaGrJOl2UmGMFMplB2Dl3V0H HAb/3bkxLlUVSw2cANyirJQoHRtj70a7lJAWEO44mZj0iN0A9fxP0P8+n1XzMI/VYQrx YF3MHZb3iGVtR/IKIQ58V/Iau6CGJT8mZ5CY8GOCxEj4mMgakkYa/xr/SJ68OLKbY9FD AuMwMaj9cMhwLIM7BR7XrXXrsolIr81GrzrFJEhX8Khm5GhfNdmyj2oWqcnVVysG5kdR ZrZP0dCH6YoXD3uL7ErS7u4lkJheZ/pS/WycxM2R1mUBpA/pz90R8VghIZP05eTmDC6T Fzrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=eWO5aV77; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h4-20020a17090aa88400b001e05bcf0287si6879760pjq.189.2022.06.01.14.30.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 14:30:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=eWO5aV77; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6ABB71E73F6; Wed, 1 Jun 2022 13:20:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242087AbiE3W1V (ORCPT + 99 others); Mon, 30 May 2022 18:27:21 -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) X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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!