mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] mm/mglru: use a smaller batch in fill/drain_evictable()
@ 2026-11-16  6:11 Hui Zhu
  2026-11-16  7:29 ` Baolin Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Hui Zhu @ 2026-11-16  6:11 UTC (permalink / raw)
  To: Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko,
	Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Barry Song,
	Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang,
	linux-mm, linux-kernel
  Cc: Hui Zhu

From: Hui Zhu <zhuhui@kylinos.cn>

lru_gen_change_state() migrates folios in batches of up to
MAX_LRU_BATCH (4096) folios under lruvec_lock_irq().  A full batch
keeps local interrupts off for up to about a millisecond, and CPUs
contending for the same lru_lock spin with interrupts disabled for
that long.

The caller already drops the lock and reschedules between batches,
and the restart protocol does not depend on the batch size: both
functions make monotone progress, so a smaller batch only shortens
the irq-off section.  Use MIN_LRU_BATCH (64) instead, bounding it to
about 15us.  This is a cold path that runs once per kill-switch
toggle; the extra unlock/resched/relock round trips cost a few
percent of wall time on an otherwise idle machine.

Same change as commit 6e9be217a3ce ("mm/mglru: use a smaller batch
for reclaim") made for try_to_shrink_lruvec().

Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
---
Changlog:
v3:
Drop the need_resched()/spin_is_contended() checks and shrink the batch
to MIN_LRU_BATCH instead (Baolin Wang).
v2:
Also yield on lock contention after a minimum batch (Kairui Song).

 mm/vmscan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 6a1af9b92349..054af6cf6a2e 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -5499,7 +5499,7 @@ static bool __maybe_unused state_is_valid(struct lruvec *lruvec)
 static bool fill_evictable(struct lruvec *lruvec)
 {
 	enum lru_list lru;
-	int remaining = MAX_LRU_BATCH;
+	int remaining = MIN_LRU_BATCH;
 
 	for_each_evictable_lru(lru) {
 		int type = is_file_lru(lru);
@@ -5544,7 +5544,7 @@ static bool fill_evictable(struct lruvec *lruvec)
 static bool drain_evictable(struct lruvec *lruvec)
 {
 	int gen, type, zone;
-	int remaining = MAX_LRU_BATCH;
+	int remaining = MIN_LRU_BATCH;
 
 	for_each_gen_type_zone(gen, type, zone) {
 		struct list_head *head = &lruvec->lrugen.folios[gen][type][zone];
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] mm/mglru: use a smaller batch in fill/drain_evictable()
  2026-11-16  6:11 [PATCH v3] mm/mglru: use a smaller batch in fill/drain_evictable() Hui Zhu
@ 2026-11-16  7:29 ` Baolin Wang
  2026-11-16  7:47   ` Barry Song
  0 siblings, 1 reply; 3+ messages in thread
From: Baolin Wang @ 2026-11-16  7:29 UTC (permalink / raw)
  To: Hui Zhu, Andrew Morton, Johannes Weiner, David Hildenbrand,
	Michal Hocko, Qi Zheng, Shakeel Butt, Lorenzo Stoakes,
	Kairui Song, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu,
	Baoquan He, linux-mm, linux-kernel
  Cc: Hui Zhu



On 11/16/26 2:11 PM, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
> 
> lru_gen_change_state() migrates folios in batches of up to
> MAX_LRU_BATCH (4096) folios under lruvec_lock_irq().  A full batch
> keeps local interrupts off for up to about a millisecond, and CPUs
> contending for the same lru_lock spin with interrupts disabled for
> that long.
> 
> The caller already drops the lock and reschedules between batches,
> and the restart protocol does not depend on the batch size: both
> functions make monotone progress, so a smaller batch only shortens
> the irq-off section.  Use MIN_LRU_BATCH (64) instead, bounding it to
> about 15us.  This is a cold path that runs once per kill-switch
> toggle; the extra unlock/resched/relock round trips cost a few
> percent of wall time on an otherwise idle machine.
> 
> Same change as commit 6e9be217a3ce ("mm/mglru: use a smaller batch
> for reclaim") made for try_to_shrink_lruvec().
> 
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> ---

I'm fine if the small change can fix your issue in this cold path. Let's 
also see others' input. Feel free to add:
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] mm/mglru: use a smaller batch in fill/drain_evictable()
  2026-11-16  7:29 ` Baolin Wang
@ 2026-11-16  7:47   ` Barry Song
  0 siblings, 0 replies; 3+ messages in thread
From: Barry Song @ 2026-11-16  7:47 UTC (permalink / raw)
  To: Baolin Wang
  Cc: Hui Zhu, Andrew Morton, Johannes Weiner, David Hildenbrand,
	Michal Hocko, Qi Zheng, Shakeel Butt, Lorenzo Stoakes,
	Kairui Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He,
	linux-mm, linux-kernel, Hui Zhu

On Mon, Nov 16, 2026 at 3:29 PM Baolin Wang
<baolin.wang@linux.alibaba.com> wrote:
>
>
>
> On 11/16/26 2:11 PM, Hui Zhu wrote:
> > From: Hui Zhu <zhuhui@kylinos.cn>
> >
> > lru_gen_change_state() migrates folios in batches of up to
> > MAX_LRU_BATCH (4096) folios under lruvec_lock_irq().  A full batch
> > keeps local interrupts off for up to about a millisecond, and CPUs
> > contending for the same lru_lock spin with interrupts disabled for
> > that long.
> >
> > The caller already drops the lock and reschedules between batches,
> > and the restart protocol does not depend on the batch size: both
> > functions make monotone progress, so a smaller batch only shortens
> > the irq-off section.  Use MIN_LRU_BATCH (64) instead, bounding it to
> > about 15us.  This is a cold path that runs once per kill-switch
> > toggle; the extra unlock/resched/relock round trips cost a few
> > percent of wall time on an otherwise idle machine.
> >
> > Same change as commit 6e9be217a3ce ("mm/mglru: use a smaller batch
> > for reclaim") made for try_to_shrink_lruvec().
> >
> > Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> > ---
>
> I'm fine if the small change can fix your issue in this cold path. Let's
> also see others' input. Feel free to add:
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

+1

This is a rarely used code path, and we may eventually remove it
entirely. So let's avoid over-engineering it.

Reviewed-by: Barry Song <baohua@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-16  7:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16  6:11 [PATCH v3] mm/mglru: use a smaller batch in fill/drain_evictable() Hui Zhu
2026-11-16  7:29 ` Baolin Wang
2026-11-16  7:47   ` Barry Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®