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 --- 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 #include #include +#include #include #include @@ -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 Signed-off-by: Zicheng Wang --- mm/Kconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/Kconfig b/mm/Kconfig index e443fe8cd..be7efa794 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1325,6 +1325,16 @@ config LRU_GEN_STATS config LRU_GEN_WALKS_MMU def_bool y depends on LRU_GEN && ARCH_HAS_HW_PTE_YOUNG + +config LRU_GEN_PROCFS_CTRL + bool "Move lru_gen files from debugfs to procfs" + depends on LRU_GEN && PROC_FS + help + Move lru_gen management from debugfs to procfs (/proc/lru_gen). + This production-ready feature provides critical memory reclaim + prediction and control. It is no longer experimental. + The migration ensures availability in commercial products where + debugfs may be disabled. # } config ARCH_SUPPORTS_PER_VMA_LOCK -- 2.25.1 Signed-off-by: Zicheng Wang --- Documentation/admin-guide/mm/multigen_lru.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/admin-guide/mm/multigen_lru.rst b/Documentation/admin-guide/mm/multigen_lru.rst index 9cb54b4ff..d9927b254 100644 --- a/Documentation/admin-guide/mm/multigen_lru.rst +++ b/Documentation/admin-guide/mm/multigen_lru.rst @@ -161,3 +161,22 @@ cold pages because of the overestimation, it retries on the next server according to the ranking result obtained from the working set estimation step. This less forceful approach limits the impacts on the existing jobs. + +Procfs Migration +================ +The multi-gen LRU control interface has been moved from debugfs to procfs +via ``CONFIG_LRU_GEN_PROCFS_CTRL``: + +New Path +-------- +- Control interface: ``/proc/lru_gen`` +- Replaces debugfs path: ``/sys/kernel/debug/lru_gen`` + +Key Advantages +-------------- +1. Production-ready availability (works when debugfs is not allowed) +2. Maintains identical ABI to original debugfs interface +3. Preserves all core functionality (working set estimation, proactive reclaim) +4. Standardized location matching memory management conventions + +Note: Requires both ``CONFIG_PROC_FS`` and ``CONFIG_LRU_GEN`` -- 2.25.1