linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files
@ 2024-12-23 14:15 Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 01/15] mm: vmstat: move sysctls to mm/vmstat.c Kaixiong Yu
                   ` (31 more replies)
  0 siblings, 32 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This patch series moves sysctls of vm_table in kernel/sysctl.c to
places where they actually belong, and do some related code clean-ups.
After this patch series, all sysctls in vm_table have been moved into its
own files, meanwhile, delete vm_table.

All the modifications of this patch series base on
linux-next(tags/next-20241219). To test this patch series, the code was
compiled with both the CONFIG_SYSCTL enabled and disabled on arm64 and
x86_64 architectures. After this patch series is applied, all files
under /proc/sys/vm can be read or written normally.

Changes in v4:
 - change all "static struct ctl_table" type into
   "static const struct ctl_table" type in patch1~10,12,13,14
 - simplify result of rpcauth_cache_shrink_count() in patch11

Changes in v3:
 - change patch1~10, patch14 title suggested by Joel Granados
 - change sysctl_stat_interval to static type in patch1
 - add acked-by from Paul Moore in patch7
 - change dirtytime_expire_interval to static type in patch9
 - add acked-by from Anna Schumaker in patch11

Changes in v2:
 - fix sysctl_max_map_count undeclared issue in mm/nommu.c for patch6
 - update changelog for patch7/12, suggested by Kees/Paul
 - fix patch8, sorry for wrong changes and forget to built with NOMMU
 - add reviewed-by from Kees except patch8 since patch8 is wrong in v1
 - add reviewed-by from Jan Kara, Christian Brauner in patch12

Kaixiong Yu (15):
  mm: vmstat: move sysctls to mm/vmstat.c
  mm: filemap: move sysctl to mm/filemap.c
  mm: swap: move sysctl to mm/swap.c
  mm: vmscan: move vmscan sysctls to mm/vmscan.c
  mm: util: move sysctls to mm/util.c
  mm: mmap: move sysctl to mm/mmap.c
  security: min_addr: move sysctl to security/min_addr.c
  mm: nommu: move sysctl to mm/nommu.c
  fs: fs-writeback: move sysctl to fs/fs-writeback.c
  fs: drop_caches: move sysctl to fs/drop_caches.c
  sunrpc: simplify rpcauth_cache_shrink_count()
  fs: dcache: move the sysctl to fs/dcache.c
  x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c
  sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c
  sysctl: remove unneeded include

 arch/sh/kernel/vsyscall/vsyscall.c |  14 ++
 arch/x86/entry/vdso/vdso32-setup.c |  16 ++-
 fs/dcache.c                        |  21 ++-
 fs/drop_caches.c                   |  23 ++-
 fs/fs-writeback.c                  |  30 ++--
 include/linux/dcache.h             |   7 +-
 include/linux/mm.h                 |  23 ---
 include/linux/mman.h               |   2 -
 include/linux/swap.h               |   9 --
 include/linux/vmstat.h             |  11 --
 include/linux/writeback.h          |   4 -
 kernel/sysctl.c                    | 221 -----------------------------
 mm/filemap.c                       |  18 ++-
 mm/internal.h                      |  10 ++
 mm/mmap.c                          |  54 +++++++
 mm/nommu.c                         |  15 +-
 mm/swap.c                          |  16 ++-
 mm/swap.h                          |   1 +
 mm/util.c                          |  67 +++++++--
 mm/vmscan.c                        |  23 +++
 mm/vmstat.c                        |  44 +++++-
 net/sunrpc/auth.c                  |   2 +-
 security/min_addr.c                |  11 ++
 23 files changed, 330 insertions(+), 312 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 01/15] mm: vmstat: move sysctls to mm/vmstat.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 02/15] mm: filemap: move sysctl to mm/filemap.c Kaixiong Yu
                   ` (30 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves all vmstat related sysctls to its own file, removes useless
extern variable declarations, and do some related clean-ups. To avoid
compiler warnings when CONFIG_PROC_FS is not defined, add the macro
definition CONFIG_PROC_FS ahead CONFIG_NUMA in vmstat.c.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vmstat_table
v3:
 - change the title
 - change sysctl_stat_interval to static type
---
---
 include/linux/vmstat.h | 11 -----------
 kernel/sysctl.c        | 28 ---------------------------
 mm/vmstat.c            | 44 ++++++++++++++++++++++++++++++++++++++----
 3 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index 9f3a04345b86..4751e3ecc467 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -10,15 +10,8 @@
 #include <linux/static_key.h>
 #include <linux/mmdebug.h>
 
-extern int sysctl_stat_interval;
-
 #ifdef CONFIG_NUMA
-#define ENABLE_NUMA_STAT   1
-#define DISABLE_NUMA_STAT   0
-extern int sysctl_vm_numa_stat;
 DECLARE_STATIC_KEY_TRUE(vm_numa_stat_key);
-int sysctl_vm_numa_stat_handler(const struct ctl_table *table, int write,
-		void *buffer, size_t *length, loff_t *ppos);
 #endif
 
 struct reclaim_stat {
@@ -304,10 +297,6 @@ void quiet_vmstat(void);
 void cpu_vm_stats_fold(int cpu);
 void refresh_zone_stat_thresholds(void);
 
-struct ctl_table;
-int vmstat_refresh(const struct ctl_table *, int write, void *buffer, size_t *lenp,
-		loff_t *ppos);
-
 void drain_zonestat(struct zone *zone, struct per_cpu_zonestat *);
 
 int calculate_pressure_threshold(struct zone *zone);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7ae7a4136855..f1ab251fc2d0 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -49,7 +49,6 @@
 #include <linux/limits.h>
 #include <linux/dcache.h>
 #include <linux/syscalls.h>
-#include <linux/vmstat.h>
 #include <linux/nfs_fs.h>
 #include <linux/acpi.h>
 #include <linux/reboot.h>
@@ -2071,17 +2070,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_TWO_HUNDRED,
 	},
-#ifdef CONFIG_NUMA
-	{
-		.procname	= "numa_stat",
-		.data		= &sysctl_vm_numa_stat,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= sysctl_vm_numa_stat_handler,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-#endif
 	{
 		.procname	= "drop_caches",
 		.data		= &sysctl_drop_caches,
@@ -2147,22 +2135,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif
-#ifdef CONFIG_SMP
-	{
-		.procname	= "stat_interval",
-		.data		= &sysctl_stat_interval,
-		.maxlen		= sizeof(sysctl_stat_interval),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_jiffies,
-	},
-	{
-		.procname	= "stat_refresh",
-		.data		= NULL,
-		.maxlen		= 0,
-		.mode		= 0600,
-		.proc_handler	= vmstat_refresh,
-	},
-#endif
 #ifdef CONFIG_MMU
 	{
 		.procname	= "mmap_min_addr",
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 4d016314a56c..cb4dcd4c6715 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -31,8 +31,10 @@
 
 #include "internal.h"
 
+#ifdef CONFIG_PROC_FS
 #ifdef CONFIG_NUMA
-int sysctl_vm_numa_stat = ENABLE_NUMA_STAT;
+#define ENABLE_NUMA_STAT 1
+static int sysctl_vm_numa_stat = ENABLE_NUMA_STAT;
 
 /* zero numa counters within a zone */
 static void zero_zone_numa_counters(struct zone *zone)
@@ -74,7 +76,7 @@ static void invalid_numa_statistics(void)
 
 static DEFINE_MUTEX(vm_numa_stat_lock);
 
-int sysctl_vm_numa_stat_handler(const struct ctl_table *table, int write,
+static int sysctl_vm_numa_stat_handler(const struct ctl_table *table, int write,
 		void *buffer, size_t *length, loff_t *ppos)
 {
 	int ret, oldval;
@@ -102,6 +104,7 @@ int sysctl_vm_numa_stat_handler(const struct ctl_table *table, int write,
 	return ret;
 }
 #endif
+#endif /* CONFIG_PROC_FS */
 
 #ifdef CONFIG_VM_EVENT_COUNTERS
 DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
@@ -1938,7 +1941,7 @@ static const struct seq_operations vmstat_op = {
 
 #ifdef CONFIG_SMP
 static DEFINE_PER_CPU(struct delayed_work, vmstat_work);
-int sysctl_stat_interval __read_mostly = HZ;
+static int sysctl_stat_interval __read_mostly = HZ;
 static int vmstat_late_init_done;
 
 #ifdef CONFIG_PROC_FS
@@ -1947,7 +1950,7 @@ static void refresh_vm_stats(struct work_struct *work)
 	refresh_cpu_vm_stats(true);
 }
 
-int vmstat_refresh(const struct ctl_table *table, int write,
+static int vmstat_refresh(const struct ctl_table *table, int write,
 		   void *buffer, size_t *lenp, loff_t *ppos)
 {
 	long val;
@@ -2185,6 +2188,38 @@ static int __init vmstat_late_init(void)
 late_initcall(vmstat_late_init);
 #endif
 
+#ifdef CONFIG_PROC_FS
+static const struct ctl_table vmstat_table[] = {
+#ifdef CONFIG_SMP
+	{
+		.procname	= "stat_interval",
+		.data		= &sysctl_stat_interval,
+		.maxlen		= sizeof(sysctl_stat_interval),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_jiffies,
+	},
+	{
+		.procname	= "stat_refresh",
+		.data		= NULL,
+		.maxlen		= 0,
+		.mode		= 0600,
+		.proc_handler	= vmstat_refresh,
+	},
+#endif
+#ifdef CONFIG_NUMA
+	{
+		.procname	= "numa_stat",
+		.data		= &sysctl_vm_numa_stat,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= sysctl_vm_numa_stat_handler,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+#endif
+};
+#endif
+
 struct workqueue_struct *mm_percpu_wq;
 
 void __init init_mm_internals(void)
@@ -2216,6 +2251,7 @@ void __init init_mm_internals(void)
 	proc_create_seq("pagetypeinfo", 0400, NULL, &pagetypeinfo_op);
 	proc_create_seq("vmstat", 0444, NULL, &vmstat_op);
 	proc_create_seq("zoneinfo", 0444, NULL, &zoneinfo_op);
+	register_sysctl_init("vm", vmstat_table);
 #endif
 }
 
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 02/15] mm: filemap: move sysctl to mm/filemap.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 01/15] mm: vmstat: move sysctls to mm/vmstat.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 03/15] mm: swap: move sysctl to mm/swap.c Kaixiong Yu
                   ` (29 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves the filemap related sysctl to mm/filemap.c, and
removes the redundant external variable declaration.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table filemap_sysctl_table
v3:
 - change the title
---
---
 include/linux/mm.h |  2 --
 kernel/sysctl.c    |  8 --------
 mm/filemap.c       | 18 +++++++++++++++---
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index d61b9c7a3a7b..dbdf8950d681 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -40,8 +40,6 @@ struct user_struct;
 struct pt_regs;
 struct folio_batch;
 
-extern int sysctl_page_lock_unfairness;
-
 void mm_core_init(void);
 void init_mm_internals(void);
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index f1ab251fc2d0..23c8db80da5d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2079,14 +2079,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_FOUR,
 	},
-	{
-		.procname	= "page_lock_unfairness",
-		.data		= &sysctl_page_lock_unfairness,
-		.maxlen		= sizeof(sysctl_page_lock_unfairness),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
 #ifdef CONFIG_MMU
 	{
 		.procname	= "max_map_count",
diff --git a/mm/filemap.c b/mm/filemap.c
index 899dab55d235..bb7aff8960a4 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -47,6 +47,7 @@
 #include <linux/splice.h>
 #include <linux/rcupdate_wait.h>
 #include <linux/sched/mm.h>
+#include <linux/sysctl.h>
 #include <linux/fsnotify.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
@@ -1069,6 +1070,19 @@ static wait_queue_head_t *folio_waitqueue(struct folio *folio)
 	return &folio_wait_table[hash_ptr(folio, PAGE_WAIT_TABLE_BITS)];
 }
 
+/* How many times do we accept lock stealing from under a waiter? */
+static int sysctl_page_lock_unfairness = 5;
+static const struct ctl_table filemap_sysctl_table[] = {
+	{
+		.procname	= "page_lock_unfairness",
+		.data		= &sysctl_page_lock_unfairness,
+		.maxlen		= sizeof(sysctl_page_lock_unfairness),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+	}
+};
+
 void __init pagecache_init(void)
 {
 	int i;
@@ -1077,6 +1091,7 @@ void __init pagecache_init(void)
 		init_waitqueue_head(&folio_wait_table[i]);
 
 	page_writeback_init();
+	register_sysctl_init("vm", filemap_sysctl_table);
 }
 
 /*
@@ -1224,9 +1239,6 @@ static inline bool folio_trylock_flag(struct folio *folio, int bit_nr,
 	return true;
 }
 
-/* How many times do we accept lock stealing from under a waiter? */
-int sysctl_page_lock_unfairness = 5;
-
 static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,
 		int state, enum behavior behavior)
 {
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 03/15] mm: swap: move sysctl to mm/swap.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 01/15] mm: vmstat: move sysctls to mm/vmstat.c Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 02/15] mm: filemap: move sysctl to mm/filemap.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 04/15] mm: vmscan: move vmscan sysctls to mm/vmscan.c Kaixiong Yu
                   ` (28 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The page-cluster belongs to mm/swap.c, move it to mm/swap.c .
Removes the redundant external variable declaration and unneeded
include(linux/swap.h).

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table swap_sysctl_table
v3:
 - change the title
---
---
 include/linux/mm.h |  2 --
 kernel/sysctl.c    | 10 ----------
 mm/swap.c          | 16 +++++++++++++++-
 mm/swap.h          |  1 +
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index dbdf8950d681..8941ba3d9a77 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -76,8 +76,6 @@ static inline void totalram_pages_add(long count)
 }
 
 extern void * high_memory;
-extern int page_cluster;
-extern const int page_cluster_max;
 
 #ifdef CONFIG_SYSCTL
 extern int sysctl_legacy_va_layout;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 23c8db80da5d..ab5d94f07e53 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -21,7 +21,6 @@
 
 #include <linux/module.h>
 #include <linux/mm.h>
-#include <linux/swap.h>
 #include <linux/slab.h>
 #include <linux/sysctl.h>
 #include <linux/bitmap.h>
@@ -2044,15 +2043,6 @@ static struct ctl_table vm_table[] = {
 		.mode		= 0644,
 		.proc_handler	= overcommit_kbytes_handler,
 	},
-	{
-		.procname	= "page-cluster",
-		.data		= &page_cluster,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= (void *)&page_cluster_max,
-	},
 	{
 		.procname	= "dirtytime_expire_seconds",
 		.data		= &dirtytime_expire_interval,
diff --git a/mm/swap.c b/mm/swap.c
index 062c8565b899..d3344123381c 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -45,7 +45,7 @@
 
 /* How many pages do we try to swap or page in/out together? As a power of 2 */
 int page_cluster;
-const int page_cluster_max = 31;
+static const int page_cluster_max = 31;
 
 struct cpu_fbatches {
 	/*
@@ -1072,6 +1072,18 @@ void folio_batch_remove_exceptionals(struct folio_batch *fbatch)
 	fbatch->nr = j;
 }
 
+static const struct ctl_table swap_sysctl_table[] = {
+	{
+		.procname	= "page-cluster",
+		.data		= &page_cluster,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= (void *)&page_cluster_max,
+	}
+};
+
 /*
  * Perform any setup for the swap system
  */
@@ -1088,4 +1100,6 @@ void __init swap_setup(void)
 	 * Right now other parts of the system means that we
 	 * _really_ don't want to cluster much more
 	 */
+
+	register_sysctl_init("vm", swap_sysctl_table);
 }
diff --git a/mm/swap.h b/mm/swap.h
index ad2f121de970..274dcc6219a0 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -3,6 +3,7 @@
 #define _MM_SWAP_H
 
 struct mempolicy;
+extern int page_cluster;
 
 #ifdef CONFIG_SWAP
 #include <linux/swapops.h> /* for swp_offset */
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 04/15] mm: vmscan: move vmscan sysctls to mm/vmscan.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (2 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 03/15] mm: swap: move sysctl to mm/swap.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 05/15] mm: util: move sysctls to mm/util.c Kaixiong Yu
                   ` (27 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves vm_swappiness and zone_reclaim_mode to mm/vmscan.c,
as part of the kernel/sysctl.c cleaning, also moves some external
variable declarations and function declarations from include/linux/swap.h
into mm/internal.h.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vmscan_sysctl_table
v3:
 - change the title
---
---
 include/linux/swap.h |  9 ---------
 kernel/sysctl.c      | 19 -------------------
 mm/internal.h        | 10 ++++++++++
 mm/vmscan.c          | 23 +++++++++++++++++++++++
 4 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/include/linux/swap.h b/include/linux/swap.h
index 187715eec3cb..db1a28683e10 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -427,19 +427,10 @@ extern int vm_swappiness;
 long remove_mapping(struct address_space *mapping, struct folio *folio);
 
 #ifdef CONFIG_NUMA
-extern int node_reclaim_mode;
 extern int sysctl_min_unmapped_ratio;
 extern int sysctl_min_slab_ratio;
-#else
-#define node_reclaim_mode 0
 #endif
 
-static inline bool node_reclaim_enabled(void)
-{
-	/* Is any node_reclaim_mode bit set? */
-	return node_reclaim_mode & (RECLAIM_ZONE|RECLAIM_WRITE|RECLAIM_UNMAP);
-}
-
 void check_move_unevictable_folios(struct folio_batch *fbatch);
 
 extern void __meminit kswapd_run(int nid);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index ab5d94f07e53..cb6ca272fe9f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2051,15 +2051,6 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= dirtytime_interval_handler,
 		.extra1		= SYSCTL_ZERO,
 	},
-	{
-		.procname	= "swappiness",
-		.data		= &vm_swappiness,
-		.maxlen		= sizeof(vm_swappiness),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_TWO_HUNDRED,
-	},
 	{
 		.procname	= "drop_caches",
 		.data		= &sysctl_drop_caches,
@@ -2107,16 +2098,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif
-#ifdef CONFIG_NUMA
-	{
-		.procname	= "zone_reclaim_mode",
-		.data		= &node_reclaim_mode,
-		.maxlen		= sizeof(node_reclaim_mode),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
 #ifdef CONFIG_MMU
 	{
 		.procname	= "mmap_min_addr",
diff --git a/mm/internal.h b/mm/internal.h
index 39227887e47b..ea2623dc414a 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1095,9 +1095,13 @@ static inline void mminit_verify_zonelist(void)
 #define NODE_RECLAIM_SUCCESS	1
 
 #ifdef CONFIG_NUMA
+extern int node_reclaim_mode;
+
 extern int node_reclaim(struct pglist_data *, gfp_t, unsigned int);
 extern int find_next_best_node(int node, nodemask_t *used_node_mask);
 #else
+#define node_reclaim_mode 0
+
 static inline int node_reclaim(struct pglist_data *pgdat, gfp_t mask,
 				unsigned int order)
 {
@@ -1109,6 +1113,12 @@ static inline int find_next_best_node(int node, nodemask_t *used_node_mask)
 }
 #endif
 
+static inline bool node_reclaim_enabled(void)
+{
+	/* Is any node_reclaim_mode bit set? */
+	return node_reclaim_mode & (RECLAIM_ZONE|RECLAIM_WRITE|RECLAIM_UNMAP);
+}
+
 /*
  * mm/memory-failure.c
  */
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 39886f435ec5..10cc05b5952d 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -7351,6 +7351,28 @@ void __meminit kswapd_stop(int nid)
 	pgdat_kswapd_unlock(pgdat);
 }
 
+static const struct ctl_table vmscan_sysctl_table[] = {
+	{
+		.procname	= "swappiness",
+		.data		= &vm_swappiness,
+		.maxlen		= sizeof(vm_swappiness),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_TWO_HUNDRED,
+	},
+#ifdef CONFIG_NUMA
+	{
+		.procname	= "zone_reclaim_mode",
+		.data		= &node_reclaim_mode,
+		.maxlen		= sizeof(node_reclaim_mode),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+	}
+#endif
+};
+
 static int __init kswapd_init(void)
 {
 	int nid;
@@ -7358,6 +7380,7 @@ static int __init kswapd_init(void)
 	swap_setup();
 	for_each_node_state(nid, N_MEMORY)
  		kswapd_run(nid);
+	register_sysctl_init("vm", vmscan_sysctl_table);
 	return 0;
 }
 
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 05/15] mm: util: move sysctls to mm/util.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (3 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 04/15] mm: vmscan: move vmscan sysctls to mm/vmscan.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Kaixiong Yu
                   ` (26 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves all util related sysctls to mm/util.c, as part of the
kernel/sysctl.c cleaning, also removes redundant external
variable declarations and function declarations.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table util_sysctl_table
v3:
 - change the title
---
---
 include/linux/mm.h   | 11 --------
 include/linux/mman.h |  2 --
 kernel/sysctl.c      | 37 ------------------------
 mm/util.c            | 67 ++++++++++++++++++++++++++++++++++++++------
 4 files changed, 59 insertions(+), 58 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8941ba3d9a77..b3b87c1dc1e4 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -205,17 +205,6 @@ extern int sysctl_max_map_count;
 extern unsigned long sysctl_user_reserve_kbytes;
 extern unsigned long sysctl_admin_reserve_kbytes;
 
-extern int sysctl_overcommit_memory;
-extern int sysctl_overcommit_ratio;
-extern unsigned long sysctl_overcommit_kbytes;
-
-int overcommit_ratio_handler(const struct ctl_table *, int, void *, size_t *,
-		loff_t *);
-int overcommit_kbytes_handler(const struct ctl_table *, int, void *, size_t *,
-		loff_t *);
-int overcommit_policy_handler(const struct ctl_table *, int, void *, size_t *,
-		loff_t *);
-
 #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
 #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
 #define folio_page_idx(folio, p)	(page_to_pfn(p) - folio_pfn(folio))
diff --git a/include/linux/mman.h b/include/linux/mman.h
index a842783ffa62..bce214fece16 100644
--- a/include/linux/mman.h
+++ b/include/linux/mman.h
@@ -59,8 +59,6 @@
 		| MAP_HUGE_1GB)
 
 extern int sysctl_overcommit_memory;
-extern int sysctl_overcommit_ratio;
-extern unsigned long sysctl_overcommit_kbytes;
 extern struct percpu_counter vm_committed_as;
 
 #ifdef CONFIG_SMP
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index cb6ca272fe9f..aea3482106e0 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2020,29 +2020,6 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-	{
-		.procname	= "overcommit_memory",
-		.data		= &sysctl_overcommit_memory,
-		.maxlen		= sizeof(sysctl_overcommit_memory),
-		.mode		= 0644,
-		.proc_handler	= overcommit_policy_handler,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_TWO,
-	},
-	{
-		.procname	= "overcommit_ratio",
-		.data		= &sysctl_overcommit_ratio,
-		.maxlen		= sizeof(sysctl_overcommit_ratio),
-		.mode		= 0644,
-		.proc_handler	= overcommit_ratio_handler,
-	},
-	{
-		.procname	= "overcommit_kbytes",
-		.data		= &sysctl_overcommit_kbytes,
-		.maxlen		= sizeof(sysctl_overcommit_kbytes),
-		.mode		= 0644,
-		.proc_handler	= overcommit_kbytes_handler,
-	},
 	{
 		.procname	= "dirtytime_expire_seconds",
 		.data		= &dirtytime_expire_interval,
@@ -2123,20 +2100,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif
-	{
-		.procname	= "user_reserve_kbytes",
-		.data		= &sysctl_user_reserve_kbytes,
-		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
-		.mode		= 0644,
-		.proc_handler	= proc_doulongvec_minmax,
-	},
-	{
-		.procname	= "admin_reserve_kbytes",
-		.data		= &sysctl_admin_reserve_kbytes,
-		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
-		.mode		= 0644,
-		.proc_handler	= proc_doulongvec_minmax,
-	},
 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
 	{
 		.procname	= "mmap_rnd_bits",
diff --git a/mm/util.c b/mm/util.c
index b7dc6fabaae5..6c64664937b3 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -12,6 +12,7 @@
 #include <linux/security.h>
 #include <linux/swap.h>
 #include <linux/swapops.h>
+#include <linux/sysctl.h>
 #include <linux/mman.h>
 #include <linux/hugetlb.h>
 #include <linux/vmalloc.h>
@@ -911,14 +912,16 @@ int folio_mc_copy(struct folio *dst, struct folio *src)
 EXPORT_SYMBOL(folio_mc_copy);
 
 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS;
-int sysctl_overcommit_ratio __read_mostly = 50;
-unsigned long sysctl_overcommit_kbytes __read_mostly;
+static int sysctl_overcommit_ratio __read_mostly = 50;
+static unsigned long sysctl_overcommit_kbytes __read_mostly;
 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
 
-int overcommit_ratio_handler(const struct ctl_table *table, int write, void *buffer,
-		size_t *lenp, loff_t *ppos)
+#ifdef CONFIG_SYSCTL
+
+static int overcommit_ratio_handler(const struct ctl_table *table, int write,
+				void *buffer, size_t *lenp, loff_t *ppos)
 {
 	int ret;
 
@@ -933,8 +936,8 @@ static void sync_overcommit_as(struct work_struct *dummy)
 	percpu_counter_sync(&vm_committed_as);
 }
 
-int overcommit_policy_handler(const struct ctl_table *table, int write, void *buffer,
-		size_t *lenp, loff_t *ppos)
+static int overcommit_policy_handler(const struct ctl_table *table, int write,
+				void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct ctl_table t;
 	int new_policy = -1;
@@ -969,8 +972,8 @@ int overcommit_policy_handler(const struct ctl_table *table, int write, void *bu
 	return ret;
 }
 
-int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *buffer,
-		size_t *lenp, loff_t *ppos)
+static int overcommit_kbytes_handler(const struct ctl_table *table, int write,
+				void *buffer, size_t *lenp, loff_t *ppos)
 {
 	int ret;
 
@@ -980,6 +983,54 @@ int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *bu
 	return ret;
 }
 
+static const struct ctl_table util_sysctl_table[] = {
+	{
+		.procname	= "overcommit_memory",
+		.data		= &sysctl_overcommit_memory,
+		.maxlen		= sizeof(sysctl_overcommit_memory),
+		.mode		= 0644,
+		.proc_handler	= overcommit_policy_handler,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_TWO,
+	},
+	{
+		.procname	= "overcommit_ratio",
+		.data		= &sysctl_overcommit_ratio,
+		.maxlen		= sizeof(sysctl_overcommit_ratio),
+		.mode		= 0644,
+		.proc_handler	= overcommit_ratio_handler,
+	},
+	{
+		.procname	= "overcommit_kbytes",
+		.data		= &sysctl_overcommit_kbytes,
+		.maxlen		= sizeof(sysctl_overcommit_kbytes),
+		.mode		= 0644,
+		.proc_handler	= overcommit_kbytes_handler,
+	},
+	{
+		.procname	= "user_reserve_kbytes",
+		.data		= &sysctl_user_reserve_kbytes,
+		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
+		.mode		= 0644,
+		.proc_handler	= proc_doulongvec_minmax,
+	},
+	{
+		.procname	= "admin_reserve_kbytes",
+		.data		= &sysctl_admin_reserve_kbytes,
+		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
+		.mode		= 0644,
+		.proc_handler	= proc_doulongvec_minmax,
+	},
+};
+
+static int __init init_vm_util_sysctls(void)
+{
+	register_sysctl_init("vm", util_sysctl_table);
+	return 0;
+}
+subsys_initcall(init_vm_util_sysctls);
+#endif /* CONFIG_SYSCTL */
+
 /*
  * Committed memory limit enforced when OVERCOMMIT_NEVER policy is used
  */
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (4 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 05/15] mm: util: move sysctls to mm/util.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2025-01-02 14:08   ` Lorenzo Stoakes
  2024-12-23 14:15 ` [PATCH v4 -next 07/15] security: min_addr: move sysctl to security/min_addr.c Kaixiong Yu
                   ` (25 subsequent siblings)
  31 siblings, 1 reply; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves all mmap related sysctls to mm/mmap.c, as part of the
kernel/sysctl.c cleaning, also move the variable declaration from
kernel/sysctl.c into mm/mmap.c.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table mmap_table
v3:
 - change the title
v2:
 - fix sysctl_max_map_count undeclared issue in mm/nommu.c
---
---
 kernel/sysctl.c | 50 +--------------------------------------------
 mm/mmap.c       | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 49 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index aea3482106e0..9c245898f535 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -127,12 +127,6 @@ enum sysctl_writes_mode {
 
 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
 #endif /* CONFIG_PROC_SYSCTL */
-
-#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
-    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
-int sysctl_legacy_va_layout;
-#endif
-
 #endif /* CONFIG_SYSCTL */
 
 /*
@@ -2037,16 +2031,7 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_FOUR,
 	},
-#ifdef CONFIG_MMU
-	{
-		.procname	= "max_map_count",
-		.data		= &sysctl_max_map_count,
-		.maxlen		= sizeof(sysctl_max_map_count),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#else
+#ifndef CONFIG_MMU
 	{
 		.procname	= "nr_trim_pages",
 		.data		= &sysctl_nr_trim_pages,
@@ -2064,17 +2049,6 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= SYSCTL_ZERO,
 	},
-#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
-    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
-	{
-		.procname	= "legacy_va_layout",
-		.data		= &sysctl_legacy_va_layout,
-		.maxlen		= sizeof(sysctl_legacy_va_layout),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
 #ifdef CONFIG_MMU
 	{
 		.procname	= "mmap_min_addr",
@@ -2100,28 +2074,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif
-#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
-	{
-		.procname	= "mmap_rnd_bits",
-		.data		= &mmap_rnd_bits,
-		.maxlen		= sizeof(mmap_rnd_bits),
-		.mode		= 0600,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= (void *)&mmap_rnd_bits_min,
-		.extra2		= (void *)&mmap_rnd_bits_max,
-	},
-#endif
-#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
-	{
-		.procname	= "mmap_rnd_compat_bits",
-		.data		= &mmap_rnd_compat_bits,
-		.maxlen		= sizeof(mmap_rnd_compat_bits),
-		.mode		= 0600,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= (void *)&mmap_rnd_compat_bits_min,
-		.extra2		= (void *)&mmap_rnd_compat_bits_max,
-	},
-#endif
 };
 
 int __init sysctl_init_bases(void)
diff --git a/mm/mmap.c b/mm/mmap.c
index aef835984b1c..cc579aafd7ba 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1603,6 +1603,57 @@ struct vm_area_struct *_install_special_mapping(
 					&special_mapping_vmops);
 }
 
+#ifdef CONFIG_SYSCTL
+#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
+		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
+int sysctl_legacy_va_layout;
+#endif
+
+static const struct ctl_table mmap_table[] = {
+		{
+				.procname       = "max_map_count",
+				.data           = &sysctl_max_map_count,
+				.maxlen         = sizeof(sysctl_max_map_count),
+				.mode           = 0644,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = SYSCTL_ZERO,
+		},
+#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
+		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
+		{
+				.procname       = "legacy_va_layout",
+				.data           = &sysctl_legacy_va_layout,
+				.maxlen         = sizeof(sysctl_legacy_va_layout),
+				.mode           = 0644,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = SYSCTL_ZERO,
+		},
+#endif
+#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
+		{
+				.procname       = "mmap_rnd_bits",
+				.data           = &mmap_rnd_bits,
+				.maxlen         = sizeof(mmap_rnd_bits),
+				.mode           = 0600,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = (void *)&mmap_rnd_bits_min,
+				.extra2         = (void *)&mmap_rnd_bits_max,
+		},
+#endif
+#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
+		{
+				.procname       = "mmap_rnd_compat_bits",
+				.data           = &mmap_rnd_compat_bits,
+				.maxlen         = sizeof(mmap_rnd_compat_bits),
+				.mode           = 0600,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = (void *)&mmap_rnd_compat_bits_min,
+				.extra2         = (void *)&mmap_rnd_compat_bits_max,
+		},
+#endif
+};
+#endif /* CONFIG_SYSCTL */
+
 /*
  * initialise the percpu counter for VM
  */
@@ -1612,6 +1663,9 @@ void __init mmap_init(void)
 
 	ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
 	VM_BUG_ON(ret);
+#ifdef CONFIG_SYSCTL
+	register_sysctl_init("vm", mmap_table);
+#endif
 }
 
 /*
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 07/15] security: min_addr: move sysctl to security/min_addr.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (5 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c Kaixiong Yu
                   ` (24 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The dac_mmap_min_addr belongs to min_addr.c, move it to
min_addr.c from /kernel/sysctl.c. In the previous Linux kernel
boot process, sysctl_init_bases needs to be executed before
init_mmap_min_addr, So, register_sysctl_init should be executed
before update_mmap_min_addr in init_mmap_min_addr. And according
to the compilation condition in security/Makefile:

      obj-$(CONFIG_MMU)            += min_addr.o

if CONFIG_MMU is not defined, min_addr.c would not be included in the
compilation process. So, drop the CONFIG_MMU check.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Acked-by: Paul Moore <paul@paul-moore.com>
---
v4:
 - const qualify struct ctl_table min_addr_sysctl_table
v3:
 - change the title
v2:
 - update the changelog to explain why drop CONFIG_MMU check.
---
---
 kernel/sysctl.c     |  9 ---------
 security/min_addr.c | 11 +++++++++++
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 9c245898f535..62a58e417c40 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2049,15 +2049,6 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= SYSCTL_ZERO,
 	},
-#ifdef CONFIG_MMU
-	{
-		.procname	= "mmap_min_addr",
-		.data		= &dac_mmap_min_addr,
-		.maxlen		= sizeof(unsigned long),
-		.mode		= 0644,
-		.proc_handler	= mmap_min_addr_handler,
-	},
-#endif
 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
 	{
diff --git a/security/min_addr.c b/security/min_addr.c
index 0ce267c041ab..df1bc643d886 100644
--- a/security/min_addr.c
+++ b/security/min_addr.c
@@ -44,8 +44,19 @@ int mmap_min_addr_handler(const struct ctl_table *table, int write,
 	return ret;
 }
 
+static const struct ctl_table min_addr_sysctl_table[] = {
+	{
+		.procname	= "mmap_min_addr",
+		.data		= &dac_mmap_min_addr,
+		.maxlen		= sizeof(unsigned long),
+		.mode		= 0644,
+		.proc_handler	= mmap_min_addr_handler,
+	},
+};
+
 static int __init init_mmap_min_addr(void)
 {
+	register_sysctl_init("vm", min_addr_sysctl_table);
 	update_mmap_min_addr();
 
 	return 0;
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (6 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 07/15] security: min_addr: move sysctl to security/min_addr.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2025-01-02 14:09   ` Lorenzo Stoakes
  2024-12-23 14:15 ` [PATCH v4 -next 09/15] fs: fs-writeback: move sysctl to fs/fs-writeback.c Kaixiong Yu
                   ` (23 subsequent siblings)
  31 siblings, 1 reply; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The sysctl_nr_trim_pages belongs to nommu.c, move it to mm/nommu.c
from /kernel/sysctl.c. And remove the useless extern variable declaration
from include/linux/mm.h

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
---
v4:
 - const qualify struct ctl_table nommu_table
v3:
 - change the title
v2:
 - fix the build error: expected ';' after top level declarator
 - fix the build error: call to undeclared function 'register_syscall_init',
   use 'register_sysctl_init' to replace it.
---
---
 include/linux/mm.h |  2 --
 kernel/sysctl.c    | 10 ----------
 mm/nommu.c         | 15 ++++++++++++++-
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index b3b87c1dc1e4..9813b5b9c093 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -4080,8 +4080,6 @@ unsigned long wp_shared_mapping_range(struct address_space *mapping,
 				      pgoff_t first_index, pgoff_t nr);
 #endif
 
-extern int sysctl_nr_trim_pages;
-
 #ifdef CONFIG_PRINTK
 void mem_dump_obj(void *object);
 #else
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 62a58e417c40..97f9abffff0f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2031,16 +2031,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_FOUR,
 	},
-#ifndef CONFIG_MMU
-	{
-		.procname	= "nr_trim_pages",
-		.data		= &sysctl_nr_trim_pages,
-		.maxlen		= sizeof(sysctl_nr_trim_pages),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
 	{
 		.procname	= "vfs_cache_pressure",
 		.data		= &sysctl_vfs_cache_pressure,
diff --git a/mm/nommu.c b/mm/nommu.c
index baa79abdaf03..3c32f8b1eb54 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -48,7 +48,6 @@ struct page *mem_map;
 unsigned long max_mapnr;
 EXPORT_SYMBOL(max_mapnr);
 unsigned long highest_memmap_pfn;
-int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
 int heap_stack_gap = 0;
 
 atomic_long_t mmap_pages_allocated;
@@ -392,6 +391,19 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
 	return mm->brk = brk;
 }
 
+static int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
+
+static const struct ctl_table nommu_table[] = {
+	{
+		.procname	= "nr_trim_pages",
+		.data		= &sysctl_nr_trim_pages,
+		.maxlen		= sizeof(sysctl_nr_trim_pages),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+	},
+};
+
 /*
  * initialise the percpu counter for VM and region record slabs
  */
@@ -402,6 +414,7 @@ void __init mmap_init(void)
 	ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
 	VM_BUG_ON(ret);
 	vm_region_jar = KMEM_CACHE(vm_region, SLAB_PANIC|SLAB_ACCOUNT);
+	register_sysctl_init("vm", nommu_table);
 }
 
 /*
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 09/15] fs: fs-writeback: move sysctl to fs/fs-writeback.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (7 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 10/15] fs: drop_caches: move sysctl to fs/drop_caches.c Kaixiong Yu
                   ` (22 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The dirtytime_expire_interval belongs to fs/fs-writeback.c, move it to
fs/fs-writeback.c from /kernel/sysctl.c. And remove the useless extern
variable declaration and the function declaration from
include/linux/writeback.h

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
---
v4:
 - const qualify struct ctl_table vm_fs_writeback_table
v3:
 - change dirtytime_expire_interval to static type
 - change the title
---
---
 fs/fs-writeback.c         | 30 +++++++++++++++++++++---------
 include/linux/writeback.h |  4 ----
 kernel/sysctl.c           |  8 --------
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 5980ac24c7a4..4f907e8dbfff 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -65,7 +65,7 @@ struct wb_writeback_work {
  * timestamps written to disk after 12 hours, but in the worst case a
  * few inodes might not their timestamps updated for 24 hours.
  */
-unsigned int dirtytime_expire_interval = 12 * 60 * 60;
+static unsigned int dirtytime_expire_interval = 12 * 60 * 60;
 
 static inline struct inode *wb_inode(struct list_head *head)
 {
@@ -2435,14 +2435,7 @@ static void wakeup_dirtytime_writeback(struct work_struct *w)
 	schedule_delayed_work(&dirtytime_work, dirtytime_expire_interval * HZ);
 }
 
-static int __init start_dirtytime_writeback(void)
-{
-	schedule_delayed_work(&dirtytime_work, dirtytime_expire_interval * HZ);
-	return 0;
-}
-__initcall(start_dirtytime_writeback);
-
-int dirtytime_interval_handler(const struct ctl_table *table, int write,
+static int dirtytime_interval_handler(const struct ctl_table *table, int write,
 			       void *buffer, size_t *lenp, loff_t *ppos)
 {
 	int ret;
@@ -2453,6 +2446,25 @@ int dirtytime_interval_handler(const struct ctl_table *table, int write,
 	return ret;
 }
 
+static const struct ctl_table vm_fs_writeback_table[] = {
+	{
+		.procname	= "dirtytime_expire_seconds",
+		.data		= &dirtytime_expire_interval,
+		.maxlen		= sizeof(dirtytime_expire_interval),
+		.mode		= 0644,
+		.proc_handler	= dirtytime_interval_handler,
+		.extra1		= SYSCTL_ZERO,
+	},
+};
+
+static int __init start_dirtytime_writeback(void)
+{
+	schedule_delayed_work(&dirtytime_work, dirtytime_expire_interval * HZ);
+	register_sysctl_init("vm", vm_fs_writeback_table);
+	return 0;
+}
+__initcall(start_dirtytime_writeback);
+
 /**
  * __mark_inode_dirty -	internal function to mark an inode dirty
  *
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index d11b903c2edb..caf4f0b12235 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -327,12 +327,8 @@ extern struct wb_domain global_wb_domain;
 /* These are exported to sysctl. */
 extern unsigned int dirty_writeback_interval;
 extern unsigned int dirty_expire_interval;
-extern unsigned int dirtytime_expire_interval;
 extern int laptop_mode;
 
-int dirtytime_interval_handler(const struct ctl_table *table, int write,
-		void *buffer, size_t *lenp, loff_t *ppos);
-
 void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
 unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh);
 unsigned long cgwb_calc_thresh(struct bdi_writeback *wb);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 97f9abffff0f..c5527f59e3f2 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2014,14 +2014,6 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-	{
-		.procname	= "dirtytime_expire_seconds",
-		.data		= &dirtytime_expire_interval,
-		.maxlen		= sizeof(dirtytime_expire_interval),
-		.mode		= 0644,
-		.proc_handler	= dirtytime_interval_handler,
-		.extra1		= SYSCTL_ZERO,
-	},
 	{
 		.procname	= "drop_caches",
 		.data		= &sysctl_drop_caches,
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 10/15] fs: drop_caches: move sysctl to fs/drop_caches.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (8 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 09/15] fs: fs-writeback: move sysctl to fs/fs-writeback.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 11/15] sunrpc: simplify rpcauth_cache_shrink_count() Kaixiong Yu
                   ` (21 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The sysctl_drop_caches to fs/drop_caches.c, move it to
fs/drop_caches.c from /kernel/sysctl.c. And remove the
useless extern variable declaration from include/linux/mm.h

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christian Brauner <brauner@kernel.org>
---
v4:
 - const qualify struct ctl_table drop_caches_table
v3:
 - change the title
---
---
 fs/drop_caches.c   | 23 +++++++++++++++++++++--
 include/linux/mm.h |  6 ------
 kernel/sysctl.c    |  9 ---------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index d45ef541d848..019a8b4eaaf9 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -14,7 +14,7 @@
 #include "internal.h"
 
 /* A global variable is a bit ugly, but it keeps the code simple */
-int sysctl_drop_caches;
+static int sysctl_drop_caches;
 
 static void drop_pagecache_sb(struct super_block *sb, void *unused)
 {
@@ -48,7 +48,7 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
 	iput(toput_inode);
 }
 
-int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
+static int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
 		void *buffer, size_t *length, loff_t *ppos)
 {
 	int ret;
@@ -77,3 +77,22 @@ int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
 	}
 	return 0;
 }
+
+static const struct ctl_table drop_caches_table[] = {
+	{
+		.procname	= "drop_caches",
+		.data		= &sysctl_drop_caches,
+		.maxlen		= sizeof(int),
+		.mode		= 0200,
+		.proc_handler	= drop_caches_sysctl_handler,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= SYSCTL_FOUR,
+	},
+};
+
+static int __init init_vm_drop_caches_sysctls(void)
+{
+	register_sysctl_init("vm", drop_caches_table);
+	return 0;
+}
+fs_initcall(init_vm_drop_caches_sysctls);
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 9813b5b9c093..387f579a6c18 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3803,12 +3803,6 @@ static inline int in_gate_area(struct mm_struct *mm, unsigned long addr)
 
 extern bool process_shares_mm(struct task_struct *p, struct mm_struct *mm);
 
-#ifdef CONFIG_SYSCTL
-extern int sysctl_drop_caches;
-int drop_caches_sysctl_handler(const struct ctl_table *, int, void *, size_t *,
-		loff_t *);
-#endif
-
 void drop_slab(void);
 
 #ifndef CONFIG_MMU
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index c5527f59e3f2..7fb77cbcc24d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2014,15 +2014,6 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-	{
-		.procname	= "drop_caches",
-		.data		= &sysctl_drop_caches,
-		.maxlen		= sizeof(int),
-		.mode		= 0200,
-		.proc_handler	= drop_caches_sysctl_handler,
-		.extra1		= SYSCTL_ONE,
-		.extra2		= SYSCTL_FOUR,
-	},
 	{
 		.procname	= "vfs_cache_pressure",
 		.data		= &sysctl_vfs_cache_pressure,
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 11/15] sunrpc: simplify rpcauth_cache_shrink_count()
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (9 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 10/15] fs: drop_caches: move sysctl to fs/drop_caches.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 12/15] fs: dcache: move the sysctl to fs/dcache.c Kaixiong Yu
                   ` (20 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

It is inappropriate to use sysctl_vfs_cache_pressure here.
The sysctl is documented as: This percentage value controls
the tendency of the kernel to reclaim the memory which is used
for caching of directory and inode objects.

So, simplify result of rpcauth_cache_shrink_count() to
"return number_cred_unused;".

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Acked-by: Anna Schumaker <anna.schumaker@oracle.com>
Acked-by: Jeff Layton <jlayton@kernel.org>
---
v4:
 - Simplify result of rpcauth_cache_shrink_count().
---
---
 net/sunrpc/auth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index 04534ea537c8..5a827afd8e3b 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -489,7 +489,7 @@ static unsigned long
 rpcauth_cache_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
 
 {
-	return number_cred_unused * sysctl_vfs_cache_pressure / 100;
+	return number_cred_unused;
 }
 
 static void
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 12/15] fs: dcache: move the sysctl to fs/dcache.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (10 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 11/15] sunrpc: simplify rpcauth_cache_shrink_count() Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 13/15] x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c Kaixiong Yu
                   ` (19 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The sysctl_vfs_cache_pressure belongs to fs/dcache.c, move it to
fs/dcache.c from kernel/sysctl.c. As a part of fs/dcache.c cleaning,
sysctl_vfs_cache_pressure is changed to a static variable, and change
the inline-type function vfs_pressure_ratio() to out-of-inline type,
export vfs_pressure_ratio() with EXPORT_SYMBOL_GPL to be used by other
files. Move the unneeded include(linux/dcache.h).

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christian Brauner <brauner@kernel.org>
---
v4:
 - const qualify struct ctl_table vm_dcache_sysctls
v3:
 - change the title
v2:
 - update the changelog to call out changing the inline-type function
   vfs_pressure_ratio() to out-of-inline type
---
---
 fs/dcache.c            | 21 +++++++++++++++++++--
 include/linux/dcache.h |  7 +------
 kernel/sysctl.c        |  9 ---------
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index b4d5e9e1e43d..77ca6e9bb71e 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -73,8 +73,13 @@
  * If no ancestor relationship:
  * arbitrary, since it's serialized on rename_lock
  */
-int sysctl_vfs_cache_pressure __read_mostly = 100;
-EXPORT_SYMBOL_GPL(sysctl_vfs_cache_pressure);
+static int sysctl_vfs_cache_pressure __read_mostly = 100;
+
+unsigned long vfs_pressure_ratio(unsigned long val)
+{
+	return mult_frac(val, sysctl_vfs_cache_pressure, 100);
+}
+EXPORT_SYMBOL_GPL(vfs_pressure_ratio);
 
 __cacheline_aligned_in_smp DEFINE_SEQLOCK(rename_lock);
 
@@ -211,8 +216,20 @@ static struct ctl_table fs_dcache_sysctls[] = {
 	},
 };
 
+static const struct ctl_table vm_dcache_sysctls[] = {
+	{
+		.procname	= "vfs_cache_pressure",
+		.data		= &sysctl_vfs_cache_pressure,
+		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+	},
+};
+
 static int __init init_fs_dcache_sysctls(void)
 {
+	register_sysctl_init("vm", vm_dcache_sysctls);
 	register_sysctl_init("fs", fs_dcache_sysctls);
 	return 0;
 }
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index bff956f7b2b9..c81c2e9e13df 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -508,12 +508,7 @@ static inline int simple_positive(const struct dentry *dentry)
 	return d_really_is_positive(dentry) && !d_unhashed(dentry);
 }
 
-extern int sysctl_vfs_cache_pressure;
-
-static inline unsigned long vfs_pressure_ratio(unsigned long val)
-{
-	return mult_frac(val, sysctl_vfs_cache_pressure, 100);
-}
+unsigned long vfs_pressure_ratio(unsigned long val);
 
 /**
  * d_inode - Get the actual inode of this dentry
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7fb77cbcc24d..860dea8f1587 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -46,7 +46,6 @@
 #include <linux/key.h>
 #include <linux/times.h>
 #include <linux/limits.h>
-#include <linux/dcache.h>
 #include <linux/syscalls.h>
 #include <linux/nfs_fs.h>
 #include <linux/acpi.h>
@@ -2014,14 +2013,6 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-	{
-		.procname	= "vfs_cache_pressure",
-		.data		= &sysctl_vfs_cache_pressure,
-		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
 	{
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 13/15] x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (11 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 12/15] fs: dcache: move the sysctl to fs/dcache.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 14/15] sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c Kaixiong Yu
                   ` (18 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

When CONFIG_X86_32 is defined and CONFIG_UML is not defined,
vdso_enabled belongs to arch/x86/entry/vdso/vdso32-setup.c.
So, move it into its own file.

Before this patch, vdso_enabled was allowed to be set to
a value exceeding 1 on x86_32 architecture. After this patch is
applied, vdso_enabled is not permitted to set the value more than 1.
It does not matter, because according to the function load_vdso32(),
only vdso_enabled is set to 1, VDSO would be enabled. Other values
all mean "disabled". The same limitation could be seen in the
function vdso32_setup().

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vdso_table
---
---
 arch/x86/entry/vdso/vdso32-setup.c | 16 +++++++++++-----
 kernel/sysctl.c                    |  8 +-------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/x86/entry/vdso/vdso32-setup.c b/arch/x86/entry/vdso/vdso32-setup.c
index 76e4e74f35b5..f71625f99bf9 100644
--- a/arch/x86/entry/vdso/vdso32-setup.c
+++ b/arch/x86/entry/vdso/vdso32-setup.c
@@ -51,15 +51,17 @@ __setup("vdso32=", vdso32_setup);
 __setup_param("vdso=", vdso_setup, vdso32_setup, 0);
 #endif
 
-#ifdef CONFIG_X86_64
 
 #ifdef CONFIG_SYSCTL
-/* Register vsyscall32 into the ABI table */
 #include <linux/sysctl.h>
 
-static struct ctl_table abi_table2[] = {
+static const struct ctl_table vdso_table[] = {
 	{
+#ifdef CONFIG_X86_64
 		.procname	= "vsyscall32",
+#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
+		.procname	= "vdso_enabled",
+#endif
 		.data		= &vdso32_enabled,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
@@ -71,10 +73,14 @@ static struct ctl_table abi_table2[] = {
 
 static __init int ia32_binfmt_init(void)
 {
-	register_sysctl("abi", abi_table2);
+#ifdef CONFIG_X86_64
+	/* Register vsyscall32 into the ABI table */
+	register_sysctl("abi", vdso_table);
+#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
+	register_sysctl_init("vm", vdso_table);
+#endif
 	return 0;
 }
 __initcall(ia32_binfmt_init);
 #endif /* CONFIG_SYSCTL */
 
-#endif	/* CONFIG_X86_64 */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 860dea8f1587..7ff07b7560b4 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2013,17 +2013,11 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
-   (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
+#if defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)
 	{
 		.procname	= "vdso_enabled",
-#ifdef CONFIG_X86_32
-		.data		= &vdso32_enabled,
-		.maxlen		= sizeof(vdso32_enabled),
-#else
 		.data		= &vdso_enabled,
 		.maxlen		= sizeof(vdso_enabled),
-#endif
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 		.extra1		= SYSCTL_ZERO,
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 14/15] sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (12 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 13/15] x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 15/15] sysctl: remove unneeded include Kaixiong Yu
                   ` (17 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

When CONFIG_SUPERH and CONFIG_VSYSCALL are defined,
vdso_enabled belongs to arch/sh/kernel/vsyscall/vsyscall.c.
So, move it into its own file. After this patch is applied,
all sysctls of vm_table would be moved. So, delete vm_table.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vdso_table
v3:
 - change the title
---
---
 arch/sh/kernel/vsyscall/vsyscall.c | 14 ++++++++++++++
 kernel/sysctl.c                    | 14 --------------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
index add35c51e017..898132f34e6a 100644
--- a/arch/sh/kernel/vsyscall/vsyscall.c
+++ b/arch/sh/kernel/vsyscall/vsyscall.c
@@ -14,6 +14,7 @@
 #include <linux/module.h>
 #include <linux/elf.h>
 #include <linux/sched.h>
+#include <linux/sysctl.h>
 #include <linux/err.h>
 
 /*
@@ -30,6 +31,17 @@ static int __init vdso_setup(char *s)
 }
 __setup("vdso=", vdso_setup);
 
+static const struct ctl_table vdso_table[] = {
+	{
+		.procname	= "vdso_enabled",
+		.data		= &vdso_enabled,
+		.maxlen		= sizeof(vdso_enabled),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+		.extra1		= SYSCTL_ZERO,
+	},
+};
+
 /*
  * These symbols are defined by vsyscall.o to mark the bounds
  * of the ELF DSO images included therein.
@@ -55,6 +67,8 @@ int __init vsyscall_init(void)
 	       &vsyscall_trapa_start,
 	       &vsyscall_trapa_end - &vsyscall_trapa_start);
 
+	register_sysctl_init("vm", vdso_table);
+
 	return 0;
 }
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7ff07b7560b4..cebd0ef5d19d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2012,23 +2012,9 @@ static struct ctl_table kern_table[] = {
 #endif
 };
 
-static struct ctl_table vm_table[] = {
-#if defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)
-	{
-		.procname	= "vdso_enabled",
-		.data		= &vdso_enabled,
-		.maxlen		= sizeof(vdso_enabled),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
-};
-
 int __init sysctl_init_bases(void)
 {
 	register_sysctl_init("kernel", kern_table);
-	register_sysctl_init("vm", vm_table);
 
 	return 0;
 }
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 15/15] sysctl: remove unneeded include
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (13 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 14/15] sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (16 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

Removing unneeded mm includes in kernel/sysctl.c.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
 kernel/sysctl.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index cebd0ef5d19d..aece984bee19 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -20,8 +20,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
 #include <linux/sysctl.h>
 #include <linux/bitmap.h>
 #include <linux/signal.h>
@@ -30,7 +28,6 @@
 #include <linux/proc_fs.h>
 #include <linux/security.h>
 #include <linux/ctype.h>
-#include <linux/kmemleak.h>
 #include <linux/filter.h>
 #include <linux/fs.h>
 #include <linux/init.h>
@@ -41,7 +38,6 @@
 #include <linux/highuid.h>
 #include <linux/writeback.h>
 #include <linux/ratelimit.h>
-#include <linux/hugetlb.h>
 #include <linux/initrd.h>
 #include <linux/key.h>
 #include <linux/times.h>
@@ -52,13 +48,11 @@
 #include <linux/reboot.h>
 #include <linux/ftrace.h>
 #include <linux/perf_event.h>
-#include <linux/oom.h>
 #include <linux/kmod.h>
 #include <linux/capability.h>
 #include <linux/binfmts.h>
 #include <linux/sched/sysctl.h>
 #include <linux/mount.h>
-#include <linux/userfaultfd_k.h>
 #include <linux/pid.h>
 
 #include "../lib/kstrtox.h"
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (14 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 15/15] sysctl: remove unneeded include Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 01/15] mm: vmstat: move sysctls to mm/vmstat.c Kaixiong Yu
                   ` (15 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This patch series moves sysctls of vm_table in kernel/sysctl.c to
places where they actually belong, and do some related code clean-ups.
After this patch series, all sysctls in vm_table have been moved into its
own files, meanwhile, delete vm_table.

All the modifications of this patch series base on
linux-next(tags/next-20241219). To test this patch series, the code was
compiled with both the CONFIG_SYSCTL enabled and disabled on arm64 and
x86_64 architectures. After this patch series is applied, all files
under /proc/sys/vm can be read or written normally.

Changes in v4:
 - change all "static struct ctl_table" type into
   "static const struct ctl_table" type in patch1~10,12,13,14
 - simplify result of rpcauth_cache_shrink_count() in patch11

Changes in v3:
 - change patch1~10, patch14 title suggested by Joel Granados
 - change sysctl_stat_interval to static type in patch1
 - add acked-by from Paul Moore in patch7
 - change dirtytime_expire_interval to static type in patch9
 - add acked-by from Anna Schumaker in patch11

Changes in v2:
 - fix sysctl_max_map_count undeclared issue in mm/nommu.c for patch6
 - update changelog for patch7/12, suggested by Kees/Paul
 - fix patch8, sorry for wrong changes and forget to built with NOMMU
 - add reviewed-by from Kees except patch8 since patch8 is wrong in v1
 - add reviewed-by from Jan Kara, Christian Brauner in patch12

Kaixiong Yu (15):
  mm: vmstat: move sysctls to mm/vmstat.c
  mm: filemap: move sysctl to mm/filemap.c
  mm: swap: move sysctl to mm/swap.c
  mm: vmscan: move vmscan sysctls to mm/vmscan.c
  mm: util: move sysctls to mm/util.c
  mm: mmap: move sysctl to mm/mmap.c
  security: min_addr: move sysctl to security/min_addr.c
  mm: nommu: move sysctl to mm/nommu.c
  fs: fs-writeback: move sysctl to fs/fs-writeback.c
  fs: drop_caches: move sysctl to fs/drop_caches.c
  sunrpc: simplify rpcauth_cache_shrink_count()
  fs: dcache: move the sysctl to fs/dcache.c
  x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c
  sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c
  sysctl: remove unneeded include

 arch/sh/kernel/vsyscall/vsyscall.c |  14 ++
 arch/x86/entry/vdso/vdso32-setup.c |  16 ++-
 fs/dcache.c                        |  21 ++-
 fs/drop_caches.c                   |  23 ++-
 fs/fs-writeback.c                  |  30 ++--
 include/linux/dcache.h             |   7 +-
 include/linux/mm.h                 |  23 ---
 include/linux/mman.h               |   2 -
 include/linux/swap.h               |   9 --
 include/linux/vmstat.h             |  11 --
 include/linux/writeback.h          |   4 -
 kernel/sysctl.c                    | 221 -----------------------------
 mm/filemap.c                       |  18 ++-
 mm/internal.h                      |  10 ++
 mm/mmap.c                          |  54 +++++++
 mm/nommu.c                         |  15 +-
 mm/swap.c                          |  16 ++-
 mm/swap.h                          |   1 +
 mm/util.c                          |  67 +++++++--
 mm/vmscan.c                        |  23 +++
 mm/vmstat.c                        |  44 +++++-
 net/sunrpc/auth.c                  |   2 +-
 security/min_addr.c                |  11 ++
 23 files changed, 330 insertions(+), 312 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 01/15] mm: vmstat: move sysctls to mm/vmstat.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (15 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 02/15] mm: filemap: move sysctl to mm/filemap.c Kaixiong Yu
                   ` (14 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves all vmstat related sysctls to its own file, removes useless
extern variable declarations, and do some related clean-ups. To avoid
compiler warnings when CONFIG_PROC_FS is not defined, add the macro
definition CONFIG_PROC_FS ahead CONFIG_NUMA in vmstat.c.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vmstat_table
v3:
 - change the title
 - change sysctl_stat_interval to static type
---
---
 include/linux/vmstat.h | 11 -----------
 kernel/sysctl.c        | 28 ---------------------------
 mm/vmstat.c            | 44 ++++++++++++++++++++++++++++++++++++++----
 3 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index 9f3a04345b86..4751e3ecc467 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -10,15 +10,8 @@
 #include <linux/static_key.h>
 #include <linux/mmdebug.h>
 
-extern int sysctl_stat_interval;
-
 #ifdef CONFIG_NUMA
-#define ENABLE_NUMA_STAT   1
-#define DISABLE_NUMA_STAT   0
-extern int sysctl_vm_numa_stat;
 DECLARE_STATIC_KEY_TRUE(vm_numa_stat_key);
-int sysctl_vm_numa_stat_handler(const struct ctl_table *table, int write,
-		void *buffer, size_t *length, loff_t *ppos);
 #endif
 
 struct reclaim_stat {
@@ -304,10 +297,6 @@ void quiet_vmstat(void);
 void cpu_vm_stats_fold(int cpu);
 void refresh_zone_stat_thresholds(void);
 
-struct ctl_table;
-int vmstat_refresh(const struct ctl_table *, int write, void *buffer, size_t *lenp,
-		loff_t *ppos);
-
 void drain_zonestat(struct zone *zone, struct per_cpu_zonestat *);
 
 int calculate_pressure_threshold(struct zone *zone);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7ae7a4136855..f1ab251fc2d0 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -49,7 +49,6 @@
 #include <linux/limits.h>
 #include <linux/dcache.h>
 #include <linux/syscalls.h>
-#include <linux/vmstat.h>
 #include <linux/nfs_fs.h>
 #include <linux/acpi.h>
 #include <linux/reboot.h>
@@ -2071,17 +2070,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_TWO_HUNDRED,
 	},
-#ifdef CONFIG_NUMA
-	{
-		.procname	= "numa_stat",
-		.data		= &sysctl_vm_numa_stat,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= sysctl_vm_numa_stat_handler,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-#endif
 	{
 		.procname	= "drop_caches",
 		.data		= &sysctl_drop_caches,
@@ -2147,22 +2135,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif
-#ifdef CONFIG_SMP
-	{
-		.procname	= "stat_interval",
-		.data		= &sysctl_stat_interval,
-		.maxlen		= sizeof(sysctl_stat_interval),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_jiffies,
-	},
-	{
-		.procname	= "stat_refresh",
-		.data		= NULL,
-		.maxlen		= 0,
-		.mode		= 0600,
-		.proc_handler	= vmstat_refresh,
-	},
-#endif
 #ifdef CONFIG_MMU
 	{
 		.procname	= "mmap_min_addr",
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 4d016314a56c..cb4dcd4c6715 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -31,8 +31,10 @@
 
 #include "internal.h"
 
+#ifdef CONFIG_PROC_FS
 #ifdef CONFIG_NUMA
-int sysctl_vm_numa_stat = ENABLE_NUMA_STAT;
+#define ENABLE_NUMA_STAT 1
+static int sysctl_vm_numa_stat = ENABLE_NUMA_STAT;
 
 /* zero numa counters within a zone */
 static void zero_zone_numa_counters(struct zone *zone)
@@ -74,7 +76,7 @@ static void invalid_numa_statistics(void)
 
 static DEFINE_MUTEX(vm_numa_stat_lock);
 
-int sysctl_vm_numa_stat_handler(const struct ctl_table *table, int write,
+static int sysctl_vm_numa_stat_handler(const struct ctl_table *table, int write,
 		void *buffer, size_t *length, loff_t *ppos)
 {
 	int ret, oldval;
@@ -102,6 +104,7 @@ int sysctl_vm_numa_stat_handler(const struct ctl_table *table, int write,
 	return ret;
 }
 #endif
+#endif /* CONFIG_PROC_FS */
 
 #ifdef CONFIG_VM_EVENT_COUNTERS
 DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
@@ -1938,7 +1941,7 @@ static const struct seq_operations vmstat_op = {
 
 #ifdef CONFIG_SMP
 static DEFINE_PER_CPU(struct delayed_work, vmstat_work);
-int sysctl_stat_interval __read_mostly = HZ;
+static int sysctl_stat_interval __read_mostly = HZ;
 static int vmstat_late_init_done;
 
 #ifdef CONFIG_PROC_FS
@@ -1947,7 +1950,7 @@ static void refresh_vm_stats(struct work_struct *work)
 	refresh_cpu_vm_stats(true);
 }
 
-int vmstat_refresh(const struct ctl_table *table, int write,
+static int vmstat_refresh(const struct ctl_table *table, int write,
 		   void *buffer, size_t *lenp, loff_t *ppos)
 {
 	long val;
@@ -2185,6 +2188,38 @@ static int __init vmstat_late_init(void)
 late_initcall(vmstat_late_init);
 #endif
 
+#ifdef CONFIG_PROC_FS
+static const struct ctl_table vmstat_table[] = {
+#ifdef CONFIG_SMP
+	{
+		.procname	= "stat_interval",
+		.data		= &sysctl_stat_interval,
+		.maxlen		= sizeof(sysctl_stat_interval),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_jiffies,
+	},
+	{
+		.procname	= "stat_refresh",
+		.data		= NULL,
+		.maxlen		= 0,
+		.mode		= 0600,
+		.proc_handler	= vmstat_refresh,
+	},
+#endif
+#ifdef CONFIG_NUMA
+	{
+		.procname	= "numa_stat",
+		.data		= &sysctl_vm_numa_stat,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= sysctl_vm_numa_stat_handler,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+#endif
+};
+#endif
+
 struct workqueue_struct *mm_percpu_wq;
 
 void __init init_mm_internals(void)
@@ -2216,6 +2251,7 @@ void __init init_mm_internals(void)
 	proc_create_seq("pagetypeinfo", 0400, NULL, &pagetypeinfo_op);
 	proc_create_seq("vmstat", 0444, NULL, &vmstat_op);
 	proc_create_seq("zoneinfo", 0444, NULL, &zoneinfo_op);
+	register_sysctl_init("vm", vmstat_table);
 #endif
 }
 
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 02/15] mm: filemap: move sysctl to mm/filemap.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (16 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 01/15] mm: vmstat: move sysctls to mm/vmstat.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 03/15] mm: swap: move sysctl to mm/swap.c Kaixiong Yu
                   ` (13 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves the filemap related sysctl to mm/filemap.c, and
removes the redundant external variable declaration.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table filemap_sysctl_table
v3:
 - change the title
---
---
 include/linux/mm.h |  2 --
 kernel/sysctl.c    |  8 --------
 mm/filemap.c       | 18 +++++++++++++++---
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index d61b9c7a3a7b..dbdf8950d681 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -40,8 +40,6 @@ struct user_struct;
 struct pt_regs;
 struct folio_batch;
 
-extern int sysctl_page_lock_unfairness;
-
 void mm_core_init(void);
 void init_mm_internals(void);
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index f1ab251fc2d0..23c8db80da5d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2079,14 +2079,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_FOUR,
 	},
-	{
-		.procname	= "page_lock_unfairness",
-		.data		= &sysctl_page_lock_unfairness,
-		.maxlen		= sizeof(sysctl_page_lock_unfairness),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
 #ifdef CONFIG_MMU
 	{
 		.procname	= "max_map_count",
diff --git a/mm/filemap.c b/mm/filemap.c
index 899dab55d235..bb7aff8960a4 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -47,6 +47,7 @@
 #include <linux/splice.h>
 #include <linux/rcupdate_wait.h>
 #include <linux/sched/mm.h>
+#include <linux/sysctl.h>
 #include <linux/fsnotify.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
@@ -1069,6 +1070,19 @@ static wait_queue_head_t *folio_waitqueue(struct folio *folio)
 	return &folio_wait_table[hash_ptr(folio, PAGE_WAIT_TABLE_BITS)];
 }
 
+/* How many times do we accept lock stealing from under a waiter? */
+static int sysctl_page_lock_unfairness = 5;
+static const struct ctl_table filemap_sysctl_table[] = {
+	{
+		.procname	= "page_lock_unfairness",
+		.data		= &sysctl_page_lock_unfairness,
+		.maxlen		= sizeof(sysctl_page_lock_unfairness),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+	}
+};
+
 void __init pagecache_init(void)
 {
 	int i;
@@ -1077,6 +1091,7 @@ void __init pagecache_init(void)
 		init_waitqueue_head(&folio_wait_table[i]);
 
 	page_writeback_init();
+	register_sysctl_init("vm", filemap_sysctl_table);
 }
 
 /*
@@ -1224,9 +1239,6 @@ static inline bool folio_trylock_flag(struct folio *folio, int bit_nr,
 	return true;
 }
 
-/* How many times do we accept lock stealing from under a waiter? */
-int sysctl_page_lock_unfairness = 5;
-
 static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,
 		int state, enum behavior behavior)
 {
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 03/15] mm: swap: move sysctl to mm/swap.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (17 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 02/15] mm: filemap: move sysctl to mm/filemap.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 04/15] mm: vmscan: move vmscan sysctls to mm/vmscan.c Kaixiong Yu
                   ` (12 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The page-cluster belongs to mm/swap.c, move it to mm/swap.c .
Removes the redundant external variable declaration and unneeded
include(linux/swap.h).

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table swap_sysctl_table
v3:
 - change the title
---
---
 include/linux/mm.h |  2 --
 kernel/sysctl.c    | 10 ----------
 mm/swap.c          | 16 +++++++++++++++-
 mm/swap.h          |  1 +
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index dbdf8950d681..8941ba3d9a77 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -76,8 +76,6 @@ static inline void totalram_pages_add(long count)
 }
 
 extern void * high_memory;
-extern int page_cluster;
-extern const int page_cluster_max;
 
 #ifdef CONFIG_SYSCTL
 extern int sysctl_legacy_va_layout;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 23c8db80da5d..ab5d94f07e53 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -21,7 +21,6 @@
 
 #include <linux/module.h>
 #include <linux/mm.h>
-#include <linux/swap.h>
 #include <linux/slab.h>
 #include <linux/sysctl.h>
 #include <linux/bitmap.h>
@@ -2044,15 +2043,6 @@ static struct ctl_table vm_table[] = {
 		.mode		= 0644,
 		.proc_handler	= overcommit_kbytes_handler,
 	},
-	{
-		.procname	= "page-cluster",
-		.data		= &page_cluster,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= (void *)&page_cluster_max,
-	},
 	{
 		.procname	= "dirtytime_expire_seconds",
 		.data		= &dirtytime_expire_interval,
diff --git a/mm/swap.c b/mm/swap.c
index 062c8565b899..d3344123381c 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -45,7 +45,7 @@
 
 /* How many pages do we try to swap or page in/out together? As a power of 2 */
 int page_cluster;
-const int page_cluster_max = 31;
+static const int page_cluster_max = 31;
 
 struct cpu_fbatches {
 	/*
@@ -1072,6 +1072,18 @@ void folio_batch_remove_exceptionals(struct folio_batch *fbatch)
 	fbatch->nr = j;
 }
 
+static const struct ctl_table swap_sysctl_table[] = {
+	{
+		.procname	= "page-cluster",
+		.data		= &page_cluster,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= (void *)&page_cluster_max,
+	}
+};
+
 /*
  * Perform any setup for the swap system
  */
@@ -1088,4 +1100,6 @@ void __init swap_setup(void)
 	 * Right now other parts of the system means that we
 	 * _really_ don't want to cluster much more
 	 */
+
+	register_sysctl_init("vm", swap_sysctl_table);
 }
diff --git a/mm/swap.h b/mm/swap.h
index ad2f121de970..274dcc6219a0 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -3,6 +3,7 @@
 #define _MM_SWAP_H
 
 struct mempolicy;
+extern int page_cluster;
 
 #ifdef CONFIG_SWAP
 #include <linux/swapops.h> /* for swp_offset */
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 04/15] mm: vmscan: move vmscan sysctls to mm/vmscan.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (18 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 03/15] mm: swap: move sysctl to mm/swap.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 05/15] mm: util: move sysctls to mm/util.c Kaixiong Yu
                   ` (11 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves vm_swappiness and zone_reclaim_mode to mm/vmscan.c,
as part of the kernel/sysctl.c cleaning, also moves some external
variable declarations and function declarations from include/linux/swap.h
into mm/internal.h.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vmscan_sysctl_table
v3:
 - change the title
---
---
 include/linux/swap.h |  9 ---------
 kernel/sysctl.c      | 19 -------------------
 mm/internal.h        | 10 ++++++++++
 mm/vmscan.c          | 23 +++++++++++++++++++++++
 4 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/include/linux/swap.h b/include/linux/swap.h
index 187715eec3cb..db1a28683e10 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -427,19 +427,10 @@ extern int vm_swappiness;
 long remove_mapping(struct address_space *mapping, struct folio *folio);
 
 #ifdef CONFIG_NUMA
-extern int node_reclaim_mode;
 extern int sysctl_min_unmapped_ratio;
 extern int sysctl_min_slab_ratio;
-#else
-#define node_reclaim_mode 0
 #endif
 
-static inline bool node_reclaim_enabled(void)
-{
-	/* Is any node_reclaim_mode bit set? */
-	return node_reclaim_mode & (RECLAIM_ZONE|RECLAIM_WRITE|RECLAIM_UNMAP);
-}
-
 void check_move_unevictable_folios(struct folio_batch *fbatch);
 
 extern void __meminit kswapd_run(int nid);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index ab5d94f07e53..cb6ca272fe9f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2051,15 +2051,6 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= dirtytime_interval_handler,
 		.extra1		= SYSCTL_ZERO,
 	},
-	{
-		.procname	= "swappiness",
-		.data		= &vm_swappiness,
-		.maxlen		= sizeof(vm_swappiness),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_TWO_HUNDRED,
-	},
 	{
 		.procname	= "drop_caches",
 		.data		= &sysctl_drop_caches,
@@ -2107,16 +2098,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif
-#ifdef CONFIG_NUMA
-	{
-		.procname	= "zone_reclaim_mode",
-		.data		= &node_reclaim_mode,
-		.maxlen		= sizeof(node_reclaim_mode),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
 #ifdef CONFIG_MMU
 	{
 		.procname	= "mmap_min_addr",
diff --git a/mm/internal.h b/mm/internal.h
index 39227887e47b..ea2623dc414a 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1095,9 +1095,13 @@ static inline void mminit_verify_zonelist(void)
 #define NODE_RECLAIM_SUCCESS	1
 
 #ifdef CONFIG_NUMA
+extern int node_reclaim_mode;
+
 extern int node_reclaim(struct pglist_data *, gfp_t, unsigned int);
 extern int find_next_best_node(int node, nodemask_t *used_node_mask);
 #else
+#define node_reclaim_mode 0
+
 static inline int node_reclaim(struct pglist_data *pgdat, gfp_t mask,
 				unsigned int order)
 {
@@ -1109,6 +1113,12 @@ static inline int find_next_best_node(int node, nodemask_t *used_node_mask)
 }
 #endif
 
+static inline bool node_reclaim_enabled(void)
+{
+	/* Is any node_reclaim_mode bit set? */
+	return node_reclaim_mode & (RECLAIM_ZONE|RECLAIM_WRITE|RECLAIM_UNMAP);
+}
+
 /*
  * mm/memory-failure.c
  */
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 39886f435ec5..10cc05b5952d 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -7351,6 +7351,28 @@ void __meminit kswapd_stop(int nid)
 	pgdat_kswapd_unlock(pgdat);
 }
 
+static const struct ctl_table vmscan_sysctl_table[] = {
+	{
+		.procname	= "swappiness",
+		.data		= &vm_swappiness,
+		.maxlen		= sizeof(vm_swappiness),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_TWO_HUNDRED,
+	},
+#ifdef CONFIG_NUMA
+	{
+		.procname	= "zone_reclaim_mode",
+		.data		= &node_reclaim_mode,
+		.maxlen		= sizeof(node_reclaim_mode),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+	}
+#endif
+};
+
 static int __init kswapd_init(void)
 {
 	int nid;
@@ -7358,6 +7380,7 @@ static int __init kswapd_init(void)
 	swap_setup();
 	for_each_node_state(nid, N_MEMORY)
  		kswapd_run(nid);
+	register_sysctl_init("vm", vmscan_sysctl_table);
 	return 0;
 }
 
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 05/15] mm: util: move sysctls to mm/util.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (19 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 04/15] mm: vmscan: move vmscan sysctls to mm/vmscan.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Kaixiong Yu
                   ` (10 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves all util related sysctls to mm/util.c, as part of the
kernel/sysctl.c cleaning, also removes redundant external
variable declarations and function declarations.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table util_sysctl_table
v3:
 - change the title
---
---
 include/linux/mm.h   | 11 --------
 include/linux/mman.h |  2 --
 kernel/sysctl.c      | 37 ------------------------
 mm/util.c            | 67 ++++++++++++++++++++++++++++++++++++++------
 4 files changed, 59 insertions(+), 58 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8941ba3d9a77..b3b87c1dc1e4 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -205,17 +205,6 @@ extern int sysctl_max_map_count;
 extern unsigned long sysctl_user_reserve_kbytes;
 extern unsigned long sysctl_admin_reserve_kbytes;
 
-extern int sysctl_overcommit_memory;
-extern int sysctl_overcommit_ratio;
-extern unsigned long sysctl_overcommit_kbytes;
-
-int overcommit_ratio_handler(const struct ctl_table *, int, void *, size_t *,
-		loff_t *);
-int overcommit_kbytes_handler(const struct ctl_table *, int, void *, size_t *,
-		loff_t *);
-int overcommit_policy_handler(const struct ctl_table *, int, void *, size_t *,
-		loff_t *);
-
 #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
 #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
 #define folio_page_idx(folio, p)	(page_to_pfn(p) - folio_pfn(folio))
diff --git a/include/linux/mman.h b/include/linux/mman.h
index a842783ffa62..bce214fece16 100644
--- a/include/linux/mman.h
+++ b/include/linux/mman.h
@@ -59,8 +59,6 @@
 		| MAP_HUGE_1GB)
 
 extern int sysctl_overcommit_memory;
-extern int sysctl_overcommit_ratio;
-extern unsigned long sysctl_overcommit_kbytes;
 extern struct percpu_counter vm_committed_as;
 
 #ifdef CONFIG_SMP
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index cb6ca272fe9f..aea3482106e0 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2020,29 +2020,6 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-	{
-		.procname	= "overcommit_memory",
-		.data		= &sysctl_overcommit_memory,
-		.maxlen		= sizeof(sysctl_overcommit_memory),
-		.mode		= 0644,
-		.proc_handler	= overcommit_policy_handler,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_TWO,
-	},
-	{
-		.procname	= "overcommit_ratio",
-		.data		= &sysctl_overcommit_ratio,
-		.maxlen		= sizeof(sysctl_overcommit_ratio),
-		.mode		= 0644,
-		.proc_handler	= overcommit_ratio_handler,
-	},
-	{
-		.procname	= "overcommit_kbytes",
-		.data		= &sysctl_overcommit_kbytes,
-		.maxlen		= sizeof(sysctl_overcommit_kbytes),
-		.mode		= 0644,
-		.proc_handler	= overcommit_kbytes_handler,
-	},
 	{
 		.procname	= "dirtytime_expire_seconds",
 		.data		= &dirtytime_expire_interval,
@@ -2123,20 +2100,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif
-	{
-		.procname	= "user_reserve_kbytes",
-		.data		= &sysctl_user_reserve_kbytes,
-		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
-		.mode		= 0644,
-		.proc_handler	= proc_doulongvec_minmax,
-	},
-	{
-		.procname	= "admin_reserve_kbytes",
-		.data		= &sysctl_admin_reserve_kbytes,
-		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
-		.mode		= 0644,
-		.proc_handler	= proc_doulongvec_minmax,
-	},
 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
 	{
 		.procname	= "mmap_rnd_bits",
diff --git a/mm/util.c b/mm/util.c
index b7dc6fabaae5..6c64664937b3 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -12,6 +12,7 @@
 #include <linux/security.h>
 #include <linux/swap.h>
 #include <linux/swapops.h>
+#include <linux/sysctl.h>
 #include <linux/mman.h>
 #include <linux/hugetlb.h>
 #include <linux/vmalloc.h>
@@ -911,14 +912,16 @@ int folio_mc_copy(struct folio *dst, struct folio *src)
 EXPORT_SYMBOL(folio_mc_copy);
 
 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS;
-int sysctl_overcommit_ratio __read_mostly = 50;
-unsigned long sysctl_overcommit_kbytes __read_mostly;
+static int sysctl_overcommit_ratio __read_mostly = 50;
+static unsigned long sysctl_overcommit_kbytes __read_mostly;
 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
 
-int overcommit_ratio_handler(const struct ctl_table *table, int write, void *buffer,
-		size_t *lenp, loff_t *ppos)
+#ifdef CONFIG_SYSCTL
+
+static int overcommit_ratio_handler(const struct ctl_table *table, int write,
+				void *buffer, size_t *lenp, loff_t *ppos)
 {
 	int ret;
 
@@ -933,8 +936,8 @@ static void sync_overcommit_as(struct work_struct *dummy)
 	percpu_counter_sync(&vm_committed_as);
 }
 
-int overcommit_policy_handler(const struct ctl_table *table, int write, void *buffer,
-		size_t *lenp, loff_t *ppos)
+static int overcommit_policy_handler(const struct ctl_table *table, int write,
+				void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct ctl_table t;
 	int new_policy = -1;
@@ -969,8 +972,8 @@ int overcommit_policy_handler(const struct ctl_table *table, int write, void *bu
 	return ret;
 }
 
-int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *buffer,
-		size_t *lenp, loff_t *ppos)
+static int overcommit_kbytes_handler(const struct ctl_table *table, int write,
+				void *buffer, size_t *lenp, loff_t *ppos)
 {
 	int ret;
 
@@ -980,6 +983,54 @@ int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *bu
 	return ret;
 }
 
+static const struct ctl_table util_sysctl_table[] = {
+	{
+		.procname	= "overcommit_memory",
+		.data		= &sysctl_overcommit_memory,
+		.maxlen		= sizeof(sysctl_overcommit_memory),
+		.mode		= 0644,
+		.proc_handler	= overcommit_policy_handler,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_TWO,
+	},
+	{
+		.procname	= "overcommit_ratio",
+		.data		= &sysctl_overcommit_ratio,
+		.maxlen		= sizeof(sysctl_overcommit_ratio),
+		.mode		= 0644,
+		.proc_handler	= overcommit_ratio_handler,
+	},
+	{
+		.procname	= "overcommit_kbytes",
+		.data		= &sysctl_overcommit_kbytes,
+		.maxlen		= sizeof(sysctl_overcommit_kbytes),
+		.mode		= 0644,
+		.proc_handler	= overcommit_kbytes_handler,
+	},
+	{
+		.procname	= "user_reserve_kbytes",
+		.data		= &sysctl_user_reserve_kbytes,
+		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
+		.mode		= 0644,
+		.proc_handler	= proc_doulongvec_minmax,
+	},
+	{
+		.procname	= "admin_reserve_kbytes",
+		.data		= &sysctl_admin_reserve_kbytes,
+		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
+		.mode		= 0644,
+		.proc_handler	= proc_doulongvec_minmax,
+	},
+};
+
+static int __init init_vm_util_sysctls(void)
+{
+	register_sysctl_init("vm", util_sysctl_table);
+	return 0;
+}
+subsys_initcall(init_vm_util_sysctls);
+#endif /* CONFIG_SYSCTL */
+
 /*
  * Committed memory limit enforced when OVERCOMMIT_NEVER policy is used
  */
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (20 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 05/15] mm: util: move sysctls to mm/util.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 07/15] security: min_addr: move sysctl to security/min_addr.c Kaixiong Yu
                   ` (9 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves all mmap related sysctls to mm/mmap.c, as part of the
kernel/sysctl.c cleaning, also move the variable declaration from
kernel/sysctl.c into mm/mmap.c.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table mmap_table
v3:
 - change the title
v2:
 - fix sysctl_max_map_count undeclared issue in mm/nommu.c
---
---
 kernel/sysctl.c | 50 +--------------------------------------------
 mm/mmap.c       | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 49 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index aea3482106e0..9c245898f535 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -127,12 +127,6 @@ enum sysctl_writes_mode {
 
 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
 #endif /* CONFIG_PROC_SYSCTL */
-
-#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
-    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
-int sysctl_legacy_va_layout;
-#endif
-
 #endif /* CONFIG_SYSCTL */
 
 /*
@@ -2037,16 +2031,7 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_FOUR,
 	},
-#ifdef CONFIG_MMU
-	{
-		.procname	= "max_map_count",
-		.data		= &sysctl_max_map_count,
-		.maxlen		= sizeof(sysctl_max_map_count),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#else
+#ifndef CONFIG_MMU
 	{
 		.procname	= "nr_trim_pages",
 		.data		= &sysctl_nr_trim_pages,
@@ -2064,17 +2049,6 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= SYSCTL_ZERO,
 	},
-#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
-    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
-	{
-		.procname	= "legacy_va_layout",
-		.data		= &sysctl_legacy_va_layout,
-		.maxlen		= sizeof(sysctl_legacy_va_layout),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
 #ifdef CONFIG_MMU
 	{
 		.procname	= "mmap_min_addr",
@@ -2100,28 +2074,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif
-#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
-	{
-		.procname	= "mmap_rnd_bits",
-		.data		= &mmap_rnd_bits,
-		.maxlen		= sizeof(mmap_rnd_bits),
-		.mode		= 0600,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= (void *)&mmap_rnd_bits_min,
-		.extra2		= (void *)&mmap_rnd_bits_max,
-	},
-#endif
-#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
-	{
-		.procname	= "mmap_rnd_compat_bits",
-		.data		= &mmap_rnd_compat_bits,
-		.maxlen		= sizeof(mmap_rnd_compat_bits),
-		.mode		= 0600,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= (void *)&mmap_rnd_compat_bits_min,
-		.extra2		= (void *)&mmap_rnd_compat_bits_max,
-	},
-#endif
 };
 
 int __init sysctl_init_bases(void)
diff --git a/mm/mmap.c b/mm/mmap.c
index aef835984b1c..cc579aafd7ba 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1603,6 +1603,57 @@ struct vm_area_struct *_install_special_mapping(
 					&special_mapping_vmops);
 }
 
+#ifdef CONFIG_SYSCTL
+#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
+		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
+int sysctl_legacy_va_layout;
+#endif
+
+static const struct ctl_table mmap_table[] = {
+		{
+				.procname       = "max_map_count",
+				.data           = &sysctl_max_map_count,
+				.maxlen         = sizeof(sysctl_max_map_count),
+				.mode           = 0644,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = SYSCTL_ZERO,
+		},
+#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
+		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
+		{
+				.procname       = "legacy_va_layout",
+				.data           = &sysctl_legacy_va_layout,
+				.maxlen         = sizeof(sysctl_legacy_va_layout),
+				.mode           = 0644,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = SYSCTL_ZERO,
+		},
+#endif
+#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
+		{
+				.procname       = "mmap_rnd_bits",
+				.data           = &mmap_rnd_bits,
+				.maxlen         = sizeof(mmap_rnd_bits),
+				.mode           = 0600,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = (void *)&mmap_rnd_bits_min,
+				.extra2         = (void *)&mmap_rnd_bits_max,
+		},
+#endif
+#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
+		{
+				.procname       = "mmap_rnd_compat_bits",
+				.data           = &mmap_rnd_compat_bits,
+				.maxlen         = sizeof(mmap_rnd_compat_bits),
+				.mode           = 0600,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = (void *)&mmap_rnd_compat_bits_min,
+				.extra2         = (void *)&mmap_rnd_compat_bits_max,
+		},
+#endif
+};
+#endif /* CONFIG_SYSCTL */
+
 /*
  * initialise the percpu counter for VM
  */
@@ -1612,6 +1663,9 @@ void __init mmap_init(void)
 
 	ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
 	VM_BUG_ON(ret);
+#ifdef CONFIG_SYSCTL
+	register_sysctl_init("vm", mmap_table);
+#endif
 }
 
 /*
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 07/15] security: min_addr: move sysctl to security/min_addr.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (21 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c Kaixiong Yu
                   ` (8 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The dac_mmap_min_addr belongs to min_addr.c, move it to
min_addr.c from /kernel/sysctl.c. In the previous Linux kernel
boot process, sysctl_init_bases needs to be executed before
init_mmap_min_addr, So, register_sysctl_init should be executed
before update_mmap_min_addr in init_mmap_min_addr. And according
to the compilation condition in security/Makefile:

      obj-$(CONFIG_MMU)            += min_addr.o

if CONFIG_MMU is not defined, min_addr.c would not be included in the
compilation process. So, drop the CONFIG_MMU check.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Acked-by: Paul Moore <paul@paul-moore.com>
---
v4:
 - const qualify struct ctl_table min_addr_sysctl_table
v3:
 - change the title
v2:
 - update the changelog to explain why drop CONFIG_MMU check.
---
---
 kernel/sysctl.c     |  9 ---------
 security/min_addr.c | 11 +++++++++++
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 9c245898f535..62a58e417c40 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2049,15 +2049,6 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= SYSCTL_ZERO,
 	},
-#ifdef CONFIG_MMU
-	{
-		.procname	= "mmap_min_addr",
-		.data		= &dac_mmap_min_addr,
-		.maxlen		= sizeof(unsigned long),
-		.mode		= 0644,
-		.proc_handler	= mmap_min_addr_handler,
-	},
-#endif
 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
 	{
diff --git a/security/min_addr.c b/security/min_addr.c
index 0ce267c041ab..df1bc643d886 100644
--- a/security/min_addr.c
+++ b/security/min_addr.c
@@ -44,8 +44,19 @@ int mmap_min_addr_handler(const struct ctl_table *table, int write,
 	return ret;
 }
 
+static const struct ctl_table min_addr_sysctl_table[] = {
+	{
+		.procname	= "mmap_min_addr",
+		.data		= &dac_mmap_min_addr,
+		.maxlen		= sizeof(unsigned long),
+		.mode		= 0644,
+		.proc_handler	= mmap_min_addr_handler,
+	},
+};
+
 static int __init init_mmap_min_addr(void)
 {
+	register_sysctl_init("vm", min_addr_sysctl_table);
 	update_mmap_min_addr();
 
 	return 0;
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (22 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 07/15] security: min_addr: move sysctl to security/min_addr.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 09/15] fs: fs-writeback: move sysctl to fs/fs-writeback.c Kaixiong Yu
                   ` (7 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The sysctl_nr_trim_pages belongs to nommu.c, move it to mm/nommu.c
from /kernel/sysctl.c. And remove the useless extern variable declaration
from include/linux/mm.h

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
---
v4:
 - const qualify struct ctl_table nommu_table
v3:
 - change the title
v2:
 - fix the build error: expected ';' after top level declarator
 - fix the build error: call to undeclared function 'register_syscall_init',
   use 'register_sysctl_init' to replace it.
---
---
 include/linux/mm.h |  2 --
 kernel/sysctl.c    | 10 ----------
 mm/nommu.c         | 15 ++++++++++++++-
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index b3b87c1dc1e4..9813b5b9c093 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -4080,8 +4080,6 @@ unsigned long wp_shared_mapping_range(struct address_space *mapping,
 				      pgoff_t first_index, pgoff_t nr);
 #endif
 
-extern int sysctl_nr_trim_pages;
-
 #ifdef CONFIG_PRINTK
 void mem_dump_obj(void *object);
 #else
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 62a58e417c40..97f9abffff0f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2031,16 +2031,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_FOUR,
 	},
-#ifndef CONFIG_MMU
-	{
-		.procname	= "nr_trim_pages",
-		.data		= &sysctl_nr_trim_pages,
-		.maxlen		= sizeof(sysctl_nr_trim_pages),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
 	{
 		.procname	= "vfs_cache_pressure",
 		.data		= &sysctl_vfs_cache_pressure,
diff --git a/mm/nommu.c b/mm/nommu.c
index baa79abdaf03..3c32f8b1eb54 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -48,7 +48,6 @@ struct page *mem_map;
 unsigned long max_mapnr;
 EXPORT_SYMBOL(max_mapnr);
 unsigned long highest_memmap_pfn;
-int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
 int heap_stack_gap = 0;
 
 atomic_long_t mmap_pages_allocated;
@@ -392,6 +391,19 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
 	return mm->brk = brk;
 }
 
+static int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
+
+static const struct ctl_table nommu_table[] = {
+	{
+		.procname	= "nr_trim_pages",
+		.data		= &sysctl_nr_trim_pages,
+		.maxlen		= sizeof(sysctl_nr_trim_pages),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+	},
+};
+
 /*
  * initialise the percpu counter for VM and region record slabs
  */
@@ -402,6 +414,7 @@ void __init mmap_init(void)
 	ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
 	VM_BUG_ON(ret);
 	vm_region_jar = KMEM_CACHE(vm_region, SLAB_PANIC|SLAB_ACCOUNT);
+	register_sysctl_init("vm", nommu_table);
 }
 
 /*
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 09/15] fs: fs-writeback: move sysctl to fs/fs-writeback.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (23 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 10/15] fs: drop_caches: move sysctl to fs/drop_caches.c Kaixiong Yu
                   ` (6 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The dirtytime_expire_interval belongs to fs/fs-writeback.c, move it to
fs/fs-writeback.c from /kernel/sysctl.c. And remove the useless extern
variable declaration and the function declaration from
include/linux/writeback.h

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
---
v4:
 - const qualify struct ctl_table vm_fs_writeback_table
v3:
 - change dirtytime_expire_interval to static type
 - change the title
---
---
 fs/fs-writeback.c         | 30 +++++++++++++++++++++---------
 include/linux/writeback.h |  4 ----
 kernel/sysctl.c           |  8 --------
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 5980ac24c7a4..4f907e8dbfff 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -65,7 +65,7 @@ struct wb_writeback_work {
  * timestamps written to disk after 12 hours, but in the worst case a
  * few inodes might not their timestamps updated for 24 hours.
  */
-unsigned int dirtytime_expire_interval = 12 * 60 * 60;
+static unsigned int dirtytime_expire_interval = 12 * 60 * 60;
 
 static inline struct inode *wb_inode(struct list_head *head)
 {
@@ -2435,14 +2435,7 @@ static void wakeup_dirtytime_writeback(struct work_struct *w)
 	schedule_delayed_work(&dirtytime_work, dirtytime_expire_interval * HZ);
 }
 
-static int __init start_dirtytime_writeback(void)
-{
-	schedule_delayed_work(&dirtytime_work, dirtytime_expire_interval * HZ);
-	return 0;
-}
-__initcall(start_dirtytime_writeback);
-
-int dirtytime_interval_handler(const struct ctl_table *table, int write,
+static int dirtytime_interval_handler(const struct ctl_table *table, int write,
 			       void *buffer, size_t *lenp, loff_t *ppos)
 {
 	int ret;
@@ -2453,6 +2446,25 @@ int dirtytime_interval_handler(const struct ctl_table *table, int write,
 	return ret;
 }
 
+static const struct ctl_table vm_fs_writeback_table[] = {
+	{
+		.procname	= "dirtytime_expire_seconds",
+		.data		= &dirtytime_expire_interval,
+		.maxlen		= sizeof(dirtytime_expire_interval),
+		.mode		= 0644,
+		.proc_handler	= dirtytime_interval_handler,
+		.extra1		= SYSCTL_ZERO,
+	},
+};
+
+static int __init start_dirtytime_writeback(void)
+{
+	schedule_delayed_work(&dirtytime_work, dirtytime_expire_interval * HZ);
+	register_sysctl_init("vm", vm_fs_writeback_table);
+	return 0;
+}
+__initcall(start_dirtytime_writeback);
+
 /**
  * __mark_inode_dirty -	internal function to mark an inode dirty
  *
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index d11b903c2edb..caf4f0b12235 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -327,12 +327,8 @@ extern struct wb_domain global_wb_domain;
 /* These are exported to sysctl. */
 extern unsigned int dirty_writeback_interval;
 extern unsigned int dirty_expire_interval;
-extern unsigned int dirtytime_expire_interval;
 extern int laptop_mode;
 
-int dirtytime_interval_handler(const struct ctl_table *table, int write,
-		void *buffer, size_t *lenp, loff_t *ppos);
-
 void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
 unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh);
 unsigned long cgwb_calc_thresh(struct bdi_writeback *wb);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 97f9abffff0f..c5527f59e3f2 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2014,14 +2014,6 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-	{
-		.procname	= "dirtytime_expire_seconds",
-		.data		= &dirtytime_expire_interval,
-		.maxlen		= sizeof(dirtytime_expire_interval),
-		.mode		= 0644,
-		.proc_handler	= dirtytime_interval_handler,
-		.extra1		= SYSCTL_ZERO,
-	},
 	{
 		.procname	= "drop_caches",
 		.data		= &sysctl_drop_caches,
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 10/15] fs: drop_caches: move sysctl to fs/drop_caches.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (24 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 09/15] fs: fs-writeback: move sysctl to fs/fs-writeback.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 11/15] sunrpc: simplify rpcauth_cache_shrink_count() Kaixiong Yu
                   ` (5 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The sysctl_drop_caches to fs/drop_caches.c, move it to
fs/drop_caches.c from /kernel/sysctl.c. And remove the
useless extern variable declaration from include/linux/mm.h

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christian Brauner <brauner@kernel.org>
---
v4:
 - const qualify struct ctl_table drop_caches_table
v3:
 - change the title
---
---
 fs/drop_caches.c   | 23 +++++++++++++++++++++--
 include/linux/mm.h |  6 ------
 kernel/sysctl.c    |  9 ---------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index d45ef541d848..019a8b4eaaf9 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -14,7 +14,7 @@
 #include "internal.h"
 
 /* A global variable is a bit ugly, but it keeps the code simple */
-int sysctl_drop_caches;
+static int sysctl_drop_caches;
 
 static void drop_pagecache_sb(struct super_block *sb, void *unused)
 {
@@ -48,7 +48,7 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
 	iput(toput_inode);
 }
 
-int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
+static int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
 		void *buffer, size_t *length, loff_t *ppos)
 {
 	int ret;
@@ -77,3 +77,22 @@ int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
 	}
 	return 0;
 }
+
+static const struct ctl_table drop_caches_table[] = {
+	{
+		.procname	= "drop_caches",
+		.data		= &sysctl_drop_caches,
+		.maxlen		= sizeof(int),
+		.mode		= 0200,
+		.proc_handler	= drop_caches_sysctl_handler,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= SYSCTL_FOUR,
+	},
+};
+
+static int __init init_vm_drop_caches_sysctls(void)
+{
+	register_sysctl_init("vm", drop_caches_table);
+	return 0;
+}
+fs_initcall(init_vm_drop_caches_sysctls);
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 9813b5b9c093..387f579a6c18 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3803,12 +3803,6 @@ static inline int in_gate_area(struct mm_struct *mm, unsigned long addr)
 
 extern bool process_shares_mm(struct task_struct *p, struct mm_struct *mm);
 
-#ifdef CONFIG_SYSCTL
-extern int sysctl_drop_caches;
-int drop_caches_sysctl_handler(const struct ctl_table *, int, void *, size_t *,
-		loff_t *);
-#endif
-
 void drop_slab(void);
 
 #ifndef CONFIG_MMU
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index c5527f59e3f2..7fb77cbcc24d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2014,15 +2014,6 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-	{
-		.procname	= "drop_caches",
-		.data		= &sysctl_drop_caches,
-		.maxlen		= sizeof(int),
-		.mode		= 0200,
-		.proc_handler	= drop_caches_sysctl_handler,
-		.extra1		= SYSCTL_ONE,
-		.extra2		= SYSCTL_FOUR,
-	},
 	{
 		.procname	= "vfs_cache_pressure",
 		.data		= &sysctl_vfs_cache_pressure,
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 11/15] sunrpc: simplify rpcauth_cache_shrink_count()
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (25 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 10/15] fs: drop_caches: move sysctl to fs/drop_caches.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 12/15] fs: dcache: move the sysctl to fs/dcache.c Kaixiong Yu
                   ` (4 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

It is inappropriate to use sysctl_vfs_cache_pressure here.
The sysctl is documented as: This percentage value controls
the tendency of the kernel to reclaim the memory which is used
for caching of directory and inode objects.

So, simplify result of rpcauth_cache_shrink_count() to
"return number_cred_unused;".

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Acked-by: Anna Schumaker <anna.schumaker@oracle.com>
Acked-by: Jeff Layton <jlayton@kernel.org>
---
v4:
 - Simplify result of rpcauth_cache_shrink_count().
---
---
 net/sunrpc/auth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index 04534ea537c8..5a827afd8e3b 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -489,7 +489,7 @@ static unsigned long
 rpcauth_cache_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
 
 {
-	return number_cred_unused * sysctl_vfs_cache_pressure / 100;
+	return number_cred_unused;
 }
 
 static void
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 12/15] fs: dcache: move the sysctl to fs/dcache.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (26 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 11/15] sunrpc: simplify rpcauth_cache_shrink_count() Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 13/15] x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c Kaixiong Yu
                   ` (3 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

The sysctl_vfs_cache_pressure belongs to fs/dcache.c, move it to
fs/dcache.c from kernel/sysctl.c. As a part of fs/dcache.c cleaning,
sysctl_vfs_cache_pressure is changed to a static variable, and change
the inline-type function vfs_pressure_ratio() to out-of-inline type,
export vfs_pressure_ratio() with EXPORT_SYMBOL_GPL to be used by other
files. Move the unneeded include(linux/dcache.h).

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christian Brauner <brauner@kernel.org>
---
v4:
 - const qualify struct ctl_table vm_dcache_sysctls
v3:
 - change the title
v2:
 - update the changelog to call out changing the inline-type function
   vfs_pressure_ratio() to out-of-inline type
---
---
 fs/dcache.c            | 21 +++++++++++++++++++--
 include/linux/dcache.h |  7 +------
 kernel/sysctl.c        |  9 ---------
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index b4d5e9e1e43d..77ca6e9bb71e 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -73,8 +73,13 @@
  * If no ancestor relationship:
  * arbitrary, since it's serialized on rename_lock
  */
-int sysctl_vfs_cache_pressure __read_mostly = 100;
-EXPORT_SYMBOL_GPL(sysctl_vfs_cache_pressure);
+static int sysctl_vfs_cache_pressure __read_mostly = 100;
+
+unsigned long vfs_pressure_ratio(unsigned long val)
+{
+	return mult_frac(val, sysctl_vfs_cache_pressure, 100);
+}
+EXPORT_SYMBOL_GPL(vfs_pressure_ratio);
 
 __cacheline_aligned_in_smp DEFINE_SEQLOCK(rename_lock);
 
@@ -211,8 +216,20 @@ static struct ctl_table fs_dcache_sysctls[] = {
 	},
 };
 
+static const struct ctl_table vm_dcache_sysctls[] = {
+	{
+		.procname	= "vfs_cache_pressure",
+		.data		= &sysctl_vfs_cache_pressure,
+		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+	},
+};
+
 static int __init init_fs_dcache_sysctls(void)
 {
+	register_sysctl_init("vm", vm_dcache_sysctls);
 	register_sysctl_init("fs", fs_dcache_sysctls);
 	return 0;
 }
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index bff956f7b2b9..c81c2e9e13df 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -508,12 +508,7 @@ static inline int simple_positive(const struct dentry *dentry)
 	return d_really_is_positive(dentry) && !d_unhashed(dentry);
 }
 
-extern int sysctl_vfs_cache_pressure;
-
-static inline unsigned long vfs_pressure_ratio(unsigned long val)
-{
-	return mult_frac(val, sysctl_vfs_cache_pressure, 100);
-}
+unsigned long vfs_pressure_ratio(unsigned long val);
 
 /**
  * d_inode - Get the actual inode of this dentry
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7fb77cbcc24d..860dea8f1587 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -46,7 +46,6 @@
 #include <linux/key.h>
 #include <linux/times.h>
 #include <linux/limits.h>
-#include <linux/dcache.h>
 #include <linux/syscalls.h>
 #include <linux/nfs_fs.h>
 #include <linux/acpi.h>
@@ -2014,14 +2013,6 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-	{
-		.procname	= "vfs_cache_pressure",
-		.data		= &sysctl_vfs_cache_pressure,
-		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
 	{
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 13/15] x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (27 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 12/15] fs: dcache: move the sysctl to fs/dcache.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 14/15] sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c Kaixiong Yu
                   ` (2 subsequent siblings)
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

When CONFIG_X86_32 is defined and CONFIG_UML is not defined,
vdso_enabled belongs to arch/x86/entry/vdso/vdso32-setup.c.
So, move it into its own file.

Before this patch, vdso_enabled was allowed to be set to
a value exceeding 1 on x86_32 architecture. After this patch is
applied, vdso_enabled is not permitted to set the value more than 1.
It does not matter, because according to the function load_vdso32(),
only vdso_enabled is set to 1, VDSO would be enabled. Other values
all mean "disabled". The same limitation could be seen in the
function vdso32_setup().

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vdso_table
---
---
 arch/x86/entry/vdso/vdso32-setup.c | 16 +++++++++++-----
 kernel/sysctl.c                    |  8 +-------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/x86/entry/vdso/vdso32-setup.c b/arch/x86/entry/vdso/vdso32-setup.c
index 76e4e74f35b5..f71625f99bf9 100644
--- a/arch/x86/entry/vdso/vdso32-setup.c
+++ b/arch/x86/entry/vdso/vdso32-setup.c
@@ -51,15 +51,17 @@ __setup("vdso32=", vdso32_setup);
 __setup_param("vdso=", vdso_setup, vdso32_setup, 0);
 #endif
 
-#ifdef CONFIG_X86_64
 
 #ifdef CONFIG_SYSCTL
-/* Register vsyscall32 into the ABI table */
 #include <linux/sysctl.h>
 
-static struct ctl_table abi_table2[] = {
+static const struct ctl_table vdso_table[] = {
 	{
+#ifdef CONFIG_X86_64
 		.procname	= "vsyscall32",
+#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
+		.procname	= "vdso_enabled",
+#endif
 		.data		= &vdso32_enabled,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
@@ -71,10 +73,14 @@ static struct ctl_table abi_table2[] = {
 
 static __init int ia32_binfmt_init(void)
 {
-	register_sysctl("abi", abi_table2);
+#ifdef CONFIG_X86_64
+	/* Register vsyscall32 into the ABI table */
+	register_sysctl("abi", vdso_table);
+#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
+	register_sysctl_init("vm", vdso_table);
+#endif
 	return 0;
 }
 __initcall(ia32_binfmt_init);
 #endif /* CONFIG_SYSCTL */
 
-#endif	/* CONFIG_X86_64 */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 860dea8f1587..7ff07b7560b4 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2013,17 +2013,11 @@ static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
-   (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
+#if defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)
 	{
 		.procname	= "vdso_enabled",
-#ifdef CONFIG_X86_32
-		.data		= &vdso32_enabled,
-		.maxlen		= sizeof(vdso32_enabled),
-#else
 		.data		= &vdso_enabled,
 		.maxlen		= sizeof(vdso_enabled),
-#endif
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 		.extra1		= SYSCTL_ZERO,
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 14/15] sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (28 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 13/15] x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-23 14:15 ` [PATCH v4 -next 15/15] sysctl: remove unneeded include Kaixiong Yu
  2024-12-28 12:15 ` [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Joel Granados
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

When CONFIG_SUPERH and CONFIG_VSYSCALL are defined,
vdso_enabled belongs to arch/sh/kernel/vsyscall/vsyscall.c.
So, move it into its own file. After this patch is applied,
all sysctls of vm_table would be moved. So, delete vm_table.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vdso_table
v3:
 - change the title
---
---
 arch/sh/kernel/vsyscall/vsyscall.c | 14 ++++++++++++++
 kernel/sysctl.c                    | 14 --------------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
index add35c51e017..898132f34e6a 100644
--- a/arch/sh/kernel/vsyscall/vsyscall.c
+++ b/arch/sh/kernel/vsyscall/vsyscall.c
@@ -14,6 +14,7 @@
 #include <linux/module.h>
 #include <linux/elf.h>
 #include <linux/sched.h>
+#include <linux/sysctl.h>
 #include <linux/err.h>
 
 /*
@@ -30,6 +31,17 @@ static int __init vdso_setup(char *s)
 }
 __setup("vdso=", vdso_setup);
 
+static const struct ctl_table vdso_table[] = {
+	{
+		.procname	= "vdso_enabled",
+		.data		= &vdso_enabled,
+		.maxlen		= sizeof(vdso_enabled),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+		.extra1		= SYSCTL_ZERO,
+	},
+};
+
 /*
  * These symbols are defined by vsyscall.o to mark the bounds
  * of the ELF DSO images included therein.
@@ -55,6 +67,8 @@ int __init vsyscall_init(void)
 	       &vsyscall_trapa_start,
 	       &vsyscall_trapa_end - &vsyscall_trapa_start);
 
+	register_sysctl_init("vm", vdso_table);
+
 	return 0;
 }
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7ff07b7560b4..cebd0ef5d19d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2012,23 +2012,9 @@ static struct ctl_table kern_table[] = {
 #endif
 };
 
-static struct ctl_table vm_table[] = {
-#if defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)
-	{
-		.procname	= "vdso_enabled",
-		.data		= &vdso_enabled,
-		.maxlen		= sizeof(vdso_enabled),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
-};
-
 int __init sysctl_init_bases(void)
 {
 	register_sysctl_init("kernel", kern_table);
-	register_sysctl_init("vm", vm_table);
 
 	return 0;
 }
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 15/15] sysctl: remove unneeded include
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (29 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 14/15] sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c Kaixiong Yu
@ 2024-12-23 14:15 ` Kaixiong Yu
  2024-12-28 12:15 ` [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Joel Granados
  31 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-23 14:15 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

Removing unneeded mm includes in kernel/sysctl.c.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
 kernel/sysctl.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index cebd0ef5d19d..aece984bee19 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -20,8 +20,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
 #include <linux/sysctl.h>
 #include <linux/bitmap.h>
 #include <linux/signal.h>
@@ -30,7 +28,6 @@
 #include <linux/proc_fs.h>
 #include <linux/security.h>
 #include <linux/ctype.h>
-#include <linux/kmemleak.h>
 #include <linux/filter.h>
 #include <linux/fs.h>
 #include <linux/init.h>
@@ -41,7 +38,6 @@
 #include <linux/highuid.h>
 #include <linux/writeback.h>
 #include <linux/ratelimit.h>
-#include <linux/hugetlb.h>
 #include <linux/initrd.h>
 #include <linux/key.h>
 #include <linux/times.h>
@@ -52,13 +48,11 @@
 #include <linux/reboot.h>
 #include <linux/ftrace.h>
 #include <linux/perf_event.h>
-#include <linux/oom.h>
 #include <linux/kmod.h>
 #include <linux/capability.h>
 #include <linux/binfmts.h>
 #include <linux/sched/sysctl.h>
 #include <linux/mount.h>
-#include <linux/userfaultfd_k.h>
 #include <linux/pid.h>
 
 #include "../lib/kstrtox.h"
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files
  2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
                   ` (30 preceding siblings ...)
  2024-12-23 14:15 ` [PATCH v4 -next 15/15] sysctl: remove unneeded include Kaixiong Yu
@ 2024-12-28 12:15 ` Joel Granados
  2024-12-28 13:40   ` yukaixiong
  31 siblings, 1 reply; 41+ messages in thread
From: Joel Granados @ 2024-12-28 12:15 UTC (permalink / raw)
  To: Kaixiong Yu
  Cc: akpm, mcgrof, ysato, dalias, glaubitz, luto, tglx, mingo, bp,
	dave.hansen, hpa, viro, brauner, jack, kees, j.granados, willy,
	Liam.Howlett, vbabka, lorenzo.stoakes, trondmy, anna,
	chuck.lever, jlayton, neilb, okorniev, Dai.Ngo, tom, davem,
	edumazet, kuba, pabeni, paul, jmorris, linux-sh, linux-kernel,
	linux-fsdevel, linux-mm, linux-nfs, netdev,
	linux-security-module, dhowells, haifeng.xu, baolin.wang,
	shikemeng, dchinner, bfoster, souravpanda, hannes, rientjes,
	pasha.tatashin, david, ryan.roberts, ying.huang, yang, zev,
	serge, vegard.nossum, wangkefeng.wang

On Mon, Dec 23, 2024 at 10:15:19PM +0800, Kaixiong Yu wrote:
> This patch series moves sysctls of vm_table in kernel/sysctl.c to
> places where they actually belong, and do some related code clean-ups.
> After this patch series, all sysctls in vm_table have been moved into its
> own files, meanwhile, delete vm_table.
> 
> All the modifications of this patch series base on
> linux-next(tags/next-20241219). To test this patch series, the code was
> compiled with both the CONFIG_SYSCTL enabled and disabled on arm64 and
> x86_64 architectures. After this patch series is applied, all files
> under /proc/sys/vm can be read or written normally.
> 
> Changes in v4:
>  - change all "static struct ctl_table" type into
>    "static const struct ctl_table" type in patch1~10,12,13,14
>  - simplify result of rpcauth_cache_shrink_count() in patch11
> 
> Changes in v3:
>  - change patch1~10, patch14 title suggested by Joel Granados
>  - change sysctl_stat_interval to static type in patch1
>  - add acked-by from Paul Moore in patch7
>  - change dirtytime_expire_interval to static type in patch9
>  - add acked-by from Anna Schumaker in patch11
> 
> Changes in v2:
>  - fix sysctl_max_map_count undeclared issue in mm/nommu.c for patch6
>  - update changelog for patch7/12, suggested by Kees/Paul
>  - fix patch8, sorry for wrong changes and forget to built with NOMMU
>  - add reviewed-by from Kees except patch8 since patch8 is wrong in v1
>  - add reviewed-by from Jan Kara, Christian Brauner in patch12
> 
> Kaixiong Yu (15):
>   mm: vmstat: move sysctls to mm/vmstat.c
>   mm: filemap: move sysctl to mm/filemap.c
>   mm: swap: move sysctl to mm/swap.c
>   mm: vmscan: move vmscan sysctls to mm/vmscan.c
>   mm: util: move sysctls to mm/util.c
>   mm: mmap: move sysctl to mm/mmap.c
>   security: min_addr: move sysctl to security/min_addr.c
>   mm: nommu: move sysctl to mm/nommu.c
>   fs: fs-writeback: move sysctl to fs/fs-writeback.c
>   fs: drop_caches: move sysctl to fs/drop_caches.c
>   sunrpc: simplify rpcauth_cache_shrink_count()
>   fs: dcache: move the sysctl to fs/dcache.c
>   x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c
>   sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c
>   sysctl: remove unneeded include
This patchset looks strange. There seems to be 15 patches, but there are
30 e-mails in the thread? You can also see this when you look at it in
lore [1]. And they are different repeated e-mails (mutt does not
de-duplicate them). Also `b4 shazam ...` does not work. What happened?
Did you send it twice with the same mail ID? Am I the only one seeing
this?

I would suggest the following (hopefully you are using b4):
1. Check to see how things will be sent with b4. `b4 send --resend -o OUTPUT_DIR`
   If you see 30 emails in that dir from your patchset then something is
   still wrong.
2. After you make sure that everything is in order. Do the resend
   without bumping the version up (leave it at version 4)

Best

[1] : https://lore.kernel.org/all/20241223141550.638616-1-yukaixiong@huawei.com/

> 
>  arch/sh/kernel/vsyscall/vsyscall.c |  14 ++
>  arch/x86/entry/vdso/vdso32-setup.c |  16 ++-
>  fs/dcache.c                        |  21 ++-
>  fs/drop_caches.c                   |  23 ++-
>  fs/fs-writeback.c                  |  30 ++--
>  include/linux/dcache.h             |   7 +-
>  include/linux/mm.h                 |  23 ---
>  include/linux/mman.h               |   2 -
>  include/linux/swap.h               |   9 --
>  include/linux/vmstat.h             |  11 --
>  include/linux/writeback.h          |   4 -
>  kernel/sysctl.c                    | 221 -----------------------------
>  mm/filemap.c                       |  18 ++-
>  mm/internal.h                      |  10 ++
>  mm/mmap.c                          |  54 +++++++
>  mm/nommu.c                         |  15 +-
>  mm/swap.c                          |  16 ++-
>  mm/swap.h                          |   1 +
>  mm/util.c                          |  67 +++++++--
>  mm/vmscan.c                        |  23 +++
>  mm/vmstat.c                        |  44 +++++-
>  net/sunrpc/auth.c                  |   2 +-
>  security/min_addr.c                |  11 ++
>  23 files changed, 330 insertions(+), 312 deletions(-)
> 
> -- 
> 2.34.1
> 

-- 

Joel Granados


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files
  2024-12-28 12:15 ` [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Joel Granados
@ 2024-12-28 13:40   ` yukaixiong
  2025-01-06 11:22     ` Joel Granados
  0 siblings, 1 reply; 41+ messages in thread
From: yukaixiong @ 2024-12-28 13:40 UTC (permalink / raw)
  To: Joel Granados
  Cc: akpm, mcgrof, ysato, dalias, glaubitz, luto, tglx, mingo, bp,
	dave.hansen, hpa, viro, brauner, jack, kees, j.granados, willy,
	Liam.Howlett, vbabka, lorenzo.stoakes, trondmy, anna,
	chuck.lever, jlayton, neilb, okorniev, Dai.Ngo, tom, davem,
	edumazet, kuba, pabeni, paul, jmorris, linux-sh, linux-kernel,
	linux-fsdevel, linux-mm, linux-nfs, netdev,
	linux-security-module, dhowells, haifeng.xu, baolin.wang,
	shikemeng, dchinner, bfoster, souravpanda, hannes, rientjes,
	pasha.tatashin, david, ryan.roberts, ying.huang, yang, zev,
	serge, vegard.nossum, wangkefeng.wang



On 2024/12/28 20:15, Joel Granados wrote:
> On Mon, Dec 23, 2024 at 10:15:19PM +0800, Kaixiong Yu wrote:
>> This patch series moves sysctls of vm_table in kernel/sysctl.c to
>> places where they actually belong, and do some related code clean-ups.
>> After this patch series, all sysctls in vm_table have been moved into its
>> own files, meanwhile, delete vm_table.
>>
>> All the modifications of this patch series base on
>> linux-next(tags/next-20241219). To test this patch series, the code was
>> compiled with both the CONFIG_SYSCTL enabled and disabled on arm64 and
>> x86_64 architectures. After this patch series is applied, all files
>> under /proc/sys/vm can be read or written normally.
>>
>> Changes in v4:
>>   - change all "static struct ctl_table" type into
>>     "static const struct ctl_table" type in patch1~10,12,13,14
>>   - simplify result of rpcauth_cache_shrink_count() in patch11
>>
>> Changes in v3:
>>   - change patch1~10, patch14 title suggested by Joel Granados
>>   - change sysctl_stat_interval to static type in patch1
>>   - add acked-by from Paul Moore in patch7
>>   - change dirtytime_expire_interval to static type in patch9
>>   - add acked-by from Anna Schumaker in patch11
>>
>> Changes in v2:
>>   - fix sysctl_max_map_count undeclared issue in mm/nommu.c for patch6
>>   - update changelog for patch7/12, suggested by Kees/Paul
>>   - fix patch8, sorry for wrong changes and forget to built with NOMMU
>>   - add reviewed-by from Kees except patch8 since patch8 is wrong in v1
>>   - add reviewed-by from Jan Kara, Christian Brauner in patch12
>>
>> Kaixiong Yu (15):
>>    mm: vmstat: move sysctls to mm/vmstat.c
>>    mm: filemap: move sysctl to mm/filemap.c
>>    mm: swap: move sysctl to mm/swap.c
>>    mm: vmscan: move vmscan sysctls to mm/vmscan.c
>>    mm: util: move sysctls to mm/util.c
>>    mm: mmap: move sysctl to mm/mmap.c
>>    security: min_addr: move sysctl to security/min_addr.c
>>    mm: nommu: move sysctl to mm/nommu.c
>>    fs: fs-writeback: move sysctl to fs/fs-writeback.c
>>    fs: drop_caches: move sysctl to fs/drop_caches.c
>>    sunrpc: simplify rpcauth_cache_shrink_count()
>>    fs: dcache: move the sysctl to fs/dcache.c
>>    x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c
>>    sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c
>>    sysctl: remove unneeded include
> This patchset looks strange. There seems to be 15 patches, but there are
> 30 e-mails in the thread? You can also see this when you look at it in
> lore [1]. And they are different repeated e-mails (mutt does not
> de-duplicate them). Also `b4 shazam ...` does not work. What happened?
> Did you send it twice with the same mail ID? Am I the only one seeing
> this?
>
> I would suggest the following (hopefully you are using b4):
> 1. Check to see how things will be sent with b4. `b4 send --resend -o OUTPUT_DIR`
>     If you see 30 emails in that dir from your patchset then something is
>     still wrong.
> 2. After you make sure that everything is in order. Do the resend
>     without bumping the version up (leave it at version 4)
>
> Best
>
> [1] : https://lore.kernel.org/all/20241223141550.638616-1-yukaixiong@huawei.com/

I'm very sorry, due to my mistake, 15 patches were sent twice.

Sorry, again! I will resend these 15 patches, and leave it at version 4
>>   arch/sh/kernel/vsyscall/vsyscall.c |  14 ++
>>   arch/x86/entry/vdso/vdso32-setup.c |  16 ++-
>>   fs/dcache.c                        |  21 ++-
>>   fs/drop_caches.c                   |  23 ++-
>>   fs/fs-writeback.c                  |  30 ++--
>>   include/linux/dcache.h             |   7 +-
>>   include/linux/mm.h                 |  23 ---
>>   include/linux/mman.h               |   2 -
>>   include/linux/swap.h               |   9 --
>>   include/linux/vmstat.h             |  11 --
>>   include/linux/writeback.h          |   4 -
>>   kernel/sysctl.c                    | 221 -----------------------------
>>   mm/filemap.c                       |  18 ++-
>>   mm/internal.h                      |  10 ++
>>   mm/mmap.c                          |  54 +++++++
>>   mm/nommu.c                         |  15 +-
>>   mm/swap.c                          |  16 ++-
>>   mm/swap.h                          |   1 +
>>   mm/util.c                          |  67 +++++++--
>>   mm/vmscan.c                        |  23 +++
>>   mm/vmstat.c                        |  44 +++++-
>>   net/sunrpc/auth.c                  |   2 +-
>>   security/min_addr.c                |  11 ++
>>   23 files changed, 330 insertions(+), 312 deletions(-)
>>
>> -- 
>> 2.34.1
>>



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c
  2024-12-23 14:15 ` [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Kaixiong Yu
@ 2025-01-02 14:08   ` Lorenzo Stoakes
  2025-01-09  2:20     ` yukaixiong
  0 siblings, 1 reply; 41+ messages in thread
From: Lorenzo Stoakes @ 2025-01-02 14:08 UTC (permalink / raw)
  To: Kaixiong Yu
  Cc: akpm, mcgrof, ysato, dalias, glaubitz, luto, tglx, mingo, bp,
	dave.hansen, hpa, viro, brauner, jack, kees, j.granados, willy,
	Liam.Howlett, vbabka, trondmy, anna, chuck.lever, jlayton, neilb,
	okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni, paul,
	jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

On Mon, Dec 23, 2024 at 10:15:25PM +0800, Kaixiong Yu wrote:
> This moves all mmap related sysctls to mm/mmap.c, as part of the
> kernel/sysctl.c cleaning, also move the variable declaration from
> kernel/sysctl.c into mm/mmap.c.
>
> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
> Reviewed-by: Kees Cook <kees@kernel.org>

Looks good to me, thanks!

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
> v4:
>  - const qualify struct ctl_table mmap_table
> v3:
>  - change the title
> v2:
>  - fix sysctl_max_map_count undeclared issue in mm/nommu.c
> ---
> ---
>  kernel/sysctl.c | 50 +--------------------------------------------
>  mm/mmap.c       | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 55 insertions(+), 49 deletions(-)
>
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index aea3482106e0..9c245898f535 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -127,12 +127,6 @@ enum sysctl_writes_mode {
>
>  static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
>  #endif /* CONFIG_PROC_SYSCTL */
> -
> -#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
> -    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
> -int sysctl_legacy_va_layout;
> -#endif
> -
>  #endif /* CONFIG_SYSCTL */
>
>  /*
> @@ -2037,16 +2031,7 @@ static struct ctl_table vm_table[] = {
>  		.extra1		= SYSCTL_ONE,
>  		.extra2		= SYSCTL_FOUR,
>  	},
> -#ifdef CONFIG_MMU
> -	{
> -		.procname	= "max_map_count",
> -		.data		= &sysctl_max_map_count,
> -		.maxlen		= sizeof(sysctl_max_map_count),
> -		.mode		= 0644,
> -		.proc_handler	= proc_dointvec_minmax,
> -		.extra1		= SYSCTL_ZERO,
> -	},
> -#else
> +#ifndef CONFIG_MMU
>  	{
>  		.procname	= "nr_trim_pages",
>  		.data		= &sysctl_nr_trim_pages,
> @@ -2064,17 +2049,6 @@ static struct ctl_table vm_table[] = {
>  		.proc_handler	= proc_dointvec_minmax,
>  		.extra1		= SYSCTL_ZERO,
>  	},

Nitty, but  this bit belongs in mm/nommu.c?

> -#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
> -    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
> -	{
> -		.procname	= "legacy_va_layout",
> -		.data		= &sysctl_legacy_va_layout,
> -		.maxlen		= sizeof(sysctl_legacy_va_layout),
> -		.mode		= 0644,
> -		.proc_handler	= proc_dointvec_minmax,
> -		.extra1		= SYSCTL_ZERO,
> -	},
> -#endif
>  #ifdef CONFIG_MMU
>  	{
>  		.procname	= "mmap_min_addr",
> @@ -2100,28 +2074,6 @@ static struct ctl_table vm_table[] = {
>  		.extra1		= SYSCTL_ZERO,
>  	},
>  #endif
> -#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
> -	{
> -		.procname	= "mmap_rnd_bits",
> -		.data		= &mmap_rnd_bits,
> -		.maxlen		= sizeof(mmap_rnd_bits),
> -		.mode		= 0600,
> -		.proc_handler	= proc_dointvec_minmax,
> -		.extra1		= (void *)&mmap_rnd_bits_min,
> -		.extra2		= (void *)&mmap_rnd_bits_max,
> -	},
> -#endif
> -#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
> -	{
> -		.procname	= "mmap_rnd_compat_bits",
> -		.data		= &mmap_rnd_compat_bits,
> -		.maxlen		= sizeof(mmap_rnd_compat_bits),
> -		.mode		= 0600,
> -		.proc_handler	= proc_dointvec_minmax,
> -		.extra1		= (void *)&mmap_rnd_compat_bits_min,
> -		.extra2		= (void *)&mmap_rnd_compat_bits_max,
> -	},
> -#endif
>  };
>
>  int __init sysctl_init_bases(void)
> diff --git a/mm/mmap.c b/mm/mmap.c
> index aef835984b1c..cc579aafd7ba 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1603,6 +1603,57 @@ struct vm_area_struct *_install_special_mapping(
>  					&special_mapping_vmops);
>  }
>
> +#ifdef CONFIG_SYSCTL
> +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
> +		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
> +int sysctl_legacy_va_layout;
> +#endif
> +
> +static const struct ctl_table mmap_table[] = {
> +		{
> +				.procname       = "max_map_count",
> +				.data           = &sysctl_max_map_count,
> +				.maxlen         = sizeof(sysctl_max_map_count),
> +				.mode           = 0644,
> +				.proc_handler   = proc_dointvec_minmax,
> +				.extra1         = SYSCTL_ZERO,
> +		},
> +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
> +		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
> +		{
> +				.procname       = "legacy_va_layout",
> +				.data           = &sysctl_legacy_va_layout,
> +				.maxlen         = sizeof(sysctl_legacy_va_layout),
> +				.mode           = 0644,
> +				.proc_handler   = proc_dointvec_minmax,
> +				.extra1         = SYSCTL_ZERO,
> +		},
> +#endif
> +#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
> +		{
> +				.procname       = "mmap_rnd_bits",
> +				.data           = &mmap_rnd_bits,
> +				.maxlen         = sizeof(mmap_rnd_bits),
> +				.mode           = 0600,
> +				.proc_handler   = proc_dointvec_minmax,
> +				.extra1         = (void *)&mmap_rnd_bits_min,
> +				.extra2         = (void *)&mmap_rnd_bits_max,
> +		},
> +#endif
> +#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
> +		{
> +				.procname       = "mmap_rnd_compat_bits",
> +				.data           = &mmap_rnd_compat_bits,
> +				.maxlen         = sizeof(mmap_rnd_compat_bits),
> +				.mode           = 0600,
> +				.proc_handler   = proc_dointvec_minmax,
> +				.extra1         = (void *)&mmap_rnd_compat_bits_min,
> +				.extra2         = (void *)&mmap_rnd_compat_bits_max,
> +		},
> +#endif
> +};
> +#endif /* CONFIG_SYSCTL */
> +
>  /*
>   * initialise the percpu counter for VM
>   */
> @@ -1612,6 +1663,9 @@ void __init mmap_init(void)
>
>  	ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
>  	VM_BUG_ON(ret);
> +#ifdef CONFIG_SYSCTL
> +	register_sysctl_init("vm", mmap_table);
> +#endif
>  }
>
>  /*
> --
> 2.34.1
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c
  2024-12-23 14:15 ` [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c Kaixiong Yu
@ 2025-01-02 14:09   ` Lorenzo Stoakes
  2025-01-09  2:26     ` yukaixiong
  0 siblings, 1 reply; 41+ messages in thread
From: Lorenzo Stoakes @ 2025-01-02 14:09 UTC (permalink / raw)
  To: Kaixiong Yu
  Cc: akpm, mcgrof, ysato, dalias, glaubitz, luto, tglx, mingo, bp,
	dave.hansen, hpa, viro, brauner, jack, kees, j.granados, willy,
	Liam.Howlett, vbabka, trondmy, anna, chuck.lever, jlayton, neilb,
	okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni, paul,
	jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

On Mon, Dec 23, 2024 at 10:15:27PM +0800, Kaixiong Yu wrote:
> The sysctl_nr_trim_pages belongs to nommu.c, move it to mm/nommu.c
> from /kernel/sysctl.c. And remove the useless extern variable declaration
> from include/linux/mm.h
>
> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>

Looks good to me,

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
> v4:
>  - const qualify struct ctl_table nommu_table
> v3:
>  - change the title
> v2:
>  - fix the build error: expected ';' after top level declarator
>  - fix the build error: call to undeclared function 'register_syscall_init',
>    use 'register_sysctl_init' to replace it.
> ---
> ---
>  include/linux/mm.h |  2 --
>  kernel/sysctl.c    | 10 ----------
>  mm/nommu.c         | 15 ++++++++++++++-
>  3 files changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index b3b87c1dc1e4..9813b5b9c093 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -4080,8 +4080,6 @@ unsigned long wp_shared_mapping_range(struct address_space *mapping,
>  				      pgoff_t first_index, pgoff_t nr);
>  #endif
>
> -extern int sysctl_nr_trim_pages;
> -
>  #ifdef CONFIG_PRINTK
>  void mem_dump_obj(void *object);
>  #else
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 62a58e417c40..97f9abffff0f 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -2031,16 +2031,6 @@ static struct ctl_table vm_table[] = {
>  		.extra1		= SYSCTL_ONE,
>  		.extra2		= SYSCTL_FOUR,
>  	},
> -#ifndef CONFIG_MMU
> -	{
> -		.procname	= "nr_trim_pages",
> -		.data		= &sysctl_nr_trim_pages,
> -		.maxlen		= sizeof(sysctl_nr_trim_pages),
> -		.mode		= 0644,
> -		.proc_handler	= proc_dointvec_minmax,
> -		.extra1		= SYSCTL_ZERO,
> -	},
> -#endif

Of course later on in the series you do what I asked in a previous commit :P Nice.

>  	{
>  		.procname	= "vfs_cache_pressure",
>  		.data		= &sysctl_vfs_cache_pressure,
> diff --git a/mm/nommu.c b/mm/nommu.c
> index baa79abdaf03..3c32f8b1eb54 100644
> --- a/mm/nommu.c
> +++ b/mm/nommu.c
> @@ -48,7 +48,6 @@ struct page *mem_map;
>  unsigned long max_mapnr;
>  EXPORT_SYMBOL(max_mapnr);
>  unsigned long highest_memmap_pfn;
> -int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
>  int heap_stack_gap = 0;
>
>  atomic_long_t mmap_pages_allocated;
> @@ -392,6 +391,19 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
>  	return mm->brk = brk;
>  }
>
> +static int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
> +
> +static const struct ctl_table nommu_table[] = {
> +	{
> +		.procname	= "nr_trim_pages",
> +		.data		= &sysctl_nr_trim_pages,
> +		.maxlen		= sizeof(sysctl_nr_trim_pages),
> +		.mode		= 0644,
> +		.proc_handler	= proc_dointvec_minmax,
> +		.extra1		= SYSCTL_ZERO,
> +	},
> +};
> +
>  /*
>   * initialise the percpu counter for VM and region record slabs
>   */
> @@ -402,6 +414,7 @@ void __init mmap_init(void)
>  	ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
>  	VM_BUG_ON(ret);
>  	vm_region_jar = KMEM_CACHE(vm_region, SLAB_PANIC|SLAB_ACCOUNT);
> +	register_sysctl_init("vm", nommu_table);
>  }
>
>  /*
> --
> 2.34.1
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Re: [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files
  2024-12-28 13:40   ` yukaixiong
@ 2025-01-06 11:22     ` Joel Granados
  2025-01-09  2:35       ` yukaixiong
  0 siblings, 1 reply; 41+ messages in thread
From: Joel Granados @ 2025-01-06 11:22 UTC (permalink / raw)
  To: yukaixiong
  Cc: akpm, mcgrof, ysato, dalias, glaubitz, luto, tglx, mingo, bp,
	dave.hansen, hpa, viro, brauner, jack, kees, j.granados, willy,
	Liam.Howlett, vbabka, lorenzo.stoakes, trondmy, anna,
	chuck.lever, jlayton, neilb, okorniev, Dai.Ngo, tom, davem,
	edumazet, kuba, pabeni, paul, jmorris, linux-sh, linux-kernel,
	linux-fsdevel, linux-mm, linux-nfs, netdev,
	linux-security-module, dhowells, haifeng.xu, baolin.wang,
	shikemeng, dchinner, bfoster, souravpanda, hannes, rientjes,
	pasha.tatashin, david, ryan.roberts, ying.huang, yang, zev,
	serge, vegard.nossum, wangkefeng.wang

On Sat, Dec 28, 2024 at 09:40:50PM +0800, yukaixiong wrote:
> 
> 
> On 2024/12/28 20:15, Joel Granados wrote:
> > On Mon, Dec 23, 2024 at 10:15:19PM +0800, Kaixiong Yu wrote:
> >> This patch series moves sysctls of vm_table in kernel/sysctl.c to
> >> places where they actually belong, and do some related code clean-ups.
> >> After this patch series, all sysctls in vm_table have been moved into its
> >> own files, meanwhile, delete vm_table.
...
> >>    sysctl: remove unneeded include
> > This patchset looks strange. There seems to be 15 patches, but there are
> > 30 e-mails in the thread? You can also see this when you look at it in
> > lore [1]. And they are different repeated e-mails (mutt does not
> > de-duplicate them). Also `b4 shazam ...` does not work. What happened?
> > Did you send it twice with the same mail ID? Am I the only one seeing
> > this?
> >
> > I would suggest the following (hopefully you are using b4):
> > 1. Check to see how things will be sent with b4. `b4 send --resend -o OUTPUT_DIR`
> >     If you see 30 emails in that dir from your patchset then something is
> >     still wrong.
> > 2. After you make sure that everything is in order. Do the resend
> >     without bumping the version up (leave it at version 4)
> >
> > Best
> >
> > [1] : https://lore.kernel.org/all/20241223141550.638616-1-yukaixiong@huawei.com/
> 
> I'm very sorry, due to my mistake, 15 patches were sent twice.
No worries. I saw that you have re-sent the patchset and it seems that
this time there is only 15 mails. I see that you are only using my
j.granados@samsung.com ID; can you please add my kernel.org
(joel.granados@kernel.org) mail to the future mails that you send (no
need to re-send v4).

Thx

...

-- 

Joel Granados


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c
  2025-01-02 14:08   ` Lorenzo Stoakes
@ 2025-01-09  2:20     ` yukaixiong
  0 siblings, 0 replies; 41+ messages in thread
From: yukaixiong @ 2025-01-09  2:20 UTC (permalink / raw)
  To: Lorenzo Stoakes
  Cc: akpm, mcgrof, ysato, dalias, glaubitz, luto, tglx, mingo, bp,
	dave.hansen, hpa, viro, brauner, jack, kees, j.granados, willy,
	Liam.Howlett, vbabka, trondmy, anna, chuck.lever, jlayton, neilb,
	okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni, paul,
	jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang



On 2025/1/2 22:08, Lorenzo Stoakes wrote:
> On Mon, Dec 23, 2024 at 10:15:25PM +0800, Kaixiong Yu wrote:
>> This moves all mmap related sysctls to mm/mmap.c, as part of the
>> kernel/sysctl.c cleaning, also move the variable declaration from
>> kernel/sysctl.c into mm/mmap.c.
>>
>> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
>> Reviewed-by: Kees Cook <kees@kernel.org>
> Looks good to me, thanks!
>
> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

Thanks for your review!

Best ...
>> ---
>> v4:
>>   - const qualify struct ctl_table mmap_table
>> v3:
>>   - change the title
>> v2:
>>   - fix sysctl_max_map_count undeclared issue in mm/nommu.c
>> ---
>> ---
>>   kernel/sysctl.c | 50 +--------------------------------------------
>>   mm/mmap.c       | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
>>   2 files changed, 55 insertions(+), 49 deletions(-)
>>
>> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
>> index aea3482106e0..9c245898f535 100644
>> --- a/kernel/sysctl.c
>> +++ b/kernel/sysctl.c
>> @@ -127,12 +127,6 @@ enum sysctl_writes_mode {
>>
>>   static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
>>   #endif /* CONFIG_PROC_SYSCTL */
>> -
>> -#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
>> -    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
>> -int sysctl_legacy_va_layout;
>> -#endif
>> -
>>   #endif /* CONFIG_SYSCTL */
>>
>>   /*
>> @@ -2037,16 +2031,7 @@ static struct ctl_table vm_table[] = {
>>   		.extra1		= SYSCTL_ONE,
>>   		.extra2		= SYSCTL_FOUR,
>>   	},
>> -#ifdef CONFIG_MMU
>> -	{
>> -		.procname	= "max_map_count",
>> -		.data		= &sysctl_max_map_count,
>> -		.maxlen		= sizeof(sysctl_max_map_count),
>> -		.mode		= 0644,
>> -		.proc_handler	= proc_dointvec_minmax,
>> -		.extra1		= SYSCTL_ZERO,
>> -	},
>> -#else
>> +#ifndef CONFIG_MMU
>>   	{
>>   		.procname	= "nr_trim_pages",
>>   		.data		= &sysctl_nr_trim_pages,
>> @@ -2064,17 +2049,6 @@ static struct ctl_table vm_table[] = {
>>   		.proc_handler	= proc_dointvec_minmax,
>>   		.extra1		= SYSCTL_ZERO,
>>   	},
> Nitty, but  this bit belongs in mm/nommu.c?
>
>> -#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
>> -    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
>> -	{
>> -		.procname	= "legacy_va_layout",
>> -		.data		= &sysctl_legacy_va_layout,
>> -		.maxlen		= sizeof(sysctl_legacy_va_layout),
>> -		.mode		= 0644,
>> -		.proc_handler	= proc_dointvec_minmax,
>> -		.extra1		= SYSCTL_ZERO,
>> -	},
>> -#endif
>>   #ifdef CONFIG_MMU
>>   	{
>>   		.procname	= "mmap_min_addr",
>> @@ -2100,28 +2074,6 @@ static struct ctl_table vm_table[] = {
>>   		.extra1		= SYSCTL_ZERO,
>>   	},
>>   #endif
>> -#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
>> -	{
>> -		.procname	= "mmap_rnd_bits",
>> -		.data		= &mmap_rnd_bits,
>> -		.maxlen		= sizeof(mmap_rnd_bits),
>> -		.mode		= 0600,
>> -		.proc_handler	= proc_dointvec_minmax,
>> -		.extra1		= (void *)&mmap_rnd_bits_min,
>> -		.extra2		= (void *)&mmap_rnd_bits_max,
>> -	},
>> -#endif
>> -#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
>> -	{
>> -		.procname	= "mmap_rnd_compat_bits",
>> -		.data		= &mmap_rnd_compat_bits,
>> -		.maxlen		= sizeof(mmap_rnd_compat_bits),
>> -		.mode		= 0600,
>> -		.proc_handler	= proc_dointvec_minmax,
>> -		.extra1		= (void *)&mmap_rnd_compat_bits_min,
>> -		.extra2		= (void *)&mmap_rnd_compat_bits_max,
>> -	},
>> -#endif
>>   };
>>
>>   int __init sysctl_init_bases(void)
>> diff --git a/mm/mmap.c b/mm/mmap.c
>> index aef835984b1c..cc579aafd7ba 100644
>> --- a/mm/mmap.c
>> +++ b/mm/mmap.c
>> @@ -1603,6 +1603,57 @@ struct vm_area_struct *_install_special_mapping(
>>   					&special_mapping_vmops);
>>   }
>>
>> +#ifdef CONFIG_SYSCTL
>> +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
>> +		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
>> +int sysctl_legacy_va_layout;
>> +#endif
>> +
>> +static const struct ctl_table mmap_table[] = {
>> +		{
>> +				.procname       = "max_map_count",
>> +				.data           = &sysctl_max_map_count,
>> +				.maxlen         = sizeof(sysctl_max_map_count),
>> +				.mode           = 0644,
>> +				.proc_handler   = proc_dointvec_minmax,
>> +				.extra1         = SYSCTL_ZERO,
>> +		},
>> +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
>> +		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
>> +		{
>> +				.procname       = "legacy_va_layout",
>> +				.data           = &sysctl_legacy_va_layout,
>> +				.maxlen         = sizeof(sysctl_legacy_va_layout),
>> +				.mode           = 0644,
>> +				.proc_handler   = proc_dointvec_minmax,
>> +				.extra1         = SYSCTL_ZERO,
>> +		},
>> +#endif
>> +#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
>> +		{
>> +				.procname       = "mmap_rnd_bits",
>> +				.data           = &mmap_rnd_bits,
>> +				.maxlen         = sizeof(mmap_rnd_bits),
>> +				.mode           = 0600,
>> +				.proc_handler   = proc_dointvec_minmax,
>> +				.extra1         = (void *)&mmap_rnd_bits_min,
>> +				.extra2         = (void *)&mmap_rnd_bits_max,
>> +		},
>> +#endif
>> +#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
>> +		{
>> +				.procname       = "mmap_rnd_compat_bits",
>> +				.data           = &mmap_rnd_compat_bits,
>> +				.maxlen         = sizeof(mmap_rnd_compat_bits),
>> +				.mode           = 0600,
>> +				.proc_handler   = proc_dointvec_minmax,
>> +				.extra1         = (void *)&mmap_rnd_compat_bits_min,
>> +				.extra2         = (void *)&mmap_rnd_compat_bits_max,
>> +		},
>> +#endif
>> +};
>> +#endif /* CONFIG_SYSCTL */
>> +
>>   /*
>>    * initialise the percpu counter for VM
>>    */
>> @@ -1612,6 +1663,9 @@ void __init mmap_init(void)
>>
>>   	ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
>>   	VM_BUG_ON(ret);
>> +#ifdef CONFIG_SYSCTL
>> +	register_sysctl_init("vm", mmap_table);
>> +#endif
>>   }
>>
>>   /*
>> --
>> 2.34.1
>>
> .
>



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c
  2025-01-02 14:09   ` Lorenzo Stoakes
@ 2025-01-09  2:26     ` yukaixiong
  0 siblings, 0 replies; 41+ messages in thread
From: yukaixiong @ 2025-01-09  2:26 UTC (permalink / raw)
  To: Lorenzo Stoakes
  Cc: akpm, mcgrof, ysato, dalias, glaubitz, luto, tglx, mingo, bp,
	dave.hansen, hpa, viro, brauner, jack, kees, j.granados, willy,
	Liam.Howlett, vbabka, trondmy, anna, chuck.lever, jlayton, neilb,
	okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni, paul,
	jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang



On 2025/1/2 22:09, Lorenzo Stoakes wrote:
> On Mon, Dec 23, 2024 at 10:15:27PM +0800, Kaixiong Yu wrote:
>> The sysctl_nr_trim_pages belongs to nommu.c, move it to mm/nommu.c
>> from /kernel/sysctl.c. And remove the useless extern variable declaration
>> from include/linux/mm.h
>>
>> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
> Looks good to me,
>
> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Thanks for your review !

Best ...
>> ---
>> v4:
>>   - const qualify struct ctl_table nommu_table
>> v3:
>>   - change the title
>> v2:
>>   - fix the build error: expected ';' after top level declarator
>>   - fix the build error: call to undeclared function 'register_syscall_init',
>>     use 'register_sysctl_init' to replace it.
>> ---
>> ---
>>   include/linux/mm.h |  2 --
>>   kernel/sysctl.c    | 10 ----------
>>   mm/nommu.c         | 15 ++++++++++++++-
>>   3 files changed, 14 insertions(+), 13 deletions(-)
>>
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index b3b87c1dc1e4..9813b5b9c093 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -4080,8 +4080,6 @@ unsigned long wp_shared_mapping_range(struct address_space *mapping,
>>   				      pgoff_t first_index, pgoff_t nr);
>>   #endif
>>
>> -extern int sysctl_nr_trim_pages;
>> -
>>   #ifdef CONFIG_PRINTK
>>   void mem_dump_obj(void *object);
>>   #else
>> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
>> index 62a58e417c40..97f9abffff0f 100644
>> --- a/kernel/sysctl.c
>> +++ b/kernel/sysctl.c
>> @@ -2031,16 +2031,6 @@ static struct ctl_table vm_table[] = {
>>   		.extra1		= SYSCTL_ONE,
>>   		.extra2		= SYSCTL_FOUR,
>>   	},
>> -#ifndef CONFIG_MMU
>> -	{
>> -		.procname	= "nr_trim_pages",
>> -		.data		= &sysctl_nr_trim_pages,
>> -		.maxlen		= sizeof(sysctl_nr_trim_pages),
>> -		.mode		= 0644,
>> -		.proc_handler	= proc_dointvec_minmax,
>> -		.extra1		= SYSCTL_ZERO,
>> -	},
>> -#endif
> Of course later on in the series you do what I asked in a previous commit :P Nice.
>
>>   	{
>>   		.procname	= "vfs_cache_pressure",
>>   		.data		= &sysctl_vfs_cache_pressure,
>> diff --git a/mm/nommu.c b/mm/nommu.c
>> index baa79abdaf03..3c32f8b1eb54 100644
>> --- a/mm/nommu.c
>> +++ b/mm/nommu.c
>> @@ -48,7 +48,6 @@ struct page *mem_map;
>>   unsigned long max_mapnr;
>>   EXPORT_SYMBOL(max_mapnr);
>>   unsigned long highest_memmap_pfn;
>> -int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
>>   int heap_stack_gap = 0;
>>
>>   atomic_long_t mmap_pages_allocated;
>> @@ -392,6 +391,19 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
>>   	return mm->brk = brk;
>>   }
>>
>> +static int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
>> +
>> +static const struct ctl_table nommu_table[] = {
>> +	{
>> +		.procname	= "nr_trim_pages",
>> +		.data		= &sysctl_nr_trim_pages,
>> +		.maxlen		= sizeof(sysctl_nr_trim_pages),
>> +		.mode		= 0644,
>> +		.proc_handler	= proc_dointvec_minmax,
>> +		.extra1		= SYSCTL_ZERO,
>> +	},
>> +};
>> +
>>   /*
>>    * initialise the percpu counter for VM and region record slabs
>>    */
>> @@ -402,6 +414,7 @@ void __init mmap_init(void)
>>   	ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
>>   	VM_BUG_ON(ret);
>>   	vm_region_jar = KMEM_CACHE(vm_region, SLAB_PANIC|SLAB_ACCOUNT);
>> +	register_sysctl_init("vm", nommu_table);
>>   }
>>
>>   /*
>> --
>> 2.34.1
>>
> .
>



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files
  2025-01-06 11:22     ` Joel Granados
@ 2025-01-09  2:35       ` yukaixiong
  0 siblings, 0 replies; 41+ messages in thread
From: yukaixiong @ 2025-01-09  2:35 UTC (permalink / raw)
  To: Joel Granados
  Cc: akpm, mcgrof, ysato, dalias, glaubitz, luto, tglx, mingo, bp,
	dave.hansen, hpa, viro, brauner, jack, kees, j.granados, willy,
	Liam.Howlett, vbabka, lorenzo.stoakes, trondmy, anna,
	chuck.lever, jlayton, neilb, okorniev, Dai.Ngo, tom, davem,
	edumazet, kuba, pabeni, paul, jmorris, linux-sh, linux-kernel,
	linux-fsdevel, linux-mm, linux-nfs, netdev,
	linux-security-module, dhowells, haifeng.xu, baolin.wang,
	shikemeng, dchinner, bfoster, souravpanda, hannes, rientjes,
	pasha.tatashin, david, ryan.roberts, ying.huang, yang, zev,
	serge, vegard.nossum, wangkefeng.wang



On 2025/1/6 19:22, Joel Granados wrote:
> On Sat, Dec 28, 2024 at 09:40:50PM +0800, yukaixiong wrote:
>>
>> On 2024/12/28 20:15, Joel Granados wrote:
>>> On Mon, Dec 23, 2024 at 10:15:19PM +0800, Kaixiong Yu wrote:
>>>> This patch series moves sysctls of vm_table in kernel/sysctl.c to
>>>> places where they actually belong, and do some related code clean-ups.
>>>> After this patch series, all sysctls in vm_table have been moved into its
>>>> own files, meanwhile, delete vm_table.
> ...
>>>>     sysctl: remove unneeded include
>>> This patchset looks strange. There seems to be 15 patches, but there are
>>> 30 e-mails in the thread? You can also see this when you look at it in
>>> lore [1]. And they are different repeated e-mails (mutt does not
>>> de-duplicate them). Also `b4 shazam ...` does not work. What happened?
>>> Did you send it twice with the same mail ID? Am I the only one seeing
>>> this?
>>>
>>> I would suggest the following (hopefully you are using b4):
>>> 1. Check to see how things will be sent with b4. `b4 send --resend -o OUTPUT_DIR`
>>>      If you see 30 emails in that dir from your patchset then something is
>>>      still wrong.
>>> 2. After you make sure that everything is in order. Do the resend
>>>      without bumping the version up (leave it at version 4)
>>>
>>> Best
>>>
>>> [1] : https://lore.kernel.org/all/20241223141550.638616-1-yukaixiong@huawei.com/
>> I'm very sorry, due to my mistake, 15 patches were sent twice.
> No worries. I saw that you have re-sent the patchset and it seems that
> this time there is only 15 mails. I see that you are only using my
> j.granados@samsung.com ID; can you please add my kernel.org
> (joel.granados@kernel.org) mail to the future mails that you send (no
> need to re-send v4).
>
> Thx
>
> ...

OK, I will add joel.granados@kernel.org to the future mails.



^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c
  2024-12-28 14:57 Kaixiong Yu
@ 2024-12-28 14:57 ` Kaixiong Yu
  0 siblings, 0 replies; 41+ messages in thread
From: Kaixiong Yu @ 2024-12-28 14:57 UTC (permalink / raw)
  To: akpm, mcgrof
  Cc: ysato, dalias, glaubitz, luto, tglx, mingo, bp, dave.hansen, hpa,
	viro, brauner, jack, kees, j.granados, willy, Liam.Howlett,
	vbabka, lorenzo.stoakes, trondmy, anna, chuck.lever, jlayton,
	neilb, okorniev, Dai.Ngo, tom, davem, edumazet, kuba, pabeni,
	paul, jmorris, linux-sh, linux-kernel, linux-fsdevel, linux-mm,
	linux-nfs, netdev, linux-security-module, dhowells, haifeng.xu,
	baolin.wang, shikemeng, dchinner, bfoster, souravpanda, hannes,
	rientjes, pasha.tatashin, david, ryan.roberts, ying.huang, yang,
	zev, serge, vegard.nossum, wangkefeng.wang

This moves all mmap related sysctls to mm/mmap.c, as part of the
kernel/sysctl.c cleaning, also move the variable declaration from
kernel/sysctl.c into mm/mmap.c.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table mmap_table
v3:
 - change the title
v2:
 - fix sysctl_max_map_count undeclared issue in mm/nommu.c
---
---
 kernel/sysctl.c | 50 +--------------------------------------------
 mm/mmap.c       | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 49 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index aea3482106e0..9c245898f535 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -127,12 +127,6 @@ enum sysctl_writes_mode {
 
 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
 #endif /* CONFIG_PROC_SYSCTL */
-
-#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
-    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
-int sysctl_legacy_va_layout;
-#endif
-
 #endif /* CONFIG_SYSCTL */
 
 /*
@@ -2037,16 +2031,7 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_FOUR,
 	},
-#ifdef CONFIG_MMU
-	{
-		.procname	= "max_map_count",
-		.data		= &sysctl_max_map_count,
-		.maxlen		= sizeof(sysctl_max_map_count),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#else
+#ifndef CONFIG_MMU
 	{
 		.procname	= "nr_trim_pages",
 		.data		= &sysctl_nr_trim_pages,
@@ -2064,17 +2049,6 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= SYSCTL_ZERO,
 	},
-#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
-    defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
-	{
-		.procname	= "legacy_va_layout",
-		.data		= &sysctl_legacy_va_layout,
-		.maxlen		= sizeof(sysctl_legacy_va_layout),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
 #ifdef CONFIG_MMU
 	{
 		.procname	= "mmap_min_addr",
@@ -2100,28 +2074,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif
-#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
-	{
-		.procname	= "mmap_rnd_bits",
-		.data		= &mmap_rnd_bits,
-		.maxlen		= sizeof(mmap_rnd_bits),
-		.mode		= 0600,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= (void *)&mmap_rnd_bits_min,
-		.extra2		= (void *)&mmap_rnd_bits_max,
-	},
-#endif
-#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
-	{
-		.procname	= "mmap_rnd_compat_bits",
-		.data		= &mmap_rnd_compat_bits,
-		.maxlen		= sizeof(mmap_rnd_compat_bits),
-		.mode		= 0600,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= (void *)&mmap_rnd_compat_bits_min,
-		.extra2		= (void *)&mmap_rnd_compat_bits_max,
-	},
-#endif
 };
 
 int __init sysctl_init_bases(void)
diff --git a/mm/mmap.c b/mm/mmap.c
index aef835984b1c..cc579aafd7ba 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1603,6 +1603,57 @@ struct vm_area_struct *_install_special_mapping(
 					&special_mapping_vmops);
 }
 
+#ifdef CONFIG_SYSCTL
+#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
+		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
+int sysctl_legacy_va_layout;
+#endif
+
+static const struct ctl_table mmap_table[] = {
+		{
+				.procname       = "max_map_count",
+				.data           = &sysctl_max_map_count,
+				.maxlen         = sizeof(sysctl_max_map_count),
+				.mode           = 0644,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = SYSCTL_ZERO,
+		},
+#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
+		defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
+		{
+				.procname       = "legacy_va_layout",
+				.data           = &sysctl_legacy_va_layout,
+				.maxlen         = sizeof(sysctl_legacy_va_layout),
+				.mode           = 0644,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = SYSCTL_ZERO,
+		},
+#endif
+#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
+		{
+				.procname       = "mmap_rnd_bits",
+				.data           = &mmap_rnd_bits,
+				.maxlen         = sizeof(mmap_rnd_bits),
+				.mode           = 0600,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = (void *)&mmap_rnd_bits_min,
+				.extra2         = (void *)&mmap_rnd_bits_max,
+		},
+#endif
+#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
+		{
+				.procname       = "mmap_rnd_compat_bits",
+				.data           = &mmap_rnd_compat_bits,
+				.maxlen         = sizeof(mmap_rnd_compat_bits),
+				.mode           = 0600,
+				.proc_handler   = proc_dointvec_minmax,
+				.extra1         = (void *)&mmap_rnd_compat_bits_min,
+				.extra2         = (void *)&mmap_rnd_compat_bits_max,
+		},
+#endif
+};
+#endif /* CONFIG_SYSCTL */
+
 /*
  * initialise the percpu counter for VM
  */
@@ -1612,6 +1663,9 @@ void __init mmap_init(void)
 
 	ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
 	VM_BUG_ON(ret);
+#ifdef CONFIG_SYSCTL
+	register_sysctl_init("vm", mmap_table);
+#endif
 }
 
 /*
-- 
2.34.1



^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2025-01-09  2:35 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-23 14:15 [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 01/15] mm: vmstat: move sysctls to mm/vmstat.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 02/15] mm: filemap: move sysctl to mm/filemap.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 03/15] mm: swap: move sysctl to mm/swap.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 04/15] mm: vmscan: move vmscan sysctls to mm/vmscan.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 05/15] mm: util: move sysctls to mm/util.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Kaixiong Yu
2025-01-02 14:08   ` Lorenzo Stoakes
2025-01-09  2:20     ` yukaixiong
2024-12-23 14:15 ` [PATCH v4 -next 07/15] security: min_addr: move sysctl to security/min_addr.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c Kaixiong Yu
2025-01-02 14:09   ` Lorenzo Stoakes
2025-01-09  2:26     ` yukaixiong
2024-12-23 14:15 ` [PATCH v4 -next 09/15] fs: fs-writeback: move sysctl to fs/fs-writeback.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 10/15] fs: drop_caches: move sysctl to fs/drop_caches.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 11/15] sunrpc: simplify rpcauth_cache_shrink_count() Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 12/15] fs: dcache: move the sysctl to fs/dcache.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 13/15] x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 14/15] sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 15/15] sysctl: remove unneeded include Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 01/15] mm: vmstat: move sysctls to mm/vmstat.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 02/15] mm: filemap: move sysctl to mm/filemap.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 03/15] mm: swap: move sysctl to mm/swap.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 04/15] mm: vmscan: move vmscan sysctls to mm/vmscan.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 05/15] mm: util: move sysctls to mm/util.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 07/15] security: min_addr: move sysctl to security/min_addr.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 08/15] mm: nommu: move sysctl to mm/nommu.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 09/15] fs: fs-writeback: move sysctl to fs/fs-writeback.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 10/15] fs: drop_caches: move sysctl to fs/drop_caches.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 11/15] sunrpc: simplify rpcauth_cache_shrink_count() Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 12/15] fs: dcache: move the sysctl to fs/dcache.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 13/15] x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 14/15] sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c Kaixiong Yu
2024-12-23 14:15 ` [PATCH v4 -next 15/15] sysctl: remove unneeded include Kaixiong Yu
2024-12-28 12:15 ` [PATCH v4 -next 00/15] sysctl: move sysctls from vm_table into its own files Joel Granados
2024-12-28 13:40   ` yukaixiong
2025-01-06 11:22     ` Joel Granados
2025-01-09  2:35       ` yukaixiong
2024-12-28 14:57 Kaixiong Yu
2024-12-28 14:57 ` [PATCH v4 -next 06/15] mm: mmap: move sysctl to mm/mmap.c Kaixiong Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox