From: Lian Wang <lianux.mm@gmail.com>
To: Barry Song <baohua@kernel.org>
Cc: Lian Wang <lianux.mm@gmail.com>,
akpm@linux-foundation.org, linux-mm@kvack.org,
hannes@cmpxchg.org, david@kernel.org, mhocko@kernel.org,
qi.zheng@linux.dev, shakeel.butt@linux.dev, ljs@kernel.org,
kasong@tencent.com, axelrasmussen@google.com, yuanchu@google.com,
weixugc@google.com, linux-kernel@vger.kernel.org,
lyugaofei@xiaomi.com, stevensd@chromium.org
Subject: Re: [RFC PATCH v2 1/5] mm: mglru: avoid scanning empty generations in scan_folios()
Date: Thu, 30 Jul 2026 14:41:22 +0800 [thread overview]
Message-ID: <20260730064122.11785-1-lianux.mm@gmail.com> (raw)
In-Reply-To: <CAGsJ_4w=gpjgwkndm3PAmZXxRm+E8ASG=6XFpprWwr3AxnpvSg@mail.gmail.com>
Hi Barry,
I tested a list-based exhaustion check on top of the v2 series.
Using remaining > 0 still misses the case where remaining reaches zero
exactly when the last folio leaves the oldest generation. Since
scan_folios() still holds the lruvec lock, checking the generation's zone
lists directly avoids both this boundary and the scanned/nr_to_scan
page-versus-folio mismatch.
The change below only replaces the exhaustion check. It keeps the
priority-gated fallback unchanged, and reports the MIN_NR_GENS early
return as exhausted to preserve the current v2 behavior.
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 6a73be7590cd..59b8725a0650 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4635,7 +4635,8 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca
static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
struct scan_control *sc, int type, int tier,
- struct list_head *list, int *isolatedp)
+ struct list_head *list, int *isolatedp,
+ bool *scan_exhausted)
{
int i;
int gen;
@@ -4650,8 +4651,10 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
VM_WARN_ON_ONCE(nr_to_scan > MAX_LRU_BATCH);
VM_WARN_ON_ONCE(!list_empty(list));
- if (get_nr_gens(lruvec, type) == MIN_NR_GENS)
+ if (get_nr_gens(lruvec, type) == MIN_NR_GENS) {
+ *scan_exhausted = true;
return 0;
+ }
gen = lru_gen_from_seq(lrugen->min_seq[type]);
@@ -4704,6 +4707,14 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
scanned, skipped, isolated,
type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+ *scan_exhausted = true;
+ for (i = 0; i < MAX_NR_ZONES; i++) {
+ if (!list_empty(&lrugen->folios[gen][type][i])) {
+ *scan_exhausted = false;
+ break;
+ }
+ }
+
*isolatedp = isolated;
return scanned;
}
@@ -4757,11 +4768,13 @@ static int isolate_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
int type = get_type_to_scan(lruvec, swappiness);
for_each_evictable_type(i, swappiness) {
+ bool scan_exhausted;
int scanned;
int tier = get_tier_idx(lruvec, type);
scanned = scan_folios(nr_to_scan, lruvec, sc,
- type, tier, list, isolated);
+ type, tier, list, isolated,
+ &scan_exhausted);
total_scanned += scanned;
if (*isolated) {
@@ -4770,15 +4783,12 @@ static int isolate_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
break;
}
/*
- * If scanned >= nr_to_scan or isolated >= MIN_LRU_BATCH,
- * avoid falling back to the other type. The preferred
- * type is still reclaimable; otherwise, it would have
- * already run out of reclaimable generations. Falling
- * back too readily can disrupt the positive_ctrl_err()
- * bias. Also, only fall back when reclaim is running at
- * a high priority.
+ * The preferred type is still reclaimable unless this scan
+ * target is exhausted. Preserve the existing priority-gated
+ * fallback without inferring exhaustion from scanned, which
+ * counts base pages rather than iterations.
*/
- if (scanned < nr_to_scan && *isolated < MIN_LRU_BATCH) {
+ if (scan_exhausted) {
if (sc->priority > 2)
break;
type = !type;
I built and booted this on an arm64 VM with MGLRU enabled. A fresh
swappiness=200 pressure smoke with a 2 GiB file-cache setup and about
7 GiB of touched anonymous memory completed without a
WARN/Oops/BUG/panic.
Would this be worth considering for the next revision? If I misunderstood
the intended semantics, please ignore this.
Thanks,
Lian
next prev parent reply other threads:[~2026-07-30 6:41 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 12:21 [RFC PATCH v2 0/5] mm: mglru: fix swappiness behavior Barry Song (Xiaomi)
2026-07-26 12:21 ` [RFC PATCH v2 1/5] mm: mglru: avoid scanning empty generations in scan_folios() Barry Song (Xiaomi)
2026-07-27 23:18 ` Barry Song
2026-07-30 6:41 ` Lian Wang [this message]
2026-07-30 7:05 ` Barry Song
2026-07-30 7:21 ` Lian Wang
2026-07-26 12:21 ` [RFC PATCH v2 2/5] mm: mglru: only fall back when reclaim is running at high priority Barry Song (Xiaomi)
2026-07-26 22:08 ` Barry Song
2026-07-26 12:21 ` [RFC PATCH v2 3/5] mm: mglru: prevent min_seq[type] from pointing to an empty generation Barry Song (Xiaomi)
2026-07-26 12:21 ` [RFC PATCH v2 4/5] mm: mglru: run aging when pages are severely imbalanced across gens Barry Song (Xiaomi)
2026-07-28 3:46 ` Zicheng Wang
2026-07-28 11:20 ` Barry Song
2026-07-28 12:27 ` Zicheng Wang
2026-07-29 22:36 ` Barry Song
2026-07-30 11:38 ` wangzicheng
2026-07-30 12:22 ` Kairui Song
2026-07-26 12:21 ` [RFC PATCH v2 5/5] mm: mglru: run aging if the preferred type has no folios in reclaimable gens Barry Song (Xiaomi)
2026-07-31 7:26 ` Baolin Wang
2026-07-31 9:01 ` Barry Song
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=20260730064122.11785-1-lianux.mm@gmail.com \
--to=lianux.mm@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=lyugaofei@xiaomi.com \
--cc=mhocko@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=stevensd@chromium.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
all inboxes | Powered by JetHome®