[PATCH v2 19/37] mm/gup: remove record_subpages()
John Hubbard
jhubbard at nvidia.com
Fri Sep 5 18:05:21 PDT 2025
On 9/1/25 8:03 AM, David Hildenbrand wrote:
> We can just cleanup the code by calculating the #refs earlier,
> so we can just inline what remains of record_subpages().
>
> Calculate the number of references/pages ahead of times, and record them
> only once all our tests passed.
>
> Signed-off-by: David Hildenbrand <david at redhat.com>
> ---
> mm/gup.c | 25 ++++++++-----------------
> 1 file changed, 8 insertions(+), 17 deletions(-)
>
> diff --git a/mm/gup.c b/mm/gup.c
> index c10cd969c1a3b..f0f4d1a68e094 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -484,19 +484,6 @@ static inline void mm_set_has_pinned_flag(struct mm_struct *mm)
> #ifdef CONFIG_MMU
>
> #ifdef CONFIG_HAVE_GUP_FAST
> -static int record_subpages(struct page *page, unsigned long sz,
> - unsigned long addr, unsigned long end,
> - struct page **pages)
> -{
> - int nr;
> -
> - page += (addr & (sz - 1)) >> PAGE_SHIFT;
> - for (nr = 0; addr != end; nr++, addr += PAGE_SIZE)
> - pages[nr] = page++;
> -
> - return nr;
> -}
> -
> /**
> * try_grab_folio_fast() - Attempt to get or pin a folio in fast path.
> * @page: pointer to page to be grabbed
> @@ -2967,8 +2954,8 @@ static int gup_fast_pmd_leaf(pmd_t orig, pmd_t *pmdp, unsigned long addr,
> if (pmd_special(orig))
> return 0;
>
> - page = pmd_page(orig);
> - refs = record_subpages(page, PMD_SIZE, addr, end, pages + *nr);
> + refs = (end - addr) >> PAGE_SHIFT;
> + page = pmd_page(orig) + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
>
> folio = try_grab_folio_fast(page, refs, flags);
> if (!folio)
> @@ -2989,6 +2976,8 @@ static int gup_fast_pmd_leaf(pmd_t orig, pmd_t *pmdp, unsigned long addr,
> }
>
> *nr += refs;
> + for (; refs; refs--)
> + *(pages++) = page++;
> folio_set_referenced(folio);
> return 1;
> }
> @@ -3007,8 +2996,8 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp, unsigned long addr,
> if (pud_special(orig))
> return 0;
>
> - page = pud_page(orig);
> - refs = record_subpages(page, PUD_SIZE, addr, end, pages + *nr);
> + refs = (end - addr) >> PAGE_SHIFT;
> + page = pud_page(orig) + ((addr & ~PUD_MASK) >> PAGE_SHIFT);
>
> folio = try_grab_folio_fast(page, refs, flags);
> if (!folio)
> @@ -3030,6 +3019,8 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp, unsigned long addr,
> }
>
> *nr += refs;
> + for (; refs; refs--)
> + *(pages++) = page++;
Hi David,
Probably a similar sentiment as Lorenzo here...the above diffs make the code
*worse* to read. In fact, I recall adding record_subpages() here long ago,
specifically to help clarify what was going on.
Now it's been returned to it's original, cryptic form.
Just my take on it, for whatever that's worth. :)
thanks,
--
John Hubbard
> folio_set_referenced(folio);
> return 1;
> }
More information about the linux-riscv
mailing list