Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp452345ioo; Thu, 26 May 2022 07:18:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6D3zrCDijt9A2K8CmAbacsJhiKckwf5DX5TDktv0HIMBCmY9gHxJczOLnx7xG0XKJ4tLO X-Received: by 2002:a17:907:8a05:b0:6ff:1060:3ed1 with SMTP id sc5-20020a1709078a0500b006ff10603ed1mr7869665ejc.341.1653574716010; Thu, 26 May 2022 07:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653574716; cv=none; d=google.com; s=arc-20160816; b=D5PNmQmee7UxUzvx2cQbd4m93wgvUqW+eN6VGt2wgp2fZtuZgOfP3iIUzOqFY6WwyD 4kor06dWPmPzeejs2iscaynFj6wtN+nW7NU5NcytEj0LeyW+NMyKS4kvrv8T24ArwdgG z2TSKm8+yy3fwFHymb5JzVoyRK97ZWQuNrzKMD2Jr4+pEdmqNHtqw85jE89F/EhTX9ei gQVvZqy4DOLcOmgG7Jyiiagt/dOdCW8TrXyEW8CJaT0ruwIPGUeCLBHZ6LevGE4vQtRb CRFx2ijWSf5LtQIn5iBDBt24i8elydUsXXgLT2PSvR9VC2IvAtGGBspZxBrjtxBD8SCR wx7Q== 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=w0F6iR9EKs/zIprBUHWYk0xdfCPICb6b6FOC3ooI/Qg=; b=fDfYMqB8DD68KSql0k8ppRXs122565N33nc1NCocOwKHI2Z5xZEa0Haai0/2P+oX9n C9PeoUeQKKSkCQPwbleIN6R54NZdKFa1xMPzb1NimEeAM/E9ZcghGk33HSZYP9x+qAY9 URNDGL17VqmTcnZFY37NTiCF8PecwoHrRw1vEkJ9n5hXFhry3ffpn0OS06VONj5NI9EZ NXiXolvMwaI+2lZh33+Lf8O/9VC991uZ7Efp0ReQAIFBFoq2Jc9b5clVOUQ6D/mfi+PZ vqM0dMerT/lS+SsUhOjPwUBZMffFQpSPETffQV573D+VseWbzW/lba8qRNKPtihJM3sf y3eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=LMEKNyEI; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du6-20020a17090772c600b006fe10d6262bsi2511127ejc.500.2022.05.26.07.18.07; Thu, 26 May 2022 07:18:35 -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=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=LMEKNyEI; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239520AbiEYMob (ORCPT + 99 others); Wed, 25 May 2022 08:44:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239352AbiEYMoY (ORCPT ); Wed, 25 May 2022 08:44:24 -0400 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31C9F9158D for ; Wed, 25 May 2022 05:44:21 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id b200so8203337qkc.7 for ; Wed, 25 May 2022 05:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=w0F6iR9EKs/zIprBUHWYk0xdfCPICb6b6FOC3ooI/Qg=; b=LMEKNyEIRYPV5QWJlwplZCx+Yze+80z3MALcLFPz5jKdddgbR28N/X6bo9Jvgd00MP WWkcUcb1+z91voFM8WjtduJpm5pvevvusNqH0PzjaxsPqwHpEmvLG6H17fO8d+8uqQ/c xW/rbo+trH8MjL1X/foXOCmesnHHx99Tmug43Nb91EXZFTR7KAdlglnJRYtL1NUTbXz5 2CGVavB8u5eJ5bdNx8JVu0TNi6KB2NiCnWSVtKfIEdRU3i4wp/Kah2nDHcLAJXmplYfJ xzofRGg4rofGSre9mJv/qm1XS4Pms5gIR+r4L8hjS8Owdd3qkT56i/sicOD/din7w+oO VJFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=w0F6iR9EKs/zIprBUHWYk0xdfCPICb6b6FOC3ooI/Qg=; b=JpoHunza15nYa/LDPjqJmLcGtv8bP34udXxzDH8tN3TDFhtgOtRdMI73UuAhcN2/KQ D6cOmPEyoUFNwsPS8fIqcwNpL9+d0MLuhwyUIWolDlVZnYyRX7fY52teXi8Nc0ri2Goa azBDkfSZcTXyP8OJ7aIReDfaMEgFk78+88qSxgwQ3Cz/X91w7H1p0vb+m04VkH8qZT3Z kLqTNI6XS+59VO/fOvamvobE4siQY9s56p+7jzwIYGcL/mDlUCxhoEmvfMXnHRO32r/0 8V1JZjFAsqM90W2dfTiwdA1mOrX3B9sYg+0Xn0V28O8tai2nPYmmguIo+Rf+TXxDKDK+ wndQ== X-Gm-Message-State: AOAM531H01ASvRWNGHQ2tOoDke+6g4L0yPEQWQw1ClvkZuZHq2ySt5gV djIFu3kSMN2ILXLZLbveCiLPxQ== X-Received: by 2002:a05:620a:4047:b0:6a0:5dae:ad67 with SMTP id i7-20020a05620a404700b006a05daead67mr19946570qko.530.1653482659851; Wed, 25 May 2022 05:44:19 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:741f]) by smtp.gmail.com with ESMTPSA id g25-20020ac870d9000000b002f9433ed963sm1207797qtp.64.2022.05.25.05.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 05:44:19 -0700 (PDT) Date: Wed, 25 May 2022 08:44:18 -0400 From: Johannes Weiner 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 , Peter Zijlstra , 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 , 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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Johannes Weiner