2022-02-20 06:57:20

by tangmeng

[permalink] [raw]
Subject: [PATCH 06/11] mm/vmstat: move vmstat sysctls to its own file

kernel/sysctl.c is a kitchen sink where everyone leaves their dirty
dishes, this makes it very difficult to maintain.

To help with this maintenance let's start by moving sysctls to places
where they actually belong. The proc sysctl maintainers do not want to
know what sysctl knobs you wish to add for your own piece of code, we
just care about the core logic.

All filesystem syctls now get reviewed by fs folks. This commit
follows the commit of fs, move the vmstat sysctls to its own file,
mm/vmstat.c.

vmstat_refresh is defined when CONFIG_PROC_FS is defined, so macro
control is added to stat_refresh.

Signed-off-by: tangmeng <[email protected]>
---
include/linux/vmstat.h | 9 --------
kernel/sysctl.c | 25 ---------------------
mm/vmstat.c | 50 ++++++++++++++++++++++++++++++++++++++----
3 files changed, 46 insertions(+), 38 deletions(-)

diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index bfe38869498d..b615d8d7c1d2 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -10,15 +10,10 @@
#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(struct ctl_table *table, int write,
- void *buffer, size_t *length, loff_t *ppos);
#endif

struct reclaim_stat {
@@ -300,10 +295,6 @@ void quiet_vmstat(void);
void cpu_vm_stats_fold(int cpu);
void refresh_zone_stat_thresholds(void);

-struct ctl_table;
-int vmstat_refresh(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 62499e3207aa..31f2c6e21392 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2192,15 +2192,6 @@ static struct ctl_table vm_table[] = {
.mode = 0644,
.proc_handler = &hugetlb_mempolicy_sysctl_handler,
},
- {
- .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 = "hugetlb_shm_group",
@@ -2377,22 +2368,6 @@ static struct ctl_table vm_table[] = {
.extra2 = SYSCTL_ONE_HUNDRED,
},
#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 4057372745d0..e7eeba4db2eb 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -32,7 +32,7 @@
#include "internal.h"

#ifdef CONFIG_NUMA
-int sysctl_vm_numa_stat = ENABLE_NUMA_STAT;
+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 +74,7 @@ static void invalid_numa_statistics(void)

static DEFINE_MUTEX(vm_numa_stat_lock);

-int sysctl_vm_numa_stat_handler(struct ctl_table *table, int write,
+static int sysctl_vm_numa_stat_handler(struct ctl_table *table, int write,
void *buffer, size_t *length, loff_t *ppos)
{
int ret, oldval;
@@ -1853,7 +1853,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;

#ifdef CONFIG_PROC_FS
static void refresh_vm_stats(struct work_struct *work)
@@ -1861,7 +1861,7 @@ static void refresh_vm_stats(struct work_struct *work)
refresh_cpu_vm_stats(true);
}

-int vmstat_refresh(struct ctl_table *table, int write,
+static int vmstat_refresh(struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
long val;
@@ -2238,3 +2238,45 @@ static int __init extfrag_debug_init(void)

module_init(extfrag_debug_init);
#endif
+
+#ifdef CONFIG_SYSCTL
+static struct ctl_table vm_stat_table[] = {
+#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 /* CONFIG_NUMA */
+#ifdef CONFIG_SMP
+ {
+ .procname = "stat_interval",
+ .data = &sysctl_stat_interval,
+ .maxlen = sizeof(sysctl_stat_interval),
+ .mode = 0644,
+ .proc_handler = proc_dointvec_jiffies,
+ },
+#ifdef CONFIG_PROC_FS
+ {
+ .procname = "stat_refresh",
+ .data = NULL,
+ .maxlen = 0,
+ .mode = 0600,
+ .proc_handler = vmstat_refresh,
+ },
+#endif /* CONFIG_PROC_FS */
+#endif /* CONFIG_SMP */
+ { }
+};
+
+static __init int vm_stat_sysctls_init(void)
+{
+ register_sysctl_init("vm", vm_stat_table);
+ return 0;
+}
+late_initcall(vm_stat_sysctls_init);
+#endif /* CONFIG_SYSCTL */
--
2.20.1