Re: [RFC PATCH 0/5] mm/mglru: walk page tables under per-VMA locks
From: Lorenzo Stoakes (ARM)
Date: Fri Dec 04 2026 - 06:22:14 EST
On Fri, Dec 04, 2026 at 06:43:33PM +0800, Barry Song wrote:
> On Fri, Dec 4, 2026 at 6:39 PM Zicheng Wang <wangzicheng@xxxxxxxxx> wrote:
> >
> > Hi Suren, Chuanhua, Lorenzo,
> >
> > We hit the same stalls (140-250ms mmap/munmap/mprotect waits on
> > SurfaceFlinger and Launcher) and have a measurement that may be
> > relevant to the try_lock_next_vma() direction.
> >
> > In 3 dogfood user traces we picked for this problem, each with janky
> > frames over 500ms, a direct reclaim task doing the aging walk holds
> > mmap_lock for 140-250ms. Over 99% of that hold is spent runnable,
> > waiting to be scheduled; the aging walk itself runs for less than 1ms.
> > Each trace has thousands of direct reclaim events inside the jank window.
> >
> > A finer lock narrows who waits, but not how long. The walker runs with
> > preemption enabled while holding the lock, so a round can be preempted
> > mid-way and the lock is then held for the whole scheduling delay.
> >
> > Since the aging walk itself is already fast (<1ms), could we simply
> > disable preemption during the walk's lock-hold window instead of
> > changing the lock? We are testing a ~60-line prototype (no new lock or API)
> > and will send the patch and data separately—mainly wondering whether
> > you would prefer bounding that non-preemptible window at PUD or PMD
> > granularity.
>
> Hi Zicheng,
>
> Disabling preemption for 1 ms is unlikely to fly upstream, as
> that's simply too long. Now imagine 200 threads doing direct
> reclaim, each in a different memcg. That could result in a
> cumulative preemption-disabled time of 200 ms.
Yup :) In general we don't disable preemption unless we have to, and in general
I think when you look to a solution like this it's typically indicative that the
abstraction level of the proposed fix is wrong, i.e. you're asking the wrong
question :)
IOW this suggests that holding the VMA lock is the right solution.
Since (as I gather) Suren is looking to provide try_lock_next_vma() and update
the BPF code to reflect this (Suren - let me know if this is accurate), I
suggest you wait for this work.
Another point to be cautious of here is that a pure-VMA lock walk of VMAs is
very fiddly - you control nothing about what the _other_ VMAs are doing
i.e. have no stability on that, so you may observe unexpected things in a
traversal.
Suren has written a lot about this into the VMA lock work around /proc/$pid/maps
(in both comments and commit msgs and what is asserted in self tests) so I
suggest having a look at that code in the meantime to assess what would need to
be taken into account in this approach.
--
Cheers, Lorenzo