From: Baoquan He <baoquan.he@linux.dev>
To: linux-mm@kvack.org
Cc: akpm@linux-foundation.org, kasong@tencent.com, baohua@kernel.org,
qi.zheng@linux.dev, shakeel.butt@linux.dev,
axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com,
Baoquan He <baoquan.he@linux.dev>
Subject: [PATCH 3/4] mm/mglru: add debugfs knob to control cross-node empty walk skip threshold
Date: Fri, 7 Aug 2026 17:23:40 +0800 [thread overview]
Message-ID: <20260807092343.4123734-3-baoquan.he@linux.dev> (raw)
In-Reply-To: <20260807092343.4123734-1-baoquan.he@linux.dev>
Convert the hardcoded MGLRU_EMPTY_SKIP_GENS from a #define to a
runtime-tunable variable (mglru_empty_skip_gens, default 4), and
add a debugfs command to control it:
echo "skip_empty <N>" > /sys/kernel/debug/lru_gen (0 = disable, default 4)
echo "skip_empty" > /sys/kernel/debug/lru_gen (show current value)
Setting N=0 disables the cross-node empty walk suppression entirely,
allowing easy A/B testing without recompiling the kernel.
Default 4 matches MAX_NR_GENS so the skip window covers at most
one full LRU generation slide.
This is intended as a development/tuning aid for RFC. Whether it
should graduate to a permanent ABI (sysctl) can be decided once
field data demonstrates the optimization is worth keeping.
Signed-off-by: Baoquan He <baoquan.he@linux.dev>
---
mm/vmscan.c | 41 ++++++++++++++++++++++++++++++++---------
1 file changed, 32 insertions(+), 9 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index c39b392d7b7e..631bcd89b196 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2709,14 +2709,6 @@ static bool should_clear_pmd_young(void)
return arch_has_hw_nonleaf_pmd_young() && get_cap(LRU_GEN_NONLEAF_YOUNG);
}
-/*
- * Cross-node empty walk suppression. lru_gen_use_mm() marks an mm used on all
- * nodes, so aging on a node where the mm has no memory wastes a full page table
- * walk. Skip such an mm for up to MGLRU_EMPTY_SKIP_GENS generations after an
- * empty walk, then force-rescan to close migration/mlock/NUMA-balancing windows.
- */
-#define MGLRU_EMPTY_SKIP_GENS 4
-
/******************************************************************************
* shorthand helpers
******************************************************************************/
@@ -2927,6 +2919,9 @@ static struct lru_gen_mm_state *get_mm_state(struct lruvec *lruvec)
return &lruvec->mm_state;
}
+/* tunable empty-walk skip threshold; defined later, get_next_mm() needs it */
+static unsigned long mglru_empty_skip_gens;
+
static struct mm_struct *get_next_mm(struct lru_gen_mm_walk *walk)
{
int key;
@@ -2951,7 +2946,7 @@ static struct mm_struct *get_next_mm(struct lru_gen_mm_walk *walk)
DEFINE_MAX_SEQ(walk->lruvec);
unsigned long empty_seq = READ_ONCE(mm->lru_gen.empty_map_seq);
- if (max_seq < empty_seq + MGLRU_EMPTY_SKIP_GENS)
+ if (max_seq < empty_seq + READ_ONCE(mglru_empty_skip_gens))
return NULL; /* skip: < K gens since empty */
/* K generations passed â force rescan */
@@ -4273,6 +4268,15 @@ static bool lruvec_is_reclaimable(struct lruvec *lruvec, struct scan_control *sc
/* to protect the working set of the last N jiffies */
static unsigned long lru_gen_min_ttl __read_mostly;
+/*
+ * Cross-node empty-walk skip threshold: skip an mm on node N for up to
+ * @mglru_empty_skip_gens generations after an empty walk, then force-rescan
+ * (closes migration/mlock/NUMA-balancing windows). Default 4 matches
+ * MAX_NR_GENS; 0 disables the suppression. Tunable via:
+ * echo "skip_empty <N>" > /sys/kernel/debug/lru_gen
+ */
+static unsigned long mglru_empty_skip_gens __read_mostly = 4;
+
static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc)
{
struct mem_cgroup *memcg;
@@ -5870,6 +5874,25 @@ static ssize_t lru_gen_seq_write(struct file *file, const char __user *src,
if (!*cur)
continue;
+ /*
+ * set/show the empty-walk skip threshold: "skip_empty <N>"
+ */
+ if (!strncmp(cur, "skip_empty", 10)) {
+ cur += 10;
+ cur = skip_spaces(cur);
+ if (*cur) {
+ unsigned long val;
+
+ if (sscanf(cur, "%lu", &val) == 1)
+ WRITE_ONCE(mglru_empty_skip_gens, val);
+ } else {
+ pr_info("MGLRU empty skip threshold: %lu generations (0=disabled)\n",
+ READ_ONCE(mglru_empty_skip_gens));
+ }
+ err = 0;
+ continue;
+ }
+
n = sscanf(cur, "%c %llu %u %lu %n %4s %n %lu %n", &cmd, &memcg_id, &nid,
&seq, &end, swap_string, &end, &opt, &end);
if (n < 4 || cur[end]) {
--
2.54.0
next prev parent reply other threads:[~2026-08-07 9:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 10:29 [RFC PATCH 0/6] mm/mglru: skip empty PUD subtrees during aging with PUD-level Bloom filter Baoquan He
2026-08-06 10:29 ` [RFC PATCH 1/6] mm/mglru: add PUD-level Bloom filter state Baoquan He
2026-08-06 10:29 ` [RFC PATCH 2/6] mm/mglru: refactor Bloom filter helpers for two filter levels Baoquan He
2026-08-06 10:29 ` [RFC PATCH 3/6] mm/mglru: skip empty PUD subtrees during aging Baoquan He
2026-08-06 10:29 ` [RFC PATCH 4/6] mm/mglru: report hot PUDs from the rmap feedback path Baoquan He
2026-08-06 10:29 ` [RFC PATCH 5/6] mm/mglru: add MM_WALK_EMPTY stats and tracepoint for cross-node measurement Baoquan He
2026-08-06 11:05 ` [RFC PATCH 0/6] mm/mglru: skip empty PUD subtrees during aging with PUD-level Bloom filter Baoquan He
2026-08-07 9:23 ` [PATCH 1/4] mm/mglru: add MM_WALK_EMPTY stats and tracepoint for cross-node measurement Baoquan He
2026-08-07 9:23 ` [PATCH 2/4] mm/mglru: suppress cross-node empty page table walks Baoquan He
2026-08-07 9:23 ` Baoquan He [this message]
2026-08-07 9:23 ` [PATCH 4/4] mm/mglru: invalidate empty-walk skip on page fault and migration Baoquan He
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=20260807092343.4123734-3-baoquan.he@linux.dev \
--to=baoquan.he@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=kasong@tencent.com \
--cc=linux-mm@kvack.org \
--cc=qi.zheng@linux.dev \
--cc=shakeel.butt@linux.dev \
--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