]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm: util: move sysctls to mm/util.c
authorKaixiong Yu <yukaixiong@huawei.com>
Sat, 11 Jan 2025 07:07:40 +0000 (15:07 +0800)
committerJoel Granados <joel.granados@kernel.org>
Fri, 7 Feb 2025 15:53:04 +0000 (16:53 +0100)
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>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Joel Granados <joel.granados@kernel.org>
include/linux/mm.h
include/linux/mman.h
kernel/sysctl.c
mm/util.c

index 23cfaa40fef3835fbea56a27a2c3aa9745e3860a..7e0018222f6407ef03de89d2e398b527141bea74 100644 (file)
@@ -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))
index a842783ffa62bdabff3b22aaf1e95ba058463f26..bce214fece16b9af3791a2baaecd6063d0481938 100644 (file)
@@ -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
index c1434adb8d506cacbfc0982b4a50dc832c65b213..ad62b76851e787d626e885c02861401710b1e974 100644 (file)
@@ -2020,29 +2020,6 @@ static const struct ctl_table kern_table[] = {
 };
 
 static const 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 const 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",
index b6b9684a1438875d06287d713383c8a0da7b2e60..b3480f358d1140f1efd4548aa019e0a039fcacda 100644 (file)
--- 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>
@@ -906,14 +907,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;
 
@@ -928,8 +931,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;
@@ -964,8 +967,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;
 
@@ -975,6 +978,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
  */