Re: [RFC PATCH 1/5] mm/mmap_lock: add vma_start_read_rcu() helper
From: chuanhua han
Date: Wed Dec 02 2026 - 08:08:17 EST
On Wed, Dec 2, 2026 at 5:10 PM Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx> wrote:
>
> On Tue, Dec 01, 2026 at 06:49:55PM -0800, Suren Baghdasaryan wrote:
> > On Tue, Dec 1, 2026 at 5:24 PM chuanhua han <hanchuanhua802@xxxxxxxxx> wrote:
> > > I did use an AI assistant for this series and should have said so, sorry. I'll start with smaller MGLRU patches.
>
> Thank you, I appreciate your candour!
>
> > >
> > > The mmap_lock waits behind the MGLRU walk do cause frame drops on our
> > > phones, so I'd still like to fix that at some point. If the MGLRU
> > > maintainers have a preferred direction, I'm happy to hear it.
> >
> > I looked ahead at what you are doing later in the patchset and yeah,
> > that's definitely not something I'm comfortable with. Lockless VMA
> > walks are quite complex, just look at the lock_next_vma()
> > implementation. Speaking of which, from a quick look at your
> > walk_trylock_next_vma(), I think it might have been much easier to add
> > an option for lock_next_vma() to not fall back to mmap_lock, which I
> > think would have been enough to fit your usecase. I didn't spend much
> > time exploring that direction but it might be a much simpler change.
>
> Yeah I agree making a version of lock_next_vma() that doesn't fallback makes
> sense, but I think best way is to model it on the BPF user, i.e. replace the
> open-coded work there with a variant that permits it.
>
> Then obviously others who have a use for it can do so.
>
> Maybe try_lock_next_vma(), since lock_next_vma() is trying to guarantee a lock
> either way?
Makes sense, thanks. It will take me some time to get this right and
measure it, though.
There are two things I need to check for the MGLRU walk. In the RFC,
the walk skips VMAs that it doesn't want by their flags under RCU,
before taking the VMA lock. It also moves to the next VMA while
holding a PTE lock, so that lookup needs to stay cheap. I'll see
whether a try_lock_next_vma() that works for BPF can cover both.
>
> >
> > Also a side-note about drop_mm part in this patch. In [1] Lorenzo
> > recently changed vma_start_read() to use mmdrop_async(), so that
> > "mmdrop() is a heavy operation" thing does not apply anymore.
>
> Yup :)
>
> >
> > [1] https://lore.kernel.org/all/20261124-vma-read-lock-mmdrop-async-v1-1-257f99f551de@xxxxxxxxxx/
>
> --
> Cheers, Lorenzo
--
Thanks,
Chuanhua