On Thu, Jan 15, 2026 at 01:41:11PM +1100, Balbir Singh wrote:
> On 1/15/26 06:19, Francois Dugast wrote:
> > If the page is part of a folio, unlock and put the whole folio at once
> > instead of individual pages one after the other. This will reduce the
> > amount of operations once device THP are in use.
> > 
> > Cc: Andrew Morton <[email protected]>
> > Cc: David Hildenbrand <[email protected]>
> > Cc: Lorenzo Stoakes <[email protected]>
> > Cc: Liam R. Howlett <[email protected]>
> > Cc: Vlastimil Babka <[email protected]>
> > Cc: Mike Rapoport <[email protected]>
> > Cc: Suren Baghdasaryan <[email protected]>
> > Cc: Michal Hocko <[email protected]>
> > Cc: Zi Yan <[email protected]>
> > Cc: Alistair Popple <[email protected]>
> > Cc: Balbir Singh <[email protected]>
> > Cc: [email protected]
> > Suggested-by: Matthew Brost <[email protected]>
> > Reviewed-by: Matthew Brost <[email protected]>
> > Signed-off-by: Francois Dugast <[email protected]>
> > ---
> >  drivers/gpu/drm/drm_pagemap.c | 26 +++++++++++++++++---------
> >  1 file changed, 17 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c
> > index c497726b0147..b31090b8e97c 100644
> > --- a/drivers/gpu/drm/drm_pagemap.c
> > +++ b/drivers/gpu/drm/drm_pagemap.c
> > @@ -154,15 +154,15 @@ static void drm_pagemap_zdd_put(struct 
> > drm_pagemap_zdd *zdd)
> >  }
> >  
> >  /**
> > - * drm_pagemap_migration_unlock_put_page() - Put a migration page
> > - * @page: Pointer to the page to put
> > + * drm_pagemap_migration_unlock_put_folio() - Put a migration folio
> > + * @folio: Pointer to the folio to put
> >   *
> > - * This function unlocks and puts a page.
> > + * This function unlocks and puts a folio.
> >   */
> > -static void drm_pagemap_migration_unlock_put_page(struct page *page)
> > +static void drm_pagemap_migration_unlock_put_folio(struct folio *folio)
> >  {
> > -   unlock_page(page);
> > -   put_page(page);
> > +   folio_unlock(folio);
> > +   folio_put(folio);
> >  }
> >  
> >  /**
> > @@ -177,15 +177,23 @@ static void 
> > drm_pagemap_migration_unlock_put_pages(unsigned long npages,
> >  {
> >     unsigned long i;
> >  
> > -   for (i = 0; i < npages; ++i) {
> > +   for (i = 0; i < npages;) {
> >             struct page *page;
> > +           struct folio *folio;
> > +           unsigned int order = 0;
> >  
> >             if (!migrate_pfn[i])
> > -                   continue;
> > +                   goto next;
> >  
> >             page = migrate_pfn_to_page(migrate_pfn[i]);
> > -           drm_pagemap_migration_unlock_put_page(page);
> > +           folio = page_folio(page);
> > +           order = folio_order(folio);
> > +
> > +           drm_pagemap_migration_unlock_put_folio(folio);
> >             migrate_pfn[i] = 0;
> > +
> > +next:
> > +           i += NR_PAGES(order);
> 
> Is this just a wrapper on top of folio_nr_pages()?
> 

We might not have folio order. This is a macro defined here [1].

There probably is a similar macro elsewhere in kernel that does the same
thing, I can look for that and clean this up in a follow up if I can
find one.

[1] 
https://elixir.bootlin.com/linux/v6.19-rc5/source/include/drm/drm_pagemap.h#L9

> >     }
> >  }
> >  
> 
> Reviewed-by: Balbir Singh <[email protected]>

Thanks!

Matt

Reply via email to