Re: [PATCH v3 5/6] mm: gup: introduce gup_unshared_pages()

From: David Hildenbrand (Arm)

Date: Wed Nov 11 2026 - 05:37:26 EST


On 11/9/26 13:32, Yeoreum Yun wrote:
> This is preparatory patch to make gup_fast_pte_range() batchable.
>
> Introduce gup_unshared_pages() to count consecutive pages within a folio
> that do not require unsharing, and use it to implement gup_must_unshare().
>
> Also add a folio argument to gup_must_unshare() so callers can reuse an
> existing folio and avoid the compound_head() call implicit in PageAnon().
>
> There is no functional change.
>
> Signed-off-by: Yeoreum Yun <yeoreum.yun@xxxxxxx>
> ---
> mm/gup.c | 111 +++++++++++++++++++++++++++++++++++++--------------------------
> 1 file changed, 66 insertions(+), 45 deletions(-)
>
> diff --git a/mm/gup.c b/mm/gup.c
> index bfe83ce1411d5..c863bae33e2f1 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -633,58 +633,39 @@ static struct page *no_page_table(struct vm_area_struct *vma,
> return NULL;
> }
>
> -/*
> - * Indicates for which pages that are write-protected in the page table,
> - * whether GUP has to trigger unsharing via FAULT_FLAG_UNSHARE such that the
> - * GUP pin will remain consistent with the pages mapped into the page tables
> - * of the MM.
> - *
> - * Temporary unmapping of PageAnonExclusive() pages or clearing of
> - * PageAnonExclusive() has to protect against concurrent GUP:
> - * * Ordinary GUP: Using the PT lock
> - * * GUP-fast and fork(): mm->write_protect_seq
> - * * GUP-fast and KSM or temporary unmapping (swap, migration): see
> - * folio_try_share_anon_rmap_*()
> - *
> - * Must be called with the (sub)page that's actually referenced via the
> - * page table entry, which might not necessarily be the head page for a
> - * PTE-mapped THP.
> - *
> - * If the vma is NULL, we're coming from the GUP-fast path and might have
> - * to fallback to the slow path just to lookup the vma.
> - */
> -static inline bool gup_must_unshare(struct vm_area_struct *vma,
> - unsigned int flags, struct page *page)
> +static unsigned long gup_unshared_pages(struct vm_area_struct *vma,

Besides the function name, LGTM.

gup_pages_requiring_unsharing() ? Don't quite like it, but something along those
lines.

--
Cheers,

David