Re: [PATCH v3 1/4] mm: avoid unnecessary lru drain for wp_can_reuse_anon_folio()

From: Kairui Song

Date: Tue Jul 07 2026 - 11:42:08 EST


On Mon, Jul 6, 2026 at 4:54 PM Barry Song <baohua@xxxxxxxxxx> wrote:
>
> On Thu, Jul 2, 2026 at 4:05 PM David Hildenbrand (Arm) <david@xxxxxxxxxx> wrote:
> >
> > On 7/2/26 01:59, Barry Song (Xiaomi) wrote:
> > > There is a case where `folio_ref_count(folio) == 3` and
> > > `!folio_test_swapcache(folio)`. In that case, both
> > > `folio_ref_count(folio) > 3` and
> > > `folio_ref_count(folio) > 1 + folio_test_swapcache(folio)` evaluate
> > > false, causing an unnecessary local LRU drain.
> > >
> > > During an Ubuntu boot, I observed over 5,000 redundant local LRU
> > > drains. For a kernel build with a minimal configuration, I observed
> > > more than 20,000 redundant drains.
> > >
> > > Fix this by checking against: `1 + in_swapcache + in_lrucache`
> > > instead of hardcoding `folio_ref_count(folio) > 3`.
> > >
> > > Suggested-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> > > Reviewed-by: Kairui Song <kasong@xxxxxxxxxxx>
> > > Acked-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>
> > > Reviewed-by: Baoquan He <baoquan.he@xxxxxxxxx>
> > > Signed-off-by: Barry Song (Xiaomi) <baohua@xxxxxxxxxx>
> > > ---
> > The other folks should probably re-review this patch that changed quite a bit :)
> >
> >
> > Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> Thanks!
>
> Hi Baoquan, Shakeel, and Kairui,
>
> Would you like to re-review the patches so I can re-collect your
> tags? If not, are you okay with me removing your tags when I
> send v4?

Sure, no problem.

The only complain from me, and a trivial one is that `in_lru_cache =
!folio_test_lru(folio)` looks a bit odd. !folio_test_lru only means
the folio is not on the lru. Could it be off the lru due to isolation or
other reason? In this context it just indicates that we should try
to flush lru cache and attempt release the ref. It's trivial, just hope
people won't be confused by this. The code is correct and sound
though, so:

Reviewed-by: Kairui Song <kasong@xxxxxxxxxxx>