Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/mglru: check need_resched() in fill/drain_evictable()
@ 2026-11-12  7:58 Hui Zhu
  2026-11-12  8:03 ` Kairui Song
  0 siblings, 1 reply; 7+ messages in thread
From: Hui Zhu @ 2026-11-12  7:58 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 reschedules between batches, but a batch itself
only ends after 4096 folios.  Stop it early when a resched is
pending; the caller restarts the migration where it left off.  A
remote resched_curr() sets TIF_NEED_RESCHED directly in the target's
thread_info, so the flag can still be set with interrupts off.

This follows walk_pud_range(), which already pairs need_resched()
with a MAX_LRU_BATCH cap, and commit 6e9be217a3ce ("mm/mglru: use a
smaller batch for reclaim").

Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
---
 mm/vmscan.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 6a1af9b92349..47f2cb25eb46 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -5533,7 +5533,8 @@ static bool fill_evictable(struct lruvec *lruvec)
 			success = lru_gen_add_folio(lruvec, folio, !active);
 			VM_WARN_ON_ONCE(!success);
 
-			if (!--remaining)
+			/* stop early to shorten the irq-off section */
+			if (!--remaining || need_resched())
 				return false;
 		}
 	}
@@ -5562,7 +5563,8 @@ static bool drain_evictable(struct lruvec *lruvec)
 			VM_WARN_ON_ONCE(!success);
 			lruvec_add_folio(lruvec, folio);
 
-			if (!--remaining)
+			/* stop early to shorten the irq-off section */
+			if (!--remaining || need_resched())
 				return false;
 		}
 	}
-- 
2.53.0



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

end of thread, other threads:[~2026-11-12 15:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12  7:58 [PATCH] mm/mglru: check need_resched() in fill/drain_evictable() Hui Zhu
2026-11-12  8:03 ` Kairui Song
2026-11-12  8:09   ` Michal Hocko
2026-11-12  8:58     ` Kairui Song
2026-11-12  9:01     ` Hui Zhu
2026-11-12 15:50       ` Kairui Song
2026-11-12  8:50   ` Kairui Song

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