From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: linux-mm@kvack.org
Cc: "Jiayuan Chen" <jiayuan.chen@shopee.com>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>,
"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"Axel Rasmussen" <axelrasmussen@google.com>,
"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Muchun Song" <muchun.song@linux.dev>,
"Qi Zheng" <zhengqi.arch@bytedance.com>,
cgroups@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/3] mm/lru_gen: refactor to extract helper functions
Date: Wed, 21 Jan 2026 20:39:47 +0800 [thread overview]
Message-ID: <20260121123955.84806-2-jiayuan.chen@linux.dev> (raw)
In-Reply-To: <20260121123955.84806-1-jiayuan.chen@linux.dev>
From: Jiayuan Chen <jiayuan.chen@shopee.com>
Extract helper functions from debugfs interface for code reuse:
- lru_gen_print_lruvec(): Print generations for a single lruvec,
extracted from lru_gen_seq_show().
- __run_cmd(): Core command execution logic, extracted from run_cmd().
These helpers will be used by the upcoming memcg interface.
No functional change.
Signed-off-by: Jiayuan Chen <jiayuan.chen@shopee.com>
---
mm/vmscan.c | 82 +++++++++++++++++++++++++++++++----------------------
1 file changed, 48 insertions(+), 34 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 619691aa4393..8ea5b67daa36 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -5397,29 +5397,13 @@ static void lru_gen_seq_show_full(struct seq_file *m, struct lruvec *lruvec,
seq_putc(m, '\n');
}
-/* see Documentation/admin-guide/mm/multigen_lru.rst for details */
-static int lru_gen_seq_show(struct seq_file *m, void *v)
+/* Print generations for a single lruvec - helper for debugfs and memcg */
+static void lru_gen_print_lruvec(struct seq_file *m, struct lruvec *lruvec,
+ unsigned long max_seq, unsigned long *min_seq,
+ bool full)
{
unsigned long seq;
- bool full = debugfs_get_aux_num(m->file);
- struct lruvec *lruvec = v;
struct lru_gen_folio *lrugen = &lruvec->lrugen;
- int nid = lruvec_pgdat(lruvec)->node_id;
- struct mem_cgroup *memcg = lruvec_memcg(lruvec);
- DEFINE_MAX_SEQ(lruvec);
- DEFINE_MIN_SEQ(lruvec);
-
- if (nid == first_memory_node) {
- const char *path = memcg ? m->private : "";
-
-#ifdef CONFIG_MEMCG
- if (memcg)
- cgroup_path(memcg->css.cgroup, m->private, PATH_MAX);
-#endif
- seq_printf(m, "memcg %5hu %s\n", mem_cgroup_id(memcg), path);
- }
-
- seq_printf(m, " node %5d\n", nid);
if (!full)
seq = evictable_min_seq(min_seq, MAX_SWAPPINESS / 2);
@@ -5431,7 +5415,7 @@ static int lru_gen_seq_show(struct seq_file *m, void *v)
for (; seq <= max_seq; seq++) {
int type, zone;
int gen = lru_gen_from_seq(seq);
- unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]);
+ unsigned long birth = READ_ONCE(lrugen->timestamps[gen]);
seq_printf(m, " %10lu %10u", seq, jiffies_to_msecs(jiffies - birth));
@@ -5450,7 +5434,31 @@ static int lru_gen_seq_show(struct seq_file *m, void *v)
if (full)
lru_gen_seq_show_full(m, lruvec, max_seq, min_seq, seq);
}
+}
+
+/* see Documentation/admin-guide/mm/multigen_lru.rst for details */
+static int lru_gen_seq_show(struct seq_file *m, void *v)
+{
+ bool full = debugfs_get_aux_num(m->file);
+ struct lruvec *lruvec = v;
+ int nid = lruvec_pgdat(lruvec)->node_id;
+ struct mem_cgroup *memcg = lruvec_memcg(lruvec);
+ DEFINE_MAX_SEQ(lruvec);
+ DEFINE_MIN_SEQ(lruvec);
+
+ if (nid == first_memory_node) {
+ const char *path = memcg ? m->private : "";
+
+#ifdef CONFIG_MEMCG
+ if (memcg)
+ cgroup_path(memcg->css.cgroup, m->private, PATH_MAX);
+#endif
+ seq_printf(m, "memcg %5hu %s\n", mem_cgroup_id(memcg), path);
+ }
+ seq_printf(m, " node %5d\n", nid);
+
+ lru_gen_print_lruvec(m, lruvec, max_seq, min_seq, full);
return 0;
}
@@ -5501,6 +5509,24 @@ static int run_eviction(struct lruvec *lruvec, unsigned long seq, struct scan_co
return -EINTR;
}
+/* Core command execution - helper for debugfs and memcg */
+static int __run_cmd(char cmd, struct lruvec *lruvec, unsigned long seq,
+ struct scan_control *sc, int swappiness, unsigned long opt)
+{
+ if (swappiness < MIN_SWAPPINESS)
+ swappiness = get_swappiness(lruvec, sc);
+ else if (swappiness > SWAPPINESS_ANON_ONLY)
+ return -EINVAL;
+
+ switch (cmd) {
+ case '+':
+ return run_aging(lruvec, seq, swappiness, opt);
+ case '-':
+ return run_eviction(lruvec, seq, sc, swappiness, opt);
+ }
+ return -EINVAL;
+}
+
static int run_cmd(char cmd, int memcg_id, int nid, unsigned long seq,
struct scan_control *sc, int swappiness, unsigned long opt)
{
@@ -5530,19 +5556,7 @@ static int run_cmd(char cmd, int memcg_id, int nid, unsigned long seq,
sc->target_mem_cgroup = memcg;
lruvec = get_lruvec(memcg, nid);
- if (swappiness < MIN_SWAPPINESS)
- swappiness = get_swappiness(lruvec, sc);
- else if (swappiness > SWAPPINESS_ANON_ONLY)
- goto done;
-
- switch (cmd) {
- case '+':
- err = run_aging(lruvec, seq, swappiness, opt);
- break;
- case '-':
- err = run_eviction(lruvec, seq, sc, swappiness, opt);
- break;
- }
+ err = __run_cmd(cmd, lruvec, seq, sc, swappiness, opt);
done:
mem_cgroup_put(memcg);
--
2.43.0
next prev parent reply other threads:[~2026-01-21 12:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 12:39 [RFC PATCH 0/3] mm/lru_gen: add memory.lru_gen interface for cgroup v2 Jiayuan Chen
2026-01-21 12:39 ` Jiayuan Chen [this message]
2026-01-21 12:39 ` [RFC PATCH 2/3] " Jiayuan Chen
2026-01-21 12:39 ` [RFC PATCH 3/3] docs/cgroup: document memory.lru_gen interface Jiayuan Chen
2026-01-21 22:19 ` [RFC PATCH 0/3] mm/lru_gen: add memory.lru_gen interface for cgroup v2 Shakeel Butt
2026-01-22 1:30 ` Jiayuan Chen
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=20260121123955.84806-2-jiayuan.chen@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=cgroups@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=jiayuan.chen@shopee.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=vbabka@suse.cz \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=zhengqi.arch@bytedance.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