Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ridong Chen <ridong.chen@linux.dev>
To: Andrew Morton <akpm@linux-foundation.org>,
	Kairui Song <kasong@tencent.com>,
	David Hildenbrand <david@kernel.org>,
	Johannes Weiner <hannes@cmpxchg.org>
Cc: 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>,
	linux-mm@kvack.org (open list:MEMORY MANAGEMENT - MGLRU
	(MULTI-GEN LRU)), Ridong Chen <ridong.chen@linux.dev>,
	Ridong Chen <chenridong@xiaomi.com>
Subject: [RFC PATCH 2/2] mm/mglru: prefetch the previous folio in scan_folios()
Date: Fri, 27 Nov 2026 14:03:15 +0800	[thread overview]
Message-ID: <20261127060315.1119672-3-ridong.chen@linux.dev> (raw)
In-Reply-To: <20261127060315.1119672-1-ridong.chen@linux.dev>

From: Ridong Chen <chenridong@xiaomi.com>

scan_folios() walks a gen list from the tail under lru_lock. Isolating
a folio unlinks it, which writes the lru pointers of its neighbour, and
the next iteration then reads that neighbour's flags. Both miss in the
cache when many CPUs reclaim from the same lruvec, and the misses are
taken while other CPUs wait for the lock.

isolate_lru_folios() prefetches the previous folio for the same
reason, and inc_min_seq() prefetches the next one as it walks its list
from the head. Do the same in scan_folios(), which walks from the tail
like isolate_lru_folios().

Tested on an i7-13700HX (8P+8E cores, 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 this change in one kernel and
the runs interleaved:

  CPUs      base   patched
     1    426681    425912   -0.2%
     2    387442    392010   +1.2%
     4    360312    365538   +1.5%
     8    314549    322524   +2.5%
    12    235058    245057   +4.3%
    16    184086    200956   +9.2%
    24    124478    145011  +16.5%

Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
---
 mm/vmscan.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 9dbdcda04f13..14f75c6fc4a8 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4814,6 +4814,8 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
 			struct folio *folio = lru_to_folio(head);
 			int delta = folio_nr_pages(folio);
 
+			prefetchw_prev_lru_folio(folio, head);
+
 			VM_WARN_ON_ONCE_FOLIO(folio_test_unevictable(folio), folio);
 			VM_WARN_ON_ONCE_FOLIO(folio_test_active(folio), folio);
 			VM_WARN_ON_ONCE_FOLIO(folio_is_file_lru(folio) != type, folio);
-- 
2.34.1



      parent reply	other threads:[~2026-11-27  6:03 UTC|newest]

Thread overview: 3+ 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 ` 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=20261127060315.1119672-3-ridong.chen@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=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