From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Rik van Riel <riel@surriel.com>, linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Suren Baghdasaryan <surenb@google.com>,
Lorenzo Stoakes <ljs@kernel.org>,
Christoph Hellwig <hch@infradead.org>,
Yuan-Hao Hsu <aa9736195201@gmail.com>,
John Hubbard <jhubbard@nvidia.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Peter Xu <peterx@redhat.com>
Subject: Re: [PATCH 3/9] mm/gup: convert follow_page_mask() to return a long
Date: Thu, 26 Nov 2026 15:04:38 +0100 [thread overview]
Message-ID: <cfe8bf71-7b94-4cef-8b27-9e50c3229a4a@kernel.org> (raw)
In-Reply-To: <20261123195609.4115244-4-riel@surriel.com>
On 11/23/26 20:56, Rik van Riel wrote:
> follow_page_mask() and its helpers return a struct page pointer: NULL,
> ERR_PTR(), or the page found. Change the return type to long instead:
> 0, a negative errno, or 1 with the page stored in a new pages[0] slot.
>
> This lets the return type carry a page count rather than a single
> struct page pointer.
You can say here that we now make the interface match gup-fast.
>
> follow_huge_pud(), follow_huge_pmd() and follow_page_pte() now store
> the found page in a pages[0] slot. __get_user_pages() reads that page
> back from pages[i], fills the rest of a large folio's run itself, and
> flushes the whole run's caches with gup_flush_pages().
You can say here that we will rework that next, to collect all folio pages from
inside these functions directly.
> The follow path
> itself never flushes: the caches are always flushed from
> __get_user_pages(), without any page table lock held.
>
> The vsyscall gate area bypasses follow_page_mask() and fills and flushes
> its own slot the same way. The gate handles a single page, so it
> initializes the count to 1.
>
> *page_mask and __get_user_pages()'s handling of a large folio's
> remaining subpages are untouched, and mm/gup_test.c
As willy keeps saying, there is no such thing as subpages.
"a large folio's remainin pages"
> (PIN_LONGTERM_BENCHMARK) shows no measurable difference for 4 kB,
> 64 kB mTHP, or 2 MB THP.
>
> No functional changes intended.
>
> Suggested-by: David Hildenbrand <david@kernel.org>
> Signed-off-by: Rik van Riel <riel@surriel.com>
> ---
[...]>
> /* first iteration or cross vma bound */
> if (!vma || start >= vma->vm_end) {
> @@ -1523,8 +1536,11 @@ static long __get_user_pages(struct mm_struct *mm,
> pages ? &page : NULL);
> if (ret)
> goto out;
> - page_mask = 0;
> - goto next_page;
> + if (pages)
> + pages[i] = page;
> + nr = 1;
Why not use gup_fill_pages() here?
But why do we goto fill_flush where we do another gup_fill_pages?
> + page_increm = 1;
> + goto fill_flush;
> }
>
> if (!vma) {
> @@ -1546,10 +1562,11 @@ static long __get_user_pages(struct mm_struct *mm,
> }
> cond_resched();
>
> - page = follow_page_mask(vma, start, gup_flags, &page_mask);
> - if (!page || PTR_ERR(page) == -EMLINK) {
> + nr = follow_page_mask(vma, start, gup_flags, &page_mask,
> + pages ? &pages[i] : NULL);
> + if (!nr || nr == -EMLINK) {
> ret = faultin_page(vma, start, gup_flags,
> - PTR_ERR(page) == -EMLINK, locked);
> + nr == -EMLINK, locked);
> switch (ret) {
> case 0:
> goto retry;
> @@ -1563,7 +1580,7 @@ static long __get_user_pages(struct mm_struct *mm,
> goto out;
> }
> BUG();
> - } else if (PTR_ERR(page) == -EEXIST) {
> + } else if (nr == -EEXIST) {
> /*
> * Proper page table entry exists, but no corresponding
> * struct page. If the caller expects **pages to be
> @@ -1571,49 +1588,56 @@ static long __get_user_pages(struct mm_struct *mm,
> * for this page.
> */
> if (pages) {
> - ret = PTR_ERR(page);
> + ret = nr;
> goto out;
> }
> - } else if (IS_ERR(page)) {
> - ret = PTR_ERR(page);
> + } else if (nr < 0) {
> + ret = nr;
> goto out;
> }
> -next_page:
> +
> page_increm = 1 + (~(start >> PAGE_SHIFT) & page_mask);
> if (page_increm > nr_pages)
> page_increm = nr_pages;
>
> - if (pages) {
> + /*
> + * This must be a large folio (and doesn't need to
> + * be the whole folio; it can be part of it), do
> + * the refcount work for the remaining pages.
> + *
> + * NOTE: here the page may not be the head page
> + * e.g. when start addr is not thp-size aligned.
> + * try_grab_folio() should have taken care of tail
> + * pages.
> + */
> + if (pages && page_increm > 1) {
> + struct folio *folio = page_folio(pages[i]);
> +
> /*
> - * This must be a large folio (and doesn't need to
> - * be the whole folio; it can be part of it), do
> - * the refcount work for all the subpages too.
> - *
> - * NOTE: here the page may not be the head page
> - * e.g. when start addr is not thp-size aligned.
> - * try_grab_folio() should have taken care of tail
> - * pages.
> + * Since we already hold refcount on the
> + * large folio, this should never fail.
This code recently changed slightly:
commit 2d9bcd380585abc436f055fbb618b34f98882004
Author: David Hildenbrand (Arm) <david@kernel.org>
Date: Thu Nov 12 23:53:24 2026 +0100
mm/gup: limit pagecache folio refcount when grabbing references
So once you rebase on top of mm-core/for-next, there will be some smaller
conflcits but nothign earth shattering.
There is a lot happening in this patch. I wonder if there would be some way to
convert some of the functions before converting follow_page_mask().
--
Cheers,
David
next prev parent reply other threads:[~2026-11-26 14:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 19:56 [PATCH v6 0/9] mm/gup: walk and batch whole PTE tables in slow GUP Rik van Riel
2026-11-23 19:56 ` [PATCH 1/9] mm/gup: break out gup_fill_pages() helper Rik van Riel
2026-11-26 13:40 ` David Hildenbrand (Arm)
2026-11-23 19:56 ` [PATCH 2/9] mm/gup: break out gup_flush_pages() helper Rik van Riel
2026-11-26 13:41 ` David Hildenbrand (Arm)
2026-11-26 17:41 ` Rik van Riel
2026-11-23 19:56 ` [PATCH 3/9] mm/gup: convert follow_page_mask() to return a long Rik van Riel
2026-11-26 14:04 ` David Hildenbrand (Arm) [this message]
2026-11-23 19:56 ` [PATCH 4/9] mm/gup: split out folio grab-and-store helper Rik van Riel
2026-11-23 19:56 ` [PATCH 5/9] mm/gup: break out gup_lookup_pte() helper Rik van Riel
2026-11-23 19:56 ` [PATCH 6/9] mm/gup: return a huge page's full count from follow_page_mask() Rik van Riel
2026-11-23 19:56 ` [PATCH 7/9] mm/gup: walk multiple PTEs per follow_page_pte() call Rik van Riel
2026-11-23 19:56 ` [PATCH 8/9] mm/gup: batch contiguous same-folio PTEs into one refcount grab Rik van Riel
2026-11-23 19:56 ` [PATCH 9/9] mm/gup: unshare-check every page of a pte batch Rik van Riel
2026-11-26 13:50 ` David Hildenbrand (Arm)
2026-11-26 17:37 ` Rik van Riel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cfe8bf71-7b94-4cef-8b27-9e50c3229a4a@kernel.org \
--to=david@kernel.org \
--cc=aa9736195201@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hch@infradead.org \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=peterx@redhat.com \
--cc=riel@surriel.com \
--cc=surenb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®