[PATCH -next 5/5] mm/mglru: factor lrugen state out of shrink_lruvec

Chen Ridong
2025-12-09T01:41:13Z

From: Chen Ridong <chenridong@huawei.com>

A previous patch updated shrink_node_memcgs to handle lrugen root reclaim
and extended shrink_one to support both lrugen and non-lrugen. However,
in shrink_one, lrugen non-root reclaim still invokes shrink_lruvec, which
should only be used for non-lrugen reclaim.

To clarify the semantics, this patch moves the lrugen-specific logic out of
shrink_lruvec, leaving shrink_lruvec exclusively for non-lrugen reclaim.

Now for lrugen, shrink_one invokes lru_gen_shrink_lruvec, which calls
try_to_shrink_lruvec directly, without extra handling for root reclaim, as
that processing is already done in lru_gen_shrink_node. Non-root reclaim
behavior remains unchanged.

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

diff --git a/mm/vmscan.c b/mm/vmscan.c
index dbf2cfbe3243..c5f517ec52a7 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4762,7 +4762,12 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc
{
struct blk_plug plug;

- VM_WARN_ON_ONCE(root_reclaim(sc));
+ /* Root reclaim has finished other extra work outside, just shrink. */
+ if (root_reclaim(sc)) {
+ try_to_shrink_lruvec(lruvec, sc);
+ return;
+ }
+
VM_WARN_ON_ONCE(!sc->may_writepage || !sc->may_unmap);

lru_add_drain();
@@ -5524,11 +5529,6 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
bool proportional_reclaim;
struct blk_plug plug;

- if (lru_gen_enabled() && !root_reclaim(sc)) {
- lru_gen_shrink_lruvec(lruvec, sc);
- return;
- }
-
get_scan_count(lruvec, sc, nr);

/* Record the original scan target for proportional adjustments later */
@@ -5708,8 +5708,8 @@ static void shrink_one(struct lruvec *lruvec, struct scan_control *sc)
struct pglist_data *pgdat = lruvec_pgdat(lruvec);
struct mem_cgroup *memcg = lruvec_memcg(lruvec);

- if (lru_gen_enabled() && root_reclaim(sc))
- try_to_shrink_lruvec(lruvec, sc);
+ if (lru_gen_enabled())
+ lru_gen_shrink_lruvec(lruvec, sc);
else
shrink_lruvec(lruvec, sc);

--
2.34.1