Re: [RFC PATCH 1/5] mm/mmap_lock: add vma_start_read_rcu() helper
From: Suren Baghdasaryan
Date: Tue Dec 01 2026 - 21:50:13 EST
On Tue, Dec 1, 2026 at 5:24 PM chuanhua han <hanchuanhua802@xxxxxxxxx> wrote:
>
>
>
> Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx> 于2026年12月1日周二 21:24写道:
>>
>> NAK. You're not doing this. Any of it, sorry.
>
>
> Understood, and thanks for taking the time to reply.
>
>>
>> On Tue, Dec 01, 2026 at 09:11:31PM +0800, Chuanhua Han wrote:
>> > A later patch makes the MGLRU aging walk lock VMAs one at a time instead
>> > of holding mmap_lock for the whole mm. The walk only tries to read-lock
>> > each VMA it finds under RCU, and skips the VMA if its lock is held for
>> > write, rather than waiting for the writer. It does so in two places:
>>
>> No.
>>
>> >
>> > - While iterating the VMA tree under RCU.
>> >
>> > - While holding a PTE lock, inside the RCU read side critical section
>> > of pte_offset_map(), to hand the VMA lock off to the next VMA in
>> > the same PTE table without dropping the PTE lock. Waiting there
>> > could deadlock: a writer such as mprotect() takes the PTE lock
>> > after the VMA write lock.
>> >
>>
>> No.
>>
>> > vma_start_read() does not fit the second place, and is awkward in the
>> > first. When it fails, it leaves the RCU read side critical section,
>> > which the PTE table mapped by pte_offset_map() depends on, and the
>> > iteration has to look the next VMA up again. If the VMA has been
>> > recycled for another mm, it also mmdrop()s that mm, and __mmdrop() is
>> > heavy enough that vma_start_read() already defers it until after RCU;
>> > it should not run under a PTE lock either. lock_vma_under_rcu() and
>> > lock_next_vma() build on vma_start_read() and, on failure, retry or
>> > fall back to mmap_lock. The walk cannot open code the locking, which
>> > relies on helpers private to mm/mmap_lock.c.
>>
>> NO.
>>
>> >
>> > Move the body of vma_start_read() into __vma_start_read(), which stays
>> > in the RCU read side critical section and returns the other mm through
>> > @drop_mm instead of dropping it, and rebuild vma_start_read() on top
>> > of it with the same behavior.
>>
>> No.
>>
>> >
>> > Add vma_start_read_rcu() on top of __vma_start_read(). It returns NULL
>> > both when the VMA cannot be locked and when it is detached, since the
>> > walk skips it either way. The caller mmdrop()s the mm returned in
>> > @drop_mm after dropping its spinlocks and leaving RCU, and, as with
>> > any VMA found under RCU, checks that the locked VMA still covers the
>> > range it expects.
>>
>> No.
>>
>> >
>> > No functional change.
>>
>> Not true, you're creating a brand new API and expecting VMA maintainers to
>> maintain it indefinitely.
>
>
> Yes, it does add a new API.
>
>>
>> Also to give you free review time.
>>
>> >
>> > Signed-off-by: Chuanhua Han <hanchuanhua@xxxxxxxxxx>
>>
>> No thanks.
>>
>> As VMA co-maintainer let me just make this simple - I am not interested in
>> changes like this from unknown people, at all. Sorry.
>>
>> LLMs have changed the landscape. Do smaller changes first. I have no
>> confidence you understand any of it.
>
>
> I did use an AI assistant for this series and should have said so, sorry. I'll start with smaller MGLRU patches.
>
> 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.
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.
[1] https://lore.kernel.org/all/20261124-vma-read-lock-mmdrop-async-v1-1-257f99f551de@xxxxxxxxxx/
>
> Thanks,
> Chuanhua