Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3641981ioo; Wed, 25 May 2022 05:14:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUhJvq76p5ScCnUhunvcRL8HZT466ZojodwW9eq0Lf27PHozplpFAubXSRmlXPtLpC7idC X-Received: by 2002:a17:90a:5785:b0:1e0:3647:7851 with SMTP id g5-20020a17090a578500b001e036477851mr10064503pji.155.1653480870951; Wed, 25 May 2022 05:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653480870; cv=none; d=google.com; s=arc-20160816; b=BE3TsVDTFwvH5H2p6sVgkhE7tJh/hUJbbCRHkYkes4VXnPqPF7K7EiucPOguV5B/lz Qrgj5KR8yzP+gzr/BiKERIbdPHKKEnPh1hNQancEtCmt7kjEqNhXoNLk1ls+KWHkPqv5 7t36qhPNp4ho0DREpcLxlpEDbbXa/oEj/o+mQHmbk1M+r4ASDgcnMFXyUXPaBIpcwCMM owi7Dpmh/v090Y54MffwKcE/6XJzkZS0wuuFZudt6TZc+dKaVy3Okx22QtdOXXxv1Psz TkzYWzwCeURrarQaTouQvBvSmyLNxTQOyZL7MfbVXUa4SpHA8jdZEPZYDJjzJ439dPcr jPIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TTSfncRF4bwVxkeR+S4pHa2NuE5vU7NkHqU52imXoeo=; b=qzvYHJ6WcwGKO3UgNK0j0wQ01DQvBMTDD7TtpUVMAO3+jM0xwgPgMaLU4OLgX8KzTa AKAAJkxYQiCemm0Z8lsLqi5KSvx67LPfGVk/0Dlyskpjw/0UOs6oq6/vv/NQToTcCPc/ i2bmZje15oChzWJk4Hd1L294UPKsc5O9BLBjFoxy6yA/zXUXiB9cIlXHhbZ995yy2bZM fMqJvA9DjxU3QDRK62Y0j+/eCxEe4Bl+WTzQSsnmoCbPTxJ4kvtwl4LZkPpU9dxXo37i ikLRCHI6AowhG7x19Xybhg7oVS8JCkmNz6wRx9OgPW2Oh9Wvs4+dsJCoCuXqXE163juB EkAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=AZ7NLjul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a056a00114200b004fa8f507068si24682334pfm.96.2022.05.25.05.14.17; Wed, 25 May 2022 05:14:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=AZ7NLjul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241087AbiEYLLP (ORCPT + 99 others); Wed, 25 May 2022 07:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241080AbiEYLLK (ORCPT ); Wed, 25 May 2022 07:11:10 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE3CA8CCC5; Wed, 25 May 2022 04:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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; bh=TTSfncRF4bwVxkeR+S4pHa2NuE5vU7NkHqU52imXoeo=; b=AZ7NLjulpP1WzqY4jAw9CJ6mzn eNxn6mITLdAkzreesFIusYyJANkaOvbZVslHzJxDDqo/jW9prJ6mSOYajnNAsWgSTZTPCGe4Y+H+t Q7b5K2i3OxODvn+feDcYZuuvagMcqlznlm2xJ6e8wPUzB4c/WkijGr50Z8D32ZlBmwWuMwGQbue1E mrsCyjPGVmj7xf/0/rnV0zIseeyVAHCeyTCYTi0ZFmZwkk1CWC0IMPFglArv51u64lwHpRP8/QuNm TypGtB34O3uGaPoduTA8k7e4jOZswva+y2onGqiOIb4Z5GAtPEnJDGpyLSzDy3ZlKvUO8MvNVaZm2 4u9mbK6A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntouK-001b5l-Bp; Wed, 25 May 2022 11:10:28 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 59CA2300222; Wed, 25 May 2022 13:10:17 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 374CD207688E7; Wed, 25 May 2022 13:10:17 +0200 (CEST) Date: Wed, 25 May 2022 13:10:17 +0200 From: Peter Zijlstra To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Richard Henderson , David Hildenbrand , Matt Turner , Albert Ou , Michal Simek , Russell King , Ivan Kokshaysky , linux-riscv@lists.infradead.org, Alexander Gordeev , Dave Hansen , Jonas Bonn , Will Deacon , "James E . J . Bottomley" , "H . Peter Anvin" , Andrea Arcangeli , openrisc@lists.librecores.org, linux-s390@vger.kernel.org, Ingo Molnar , linux-m68k@lists.linux-m68k.org, Palmer Dabbelt , Heiko Carstens , Chris Zankel , Alistair Popple , linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, Vlastimil Babka , Thomas Gleixner , sparclinux@vger.kernel.org, Christian Borntraeger , Stafford Horne , Michael Ellerman , x86@kernel.org, Thomas Bogendoerfer , Paul Mackerras , linux-arm-kernel@lists.infradead.org, Sven Schnelle , Benjamin Herrenschmidt , linux-xtensa@linux-xtensa.org, Nicholas Piggin , linux-sh@vger.kernel.org, Vasily Gorbik , Borislav Petkov , linux-mips@vger.kernel.org, Max Filippov , Helge Deller , Vineet Gupta , Al Viro , Paul Walmsley , Johannes Weiner , Anton Ivanov , Catalin Marinas , linux-um@lists.infradead.org, linux-alpha@vger.kernel.org, Johannes Berg , linux-ia64@vger.kernel.org, Geert Uytterhoeven , Dinh Nguyen , Guo Ren , linux-snps-arc@lists.infradead.org, Hugh Dickins , Rich Felker , Andy Lutomirski , Richard Weinberger , linuxppc-dev@lists.ozlabs.org, Brian Cain , Yoshinori Sato , Andrew Morton , Stefan Kristiansson , linux-parisc@vger.kernel.org, "David S . Miller" Subject: Re: [PATCH v3] mm: Avoid unnecessary page fault retires on shared memory types Message-ID: References: <20220524234531.1949-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220524234531.1949-1-peterx@redhat.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Tue, May 24, 2022 at 07:45:31PM -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. > > Signed-off-by: Peter Xu Acked-by: Peter Zijlstra (Intel)