Re: [PATCH v3] mm: Avoid unnecessary page fault retires on shared memory types
From: Peter Xu <peterx@redhat.com>
Date: 2022-05-27 14:53:56
Also in:
linux-alpha, linux-m68k, linux-mips, linux-mm, linux-riscv, linux-s390, linux-sh, linux-um, lkml, sparclinux
et>, Chris Zankel [off-list ref], Michal Simek [off-list ref], Thomas Bogendoerfer [off-list ref], linux-parisc@vger.kernel.org, Max Filippov [off-list ref], linux-kernel@vger.kernel.org, Dinh Nguyen [off-list ref], Palmer Dabbelt [off-list ref], Sven Schnelle [off-list ref], Guo Ren [off-list ref], Borislav Petkov [off-list ref], Johannes Berg [off-list ref], linuxppc-dev@lists.ozlabs.org, "David S . Miller" [off-list ref] Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" [off-list ref] On Fri, May 27, 2022 at 12:46:31PM +0200, Ingo Molnar wrote:
* Peter Xu [off-list ref] wrote:quoted
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%)Nice!quoted
arch/x86/mm/fault.c | 4 ++++Reviewed-by: Ingo Molnar <mingo@kernel.org> Minor comment typo:quoted
+ /* + * We should do the same as VM_FAULT_RETRY, but let's not + * return -EBUSY since that's not reflecting the reality on + * what has happened - we've just fully completed a page + * fault, with the mmap lock released. Use -EAGAIN to show + * that we want to take the mmap lock _again_. + */s/reflecting the reality on what has happened /reflecting the reality of what has happened
Will fix.
quoted
ret = handle_mm_fault(vma, address, fault_flags, NULL); + + if (ret & VM_FAULT_COMPLETED) { + /* + * NOTE: it's a pity that we need to retake the lock here + * to pair with the unlock() in the callers. Ideally we + * could tell the callers so they do not need to unlock. + */ + mmap_read_lock(mm); + *unlocked = true; + return 0;Indeed that's a pity - I guess more performance could be gained here, especially in highly parallel threaded workloads?
Yes I think so. The patch avoids the page fault retry, including the mmap lock/unlock side. Now if we retake the lock for fixup_user_fault() we still safe time for pgtable walks but the lock overhead will be somehow kept, just with smaller critical sections. Some fixup_user_fault() callers won't be affected as long as unlocked==NULL is passed - e.g. the futex code path (fault_in_user_writeable). After all they never needed to retake the lock before/after this patch. It's about the other callers, and they may need some more touch-ups case by case. Examples are follow_fault_pfn() in vfio and hva_to_pfn_remapped() in KVM: both of them returns -EAGAIN when *unlocked==true. We need to teach them to know "*unlocked==true" does not necessarily mean a retry attempt. I think I can look into them if this patch can be accepted as a follow up. Thanks for taking a look! -- Peter Xu