[RFC PATCH 0/2] mm: continue using per-VMA lock when retrying page faults after I/O
Barry Song
21cnbao at gmail.com
Thu Nov 27 15:42:24 AEDT 2025
On Thu, Nov 27, 2025 at 12:22 PM Barry Song <21cnbao at gmail.com> wrote:
>
> On Thu, Nov 27, 2025 at 12:09 PM Matthew Wilcox <willy at infradead.org> wrote:
> >
> > On Thu, Nov 27, 2025 at 09:14:36AM +0800, Barry Song wrote:
> > > There is no need to always fall back to mmap_lock if the per-VMA
> > > lock was released only to wait for pagecache or swapcache to
> > > become ready.
> >
> > Something I've been wondering about is removing all the "drop the MM
> > locks while we wait for I/O" gunk. It's a nice amount of code removed:
>
> I think the point is that page fault handlers should avoid holding the VMA
> lock or mmap_lock for too long while waiting for I/O. Otherwise, those
> writers and readers will be stuck for a while.
>
> >
> > include/linux/pagemap.h | 8 +---
> > mm/filemap.c | 98 ++++++++++++-------------------------------------
> > mm/internal.h | 21 -----------
> > mm/memory.c | 13 +------
> > mm/shmem.c | 6 ---
> > 5 files changed, 27 insertions(+), 119 deletions(-)
> >
> > and I'm not sure we still need to do it with per-VMA locks. What I
> > have here doesn't boot and I ran out of time to debug it.
>
> I agree there’s room for improvement, but merely removing the "drop the MM
> locks while waiting for I/O" code is unlikely to improve performance.
>
One idea I have is that we could conditionally remove the "drop lock and
retry page fault" step if we are reasonably sure the I/O has already
completed:
diff --git a/mm/filemap.c b/mm/filemap.c
index 57dfd2211109..151f6d38c284 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3517,7 +3517,9 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
}
}
- if (!lock_folio_maybe_drop_mmap(vmf, folio, &fpin))
+ if (folio_test_uptodate(folio))
+ folio_lock(folio);
+ else if (!lock_folio_maybe_drop_mmap(vmf, folio, &fpin))
goto out_retry;
/* Did it get truncated? */
diff --git a/mm/memory.c b/mm/memory.c
index 7f70f0324dcf..355ed02560fd 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4758,7 +4758,10 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
}
swapcache = folio;
- ret |= folio_lock_or_retry(folio, vmf);
+ if (folio_test_uptodate(folio))
+ folio_lock(folio);
+ else
+ ret |= folio_lock_or_retry(folio, vmf);
if (ret & VM_FAULT_RETRY) {
if (fault_flag_allow_retry_first(vmf->flags) &&
!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT) &&
In that case, we are likely just waiting for the mapping to be completed by
another process. I may develop the above idea as an incremental patch after
this patchset.
Thanks
Barry
More information about the Linuxppc-dev
mailing list