Re: [PATCH v4] gup: optimize longterm pin_user_pages() for large folio

From: David Laight
Date: Sun Jun 08 2025 - 13:10:42 EST


On Fri, 6 Jun 2025 09:21:25 +0200
David Hildenbrand <david@xxxxxxxxxx> wrote:

> > * Returns the number of collected folios. Return value is always >= 0.
> > */
> > @@ -2324,16 +2349,12 @@ static void collect_longterm_unpinnable_folios(
> > struct list_head *movable_folio_list,
> > struct pages_or_folios *pofs)
> > {
> > - struct folio *prev_folio = NULL;
> > bool drain_allow = true;
> > - unsigned long i;
> > -
> > - for (i = 0; i < pofs->nr_entries; i++) {
> > - struct folio *folio = pofs_get_folio(pofs, i);
> > + struct folio *folio;
> > + long i = 0;
> >
> > - if (folio == prev_folio)
> > - continue;
> > - prev_folio = folio;
> > + for (folio = pofs_get_folio(pofs, i); folio;
> > + folio = pofs_next_folio(folio, pofs, &i)) {
>
> Nit: indentation is still off?

I tend to move the 'initialisation' to the line above:
folio = pofs_get_folio(pofs, i);
for (; folio; folio = pofs_next_folio(folio, pofs, &i)) {
code...
For 'search' loops you don't always want the conditional, so:
folio = pofs_get_folio(pofs, i);
for (;; folio = pofs_next_folio(folio, pofs, &i)) {
if (!folio)
return -ENOENT;
code...

The 'really useful (tm)' part of a 'for' loop is the statement
executed by 'continue'.

:-)

David