From: Ridong Chen <ridong.chen@linux.dev>
To: Kairui Song <ryncsn@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Barry Song <baohua@kernel.org>, Qi Zheng <qi.zheng@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Baoquan He <baoquan.he@linux.dev>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
"open list:MEMORY MANAGEMENT - MGLRU (MULTI-GEN LRU)"
<linux-mm@kvack.org>, Ridong Chen <chenridong@xiaomi.com>
Subject: Re: [RFC PATCH 0/2] mm/mglru: shorten the lru_lock hold time in scan_folios()
Date: Fri, 4 Dec 2026 18:36:14 +0800 [thread overview]
Message-ID: <ac71b91d-22ed-4209-abcf-1476dd0837d6@linux.dev> (raw)
In-Reply-To: <CAMgjq7BPMcW=F6KtMZe05Nq4kBqQp2Pv991YOt2qv_OLhkbsCw@mail.gmail.com>
On 11/28/2026 4:30 PM, Kairui Song wrote:
> On Sat, Nov 28, 2026 at 9:00 AM Ridong Chen <ridong.chen@linux.dev> wrote:
>>
>>
>>
>> On 11/28/2026 3:34 AM, Kairui Song wrote:
>>> On Fri, Nov 27, 2026 at 02:03:13PM +0800, Ridong Chen wrote:
>>>> From: Ridong Chen <chenridong@xiaomi.com>
>>>>
>>>> When many CPUs reclaim from the same lruvec, they spend most of their
>>>> time spinning on lru_lock, and the time scan_folios() holds the lock
>>>> limits reclaim throughput. With 24 threads refaulting file pages in one
>>>> memcg, about 40% of all cycles went to waiting for lru_lock here.
>>>>
>>>> This series takes per-folio work out of that critical section, along
>>>> the lines of what isolate_lru_folios() already does for the classical
>>>> LRU:
>>>>
>>>> 1. Update the node, memcg and zone LRU sizes once per zone instead of
>>>> once per isolated folio.
>>>>
>>>> 2. Prefetch the previous folio, so the cache miss on its flags and list
>>>> pointers is not taken while holding the lock.
>>>>
>>>> Tested on an i7-13700HX (8P+8E, 24 threads), turbo off and the
>>>> performance governor. 24 files of 128MiB on ext4 on brd, all threads
>>>> in one memcg with memory.max=1G, random 4K pread(), so nearly every
>>>> read refaults and every thread ends up in direct reclaim. Reads per
>>>> second per CPU, mean of 2 runs, with and without each patch in one
>>>> kernel and the runs interleaved:
>>>>
>>>> CPUs base patch 1 patch 2 both
>>>> 1 426681 -0.4% -0.2% +0.3%
>>>> 2 387442 +0.7% +1.2% +1.4%
>>>> 4 360312 +1.0% +1.5% +2.1%
>>>> 8 314549 +2.5% +2.5% +3.3%
>>>> 12 235058 +3.2% +4.3% +5.6%
>>>> 16 184086 +9.4% +9.2% +11.2%
>>>> 24 124478 +15.5% +16.5% +21.6%
>>>>
>>>> The gain grows with the number of CPUs reclaiming from one lruvec;
>>>> with a few CPUs there is little contention and no measurable change.
>>>>
>>>> Ridong Chen (2):
>>>> mm/mglru: update LRU sizes once per zone when isolating folios
>>>> mm/mglru: prefetch the previous folio in scan_folios()
>>>>
>>>> include/linux/mm_inline.h | 26 ++++++++++++++++++++++++--
>>>> mm/vmscan.c | 18 +++++++++++++++---
>>>> 2 files changed, 39 insertions(+), 5 deletions(-)
>>>
>>> Hi Ridong
>>>
>>> I have a different approach proposed about two years ago:
>>>
>>> https://lore.kernel.org/all/20240123184552.59758-1-ryncsn@gmail.com/
>>>
>>> I hesitated to push that as the end to end gain was not
>>> that large (5-10%) fio and it makes the code too complex.
>>> But I think that one may work very well for microbench.
>>>
>>> I tried to resurrect that 2 weeks ago, but realized it's not
>>> the best time at the moment, there are too many things in flight
>>> for MGLRU:
>>>
>>> https://github.com/ryncsn/linux/commits/b4/mglru-isolation/
>>>
>>> Perhaps we can discuss and see if using a "batch struct" could
>>> fit better later? It should also unify the aging batch too.
>>
>> Hi Kairui,
>>
>> Thanks for the pointers.
>>
>> I'm fine with handling the batching together with your batch struct
>> work later, and happy to fold the nr_taken[] part of patch 1 into it
>> when the time comes.
>>
>> Patch 2 (prefetch) is independent of that, though. It is the
>> one-liner Chris suggested for your v3 1/3, which he said he would ack
>> if resent on its own [1]; the inc_min_seq() half of it has since been
>> done by commit 5d3664f070f0 ("mm/mglru: move folios from oldest gen to
>> second-oldest gen from head to tail"). It is a no-op on archs without
>> prefetch, the same thing isolate_lru_folios() already does for the
>> classical LRU, and it gave +16.5% alone with 24 CPUs in my test.
>
> I'm actually a bit skeptical about the real effect of this, and the
> previous work for inc_min_seq... for example if you read:
> https://lwn.net/Articles/444336/
>
> In my previous attempt 2 years ago, I did more than just synthetic
> microbenchmarks, on three different CPUs, 5900HX, i7-9700, 8255C and
> 7K62. The results changed dramatically; it's not a x86 vs ARM thing,
> but is strongly affected by the actual microarchitecture design (which
> is not surprising). So my conclusion was that it isn't worth the
> complexity, especially considering that modern hardware branch
> prediction is much smarter and memory pressure is mostly random. In
> the longterm we should work on getting rid of the LRU "as a double
> linked list". The branch check may even bring negative effects, IMO.
>
>>
>> Would you be OK with taking the prefetch patch now, with batching left
>> for later? I can resend it as a standalone patch.
>
> But that sounds ok to me, it wasn't too ugly now considering we
> already have all the wheels. If that solves the problem for you, let's
> have it.
>
Hi Kairui,
Sorry for the late reply.
I've been looking at MGLRU direct reclaim tail latency on Android.
When many tasks enter direct reclaim at the same time they pile up on
the same memcgs and slow each other down [1], so the time spent under
lru_lock matters there.
To check the prefetch on arm64, I ran the same kind of microbenchmark
on an 8-CPU tablet: random 4K pread() on files 3x the memcg limit,
one thread per CPU, all threads in one memcg, base and patched
interleaved in one boot, 5 rounds each. Reads per second per thread:
threads base prefetch
1 180688 +1.5%
2 189663 +2.0%
4 181787 +3.2%
6 168018 +3.8%
8 146523 +6.1%
From 4 threads on, every round was faster, and there was no regression
with 1 thread.
So the gain is there on arm64 too, and the change is a single line,
the same as isolate_lru_folios() already does. I'll resend the
prefetch patch on its own and leave the batching for your batch
struct work.
[1] https://lore.kernel.org/linux-mm/20261119065043.398-1-ridong.chen@linux.dev/
> For the batching part my concern is that how should we balance the
> stack usage and batching size, vmscan have a bad history of causing
> too many stack using, with a batch on stack it will get worse, perhaps
> we should put it somewhere else, but I think this can be done later
> too, after FG maybe.
--
Best regards
Ridong
next prev parent reply other threads:[~2026-12-04 10:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 6:03 [RFC PATCH 0/2] mm/mglru: shorten the lru_lock hold time in scan_folios() Ridong Chen
2026-11-27 6:03 ` [RFC PATCH 1/2] mm/mglru: update LRU sizes once per zone when isolating folios Ridong Chen
2026-11-27 6:03 ` [RFC PATCH 2/2] mm/mglru: prefetch the previous folio in scan_folios() Ridong Chen
2026-11-27 19:34 ` [RFC PATCH 0/2] mm/mglru: shorten the lru_lock hold time " Kairui Song
2026-11-28 1:00 ` Ridong Chen
2026-11-28 8:30 ` Kairui Song
2026-12-04 10:36 ` Ridong Chen [this message]
2026-12-04 10:51 ` Barry Song
2026-12-04 11:00 ` Ridong Chen
2026-12-04 11:12 ` Barry Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ac71b91d-22ed-4209-abcf-1476dd0837d6@linux.dev \
--to=ridong.chen@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=chenridong@xiaomi.com \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=qi.zheng@linux.dev \
--cc=rppt@kernel.org \
--cc=ryncsn@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox