Re: [PATCH v3] mm: Avoid unnecessary page fault retires on shared memory types
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Peter Xu <peterx@xxxxxxxxxx>
- Subject: Re: [PATCH v3] mm: Avoid unnecessary page fault retires on shared memory types
- From: Johannes Weiner <hannes@xxxxxxxxxxx>
- Date: Wed, 25 May 2022 08:44:18 -0400
- Cc: linux-kernel@xxxxxxxxxxxxxxx, linux-mm@xxxxxxxxx, Richard Henderson <rth@xxxxxxxxxxxxxxx>, David Hildenbrand <david@xxxxxxxxxx>, Matt Turner <mattst88@xxxxxxxxx>, Albert Ou <aou@xxxxxxxxxxxxxxxxx>, Michal Simek <monstr@xxxxxxxxx>, Russell King <linux@xxxxxxxxxxxxxxx>, Ivan Kokshaysky <ink@xxxxxxxxxxxxxxxxxxxx>, linux-riscv@xxxxxxxxxxxxxxxxxxx, Alexander Gordeev <agordeev@xxxxxxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, Jonas Bonn <jonas@xxxxxxxxxxxx>, Will Deacon <will@xxxxxxxxxx>, "James E . J . Bottomley" <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>, "H . Peter Anvin" <hpa@xxxxxxxxx>, Andrea Arcangeli <aarcange@xxxxxxxxxx>, openrisc@xxxxxxxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, Ingo Molnar <mingo@xxxxxxxxxx>, linux-m68k@xxxxxxxxxxxxxxx, Palmer Dabbelt <palmer@xxxxxxxxxxx>, Heiko Carstens <hca@xxxxxxxxxxxxx>, Chris Zankel <chris@xxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, Alistair Popple <apopple@xxxxxxxxxx>, linux-csky@xxxxxxxxxxxxxxx, linux-hexagon@xxxxxxxxxxxxxxx, Vlastimil Babka <vbabka@xxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, sparclinux@xxxxxxxxxxxxxxx, Christian Borntraeger <borntraeger@xxxxxxxxxxxxx>, Stafford Horne <shorne@xxxxxxxxx>, Michael Ellerman <mpe@xxxxxxxxxxxxxx>, x86@xxxxxxxxxx, Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>, Paul Mackerras <paulus@xxxxxxxxx>, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, Sven Schnelle <svens@xxxxxxxxxxxxx>, Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>, linux-xtensa@xxxxxxxxxxxxxxxx, Nicholas Piggin <npiggin@xxxxxxxxx>, linux-sh@xxxxxxxxxxxxxxx, Vasily Gorbik <gor@xxxxxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, linux-mips@xxxxxxxxxxxxxxx, Max Filippov <jcmvbkbc@xxxxxxxxx>, Helge Deller <deller@xxxxxx>, Vineet Gupta <vgupta@xxxxxxxxxx>, Al Viro <viro@xxxxxxxxxxxxxxxxxx>, Paul Walmsley <paul.walmsley@xxxxxxxxxx>, Anton Ivanov <anton.ivanov@xxxxxxxxxxxxxxxxxx>, Catalin Marinas <catalin.marinas@xxxxxxx>, linux-um@xxxxxxxxxxxxxxxxxxx, linux-alpha@xxxxxxxxxxxxxxx, Johannes Berg <johannes@xxxxxxxxxxxxxxxx>, linux-ia64@xxxxxxxxxxxxxxx, Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>, Dinh Nguyen <dinguyen@xxxxxxxxxx>, Guo Ren <guoren@xxxxxxxxxx>, linux-snps-arc@xxxxxxxxxxxxxxxxxxx, Hugh Dickins <hughd@xxxxxxxxxx>, Rich Felker <dalias@xxxxxxxx>, Andy Lutomirski <luto@xxxxxxxxxx>, Richard Weinberger <richard@xxxxxx>, linuxppc-dev@xxxxxxxxxxxxxxxx, Brian Cain <bcain@xxxxxxxxxxx>, Yoshinori Sato <ysato@xxxxxxxxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Stefan Kristiansson <stefan.kristiansson@xxxxxxxxxxxxx>, linux-parisc@xxxxxxxxxxxxxxx, "David S . Miller" <davem@xxxxxxxxxxxxx>
- In-reply-to: <20220524234531.1949-1-peterx@redhat.com>
- References: <20220524234531.1949-1-peterx@redhat.com>
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 <peterx@xxxxxxxxxx>
Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx>
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]