Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ridong Chen <ridong.chen@linux.dev>
To: Kairui Song <ryncsn@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kairui Song <kasong@tencent.com>,
	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: Sat, 28 Nov 2026 09:00:03 +0800	[thread overview]
Message-ID: <42195463-c50b-4f80-ad2c-ecc106e4c2ae@linux.dev> (raw)
In-Reply-To: <awnYv_mxag0b6Dny@KASONG-MC4>



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.

Would you be OK with taking the prefetch patch now, with batching left
for later? I can resend it as a standalone patch.

-- 
Best regards
Ridong



      reply	other threads:[~2026-11-28  1:00 UTC|newest]

Thread overview: 5+ 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 [this message]

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=42195463-c50b-4f80-ad2c-ecc106e4c2ae@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=kasong@tencent.com \
    --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