Re: [PATCH 8/8] mm/gup: batch contiguous same-folio PTEs into one refcount grab
From: Rik van Riel
Date: Tue Nov 03 2026 - 21:08:50 EST
On Tue, 3 Nov 2026 17:55:31 +0100
"David Hildenbrand (Arm)" <david@xxxxxxxxxx> wrote:
> My plan is to get the small series for gup-fast ready, stage that, and then
> build on top of it.
>
> By then I should have been able to dig through most of your series. The cleanups
> can stay part of this series.
>
That sounds good. It looks like with this small change below,
GUP-fast and slow GUP can share another helper.
I can fold that into my series as well, or send the cleanups
in a separate series, whatever works best for you.
The PUD and PMD paths do not look as easy to untangle, but
maybe after some more cleanups on each end?
---8<---
diff --git a/mm/gup.c b/mm/gup.c
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -940,14 +940,20 @@
* run under FOLL_WRITE or FOLL_PIN does need the per-page check, so it stays
* one page at a time.
+ *
+ * @fpb_flags selects the scan: slow GUP merges young/dirty so
+ * folio_mark_dirty() sees any dirty PTE in the run; fast GUP scans
+ * locklessly and revalidates the run after grabbing it. @vma is only
+ * needed for FPB_MERGE_WRITE and may be NULL otherwise.
*/
static unsigned long gup_pte_batch_len(struct vm_area_struct *vma,
unsigned long address, unsigned long walk_end,
- struct folio *folio, pte_t *ptep, pte_t *batch_pte, unsigned int flags)
+ struct folio *folio, pte_t *ptep, pte_t *batch_pte,
+ unsigned int flags, fpb_t fpb_flags)
{
unsigned long max;
@@ -961,8 +961,7 @@
max = (walk_end - address) >> PAGE_SHIFT;
if (max <= 1)
return 1;
- /* Merge young/dirty across batch so folio_mark_dirty sees any dirty. */
return folio_pte_batch_flags(folio, vma, ptep, batch_pte, max,
- FPB_RESPECT_WRITE | FPB_MERGE_YOUNG_DIRTY);
+ fpb_flags);
}
@@ -1018,7 +1018,8 @@
folio = page_folio(page);
batch_pte = pte;
batch = gup_pte_batch_len(vma, address, walk_end, folio,
- ptep, &batch_pte, flags);
+ ptep, &batch_pte, flags,
+ FPB_RESPECT_WRITE | FPB_MERGE_YOUNG_DIRTY);
ret = gup_grab_folio_pages(folio, page, batch,
pte_dirty(batch_pte), flags,