[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9a406ab6-0da8-fb8c-968c-2b403be6781d@google.com>
Date: Fri, 15 Aug 2025 21:33:09 -0700 (PDT)
From: Hugh Dickins <hughd@...gle.com>
To: John Hubbard <jhubbard@...dia.com>
cc: Will Deacon <will@...nel.org>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Hugh Dickins <hughd@...gle.com>,
Keir Fraser <keirf@...gle.com>, Jason Gunthorpe <jgg@...pe.ca>,
David Hildenbrand <david@...hat.com>, Frederick Mayle <fmayle@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>, Peter Xu <peterx@...hat.com>,
Rik van Riel <riel@...riel.com>, Vlastimil Babka <vbabka@...e.cz>
Subject: Re: [PATCH] mm/gup: Drain batched mlock folio processing before
attempting migration
On Fri, 15 Aug 2025, John Hubbard wrote:
> On 8/15/25 3:18 AM, Will Deacon wrote:
> >
> > diff --git a/mm/gup.c b/mm/gup.c
> > index adffe663594d..656835890f05 100644
> > --- a/mm/gup.c
> > +++ b/mm/gup.c
> > @@ -2307,7 +2307,8 @@ static unsigned long collect_longterm_unpinnable_folios(
> > continue;
> > }
> >
> > - if (!folio_test_lru(folio) && drain_allow) {
> > + if (drain_allow &&
> > + (!folio_test_lru(folio) || folio_test_mlocked(folio))) {
>
> That should work, yes.
>
> Alternatively, after thinking about this a bit today, it seems to me that the
> mlock batching is a little too bold, given the presence of gup/pup. And so I'm
> tempted to fix the problem closer to the root cause, like this (below).
>
> But maybe this is actually *less* wise than what you have proposed...
>
> I'd like to hear other mm folks' opinion on this approach:
>
> diff --git a/mm/mlock.c b/mm/mlock.c
> index a1d93ad33c6d..edecdd32996e 100644
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -278,7 +278,15 @@ void mlock_new_folio(struct folio *folio)
>
> folio_get(folio);
> if (!folio_batch_add(fbatch, mlock_new(folio)) ||
> - folio_test_large(folio) || lru_cache_disabled())
> + folio_test_large(folio) || lru_cache_disabled() ||
> + /*
> + * If this is being called as part of a gup FOLL_LONGTERM operation in
> + * CMA/MOVABLE zones with MLOCK_ONFAULT active, then the newly faulted
> + * in folio will need to immediately migrate to a pinnable zone.
> + * Allowing the mlock operation to batch would break the ability to
> + * migrate the folio. Instead, force immediate processing.
> + */
> + (current->flags & PF_MEMALLOC_PIN))
> mlock_folio_batch(fbatch);
> local_unlock(&mlock_fbatch.lock);
> }
It's certainly worth considering this approach: it is consistent with
the lru_cache_disabled() approach (but I'm not a great fan of the
lru_cache_disabled() approach, often wonder how much damage it does).
But I think you've placed this in the wrong function: mlock_new_folio()
should already be satisfactorily handled, it's mlock_folio() that's
the problematic one.
I didn't know of PF_MEMALLOC_PIN at all: as you say,
let's hear other opinions.
Hugh
Powered by blists - more mailing lists