From: Zicheng Wang <wangzicheng@honor.com>
To: <akpm@linux-foundation.org>, <hannes@cmpxchg.org>,
<david@redhat.com>, <axelrasmussen@google.com>,
<yuanchu@google.com>
Cc: <mhocko@kernel.org>, <zhengqi.arch@bytedance.com>,
<shakeel.butt@linux.dev>, <lorenzo.stoakes@oracle.com>,
<weixugc@google.com>, <Liam.Howlett@oracle.com>, <vbabka@suse.cz>,
<rppt@kernel.org>, <surenb@google.com>, <mhocko@suse.com>,
<corbet@lwn.net>, <linux-mm@kvack.org>,
<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Zicheng Wang <wangzicheng@honor.com>
Subject: [PATCH 1/3] mm/lru_gen: add procfs support for lru_gen interfaces
Date: Fri, 28 Nov 2025 10:53:13 +0800 [thread overview]
Message-ID: <20251128025315.3520689-2-wangzicheng@honor.com> (raw)
In-Reply-To: <20251128025315.3520689-1-wangzicheng@honor.com>
This patch refactors the lru_gen and lru_gen_full control files to allow
their interfaces to be exposed under either debugfs or procfs.
Two main changes:
1. minimal code modification by reusing the existing seq_operations.
2. lru_gen file mode update from 0644 to 0664, so that Android's group
"system" can write to the file when procfs interface is enabled.
Signed-off-by: Zicheng Wang <wangzicheng@honor.com>
---
mm/vmscan.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 674999999..dd30f3949 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -58,6 +58,7 @@
#include <linux/random.h>
#include <linux/mmu_notifier.h>
#include <linux/parser.h>
+#include <linux/proc_fs.h>
#include <asm/tlbflush.h>
#include <asm/div64.h>
@@ -5324,9 +5325,17 @@ static const struct attribute_group lru_gen_attr_group = {
};
/******************************************************************************
- * debugfs interface
+ * lru_gen interface
******************************************************************************/
+static inline bool lru_gen_show_is_full(const struct file *file)
+{
+ /* procfs: i_private = (void *)1 means full
+ * debugfs: also works because debugfs sets i_private
+ */
+ return file->f_inode->i_private != NULL;
+}
+
static void *lru_gen_seq_start(struct seq_file *m, loff_t *pos)
{
struct mem_cgroup *memcg;
@@ -5435,7 +5444,7 @@ static void lru_gen_seq_show_full(struct seq_file *m, struct lruvec *lruvec,
static int lru_gen_seq_show(struct seq_file *m, void *v)
{
unsigned long seq;
- bool full = debugfs_get_aux_num(m->file);
+ bool full = lru_gen_show_is_full(m->file);
struct lruvec *lruvec = v;
struct lru_gen_folio *lrugen = &lruvec->lrugen;
int nid = lruvec_pgdat(lruvec)->node_id;
@@ -5671,6 +5680,7 @@ static int lru_gen_seq_open(struct inode *inode, struct file *file)
return seq_open(file, &lru_gen_seq_ops);
}
+#ifndef CONFIG_LRU_GEN_PROCFS_CTRL
static const struct file_operations lru_gen_rw_fops = {
.open = lru_gen_seq_open,
.read = seq_read,
@@ -5685,6 +5695,22 @@ static const struct file_operations lru_gen_ro_fops = {
.llseek = seq_lseek,
.release = seq_release,
};
+#else
+static const struct proc_ops lru_gen_proc_rw_ops = {
+ .proc_open = lru_gen_seq_open,
+ .proc_read = seq_read,
+ .proc_write = lru_gen_seq_write,
+ .proc_lseek = seq_lseek,
+ .proc_release = seq_release,
+};
+
+static const struct proc_ops lru_gen_proc_ro_ops = {
+ .proc_open = lru_gen_seq_open,
+ .proc_read = seq_read,
+ .proc_lseek = seq_lseek,
+ .proc_release = seq_release,
+};
+#endif
/******************************************************************************
* initialization
@@ -5772,10 +5798,17 @@ static int __init init_lru_gen(void)
if (sysfs_create_group(mm_kobj, &lru_gen_attr_group))
pr_err("lru_gen: failed to create sysfs group\n");
+#ifndef CONFIG_LRU_GEN_PROCFS_CTRL
debugfs_create_file_aux_num("lru_gen", 0644, NULL, NULL, false,
&lru_gen_rw_fops);
debugfs_create_file_aux_num("lru_gen_full", 0444, NULL, NULL, true,
&lru_gen_ro_fops);
+#else
+ proc_create_data("lru_gen", 0664, NULL,
+ &lru_gen_proc_rw_ops, NULL);
+ proc_create_data("lru_gen_full", 0444, NULL,
+ &lru_gen_proc_ro_ops, (void *)1);
+#endif
return 0;
};
--
2.25.1
next prev parent reply other threads:[~2025-11-28 3:10 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-28 2:53 [PATCH 0/3] mm/lru_gen: move lru_gen control interface from debugfs to procfs Zicheng Wang
2025-11-28 2:53 ` Zicheng Wang [this message]
2025-11-28 2:53 ` [PATCH 2/3] mm/lru_gen: add configuration option to select debugfs/procfs for lru_gen Zicheng Wang
2025-11-28 4:33 ` Randy Dunlap
2025-11-28 7:19 ` wangzicheng
2025-12-01 21:35 ` Yuanchu Xie
2025-12-02 2:53 ` wangzicheng
2025-11-28 2:53 ` [PATCH 3/3] mm/lru_gen: document procfs interface " Zicheng Wang
2025-11-28 15:16 ` [PATCH 0/3] mm/lru_gen: move lru_gen control interface from debugfs to procfs Matthew Wilcox
2025-11-28 16:13 ` Liam R. Howlett
2025-12-01 4:13 ` Barry Song
2025-12-01 6:50 ` wangzicheng
2025-12-01 7:02 ` wangzicheng
2025-12-01 7:45 ` Barry Song
2025-12-01 8:14 ` wangzicheng
2025-12-01 8:48 ` Barry Song
2025-12-01 9:54 ` wangzicheng
2025-12-01 10:39 ` Barry Song
2025-12-01 13:32 ` wangzicheng
2025-12-01 16:57 ` Barry Song
2025-12-02 2:28 ` wangzicheng
2025-12-01 9:00 ` Kairui Song
2025-12-01 12:01 ` zhongjinji
2025-12-01 7:13 ` zhongjinji
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=20251128025315.3520689-2-wangzicheng@honor.com \
--to=wangzicheng@honor.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--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
all inboxes | Powered by JetHome®