From: "Barry Song (Xiaomi)" <baohua@kernel.org>
To: akpm@linux-foundation.org
Cc: hannes@cmpxchg.org, mhocko@kernel.org, qi.zheng@linux.dev,
shakeel.butt@linux.dev, kasong@tencent.com,
axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com,
baoquan.he@linux.dev, baolin.wang@linux.alibaba.com,
mason@kernel.org, david@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, ridong.chen@linux.dev,
yuzhao@google.com, Barry Song <baohua@kernel.org>
Subject: [PATCH 1/3] mm/mglru: count all generations as evictable
Date: Sun, 29 Nov 2026 22:37:57 +0800 [thread overview]
Message-ID: <20261129143759.96221-2-baohua@kernel.org> (raw)
In-Reply-To: <20261129143759.96221-1-baohua@kernel.org>
From: Chris Mason <mason@kernel.org>
With MGLRU enabled, clean page cache that was reparented from a removed
memory cgroup can stay unreclaimable for as long as the parent has no
other evictable folios on the same node.
try_to_shrink_lruvec() derives its scan count from
lruvec_evictable_size(), and with a count of 0 it runs neither eviction
nor aging. lruvec_evictable_size() adds up nr_pages[] only for the
generations from min_seq to max_seq. That sum is complete only if the
count of a generation is 0 by the time min_seq advances past it.
But try_to_inc_min_seq() ignores the counts: it advances min_seq past a
generation as soon as the lists of that generation are empty. A folio
that folio_update_gen() promoted is counted in its new generation, but
stays on the list of the generation that it came from. Normally min_seq
stops at that list, before it reaches the new generation.
Reparenting moves each list and each count to the same index in the
parent, where that index can stand for a different age:
index (seq % MAX_NR_GENS) 0 1 2 3
seq in the child 0 1 2 3
seq in the parent 4 5 6 3
folio F: on folios[0], counted in nr_pages[3]
child: folios[0] holds min_seq at 0
parent: folios[3] is empty, so min_seq goes from 3 to 4
sum: nr_pages[0] + nr_pages[1] + nr_pages[2] = 0, without F
The fix used here is to add up nr_pages[] of all MAX_NR_GENS generations
in lruvec_evictable_size().
Fixes: 163bc3d68c9f ("mm/mglru: restructure the reclaim loop")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
[Barry: Rebased onto mm-new and added comments]
Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
---
mm/vmscan.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index cbed395955d4..60c416819c57 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4272,8 +4272,6 @@ static void lruvec_evictable_size(struct lruvec *lruvec, struct scan_control *sc
struct lru_gen_folio *lrugen = &lruvec->lrugen;
struct mem_cgroup *memcg = lruvec_memcg(lruvec);
int nid = lruvec_pgdat(lruvec)->node_id;
- DEFINE_MAX_SEQ(lruvec);
- DEFINE_MIN_SEQ(lruvec);
nr[LRU_GEN_ANON] = 0;
nr[LRU_GEN_FILE] = 0;
@@ -4281,7 +4279,12 @@ static void lruvec_evictable_size(struct lruvec *lruvec, struct scan_control *sc
for_each_evictable_type(type, swappiness) {
if (type == LRU_GEN_ANON && !can_reclaim_anon_pages(memcg, nid, sc))
continue;
- for (seq = min_seq[type]; seq <= max_seq; seq++)
+ /*
+ * Reparenting can leave folios accounted for in
+ * generations outside [min_seq, max_seq]. Count
+ * them as well to ensure reclaim makes progress.
+ */
+ for (seq = 0; seq < MAX_NR_GENS; seq++)
nr[type] += lruvec_gen_size(lrugen, type, seq, max_zone);
}
}
--
2.39.3 (Apple Git-146)
next prev parent reply other threads:[~2026-11-29 14:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 14:37 [PATCH 0/3] mm/mglru: fix a few reclaim issues Barry Song (Xiaomi)
2026-11-29 14:37 ` Barry Song (Xiaomi) [this message]
2026-11-29 14:37 ` [PATCH 2/3] mm/mglru: test PG_lru before taking a folio reference Barry Song (Xiaomi)
2026-11-29 14:37 ` [PATCH 3/3] mm/mglru: report root reclaim to memory.pressure_level Barry Song (Xiaomi)
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=20261129143759.96221-2-baohua@kernel.org \
--to=baohua@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mason@kernel.org \
--cc=mhocko@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=ridong.chen@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=yuzhao@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
all inboxes | Powered by JetHome®