sysctl: Refactor base paths registrations
authorJoel Granados <j.granados@samsung.com>
Tue, 23 May 2023 12:22:19 +0000 (14:22 +0200)
committerLuis Chamberlain <mcgrof@kernel.org>
Wed, 24 May 2023 04:43:26 +0000 (21:43 -0700)
This is part of the general push to deprecate register_sysctl_paths and
register_sysctl_table. The old way of doing this through
register_sysctl_base and DECLARE_SYSCTL_BASE macro is replaced with a
call to register_sysctl_init. The 5 base paths affected are: "kernel",
"vm", "debug", "dev" and "fs".

We remove the register_sysctl_base function and the DECLARE_SYSCTL_BASE
macro since they are no longer needed.

In order to quickly acertain that the paths did not actually change I
executed `find /proc/sys/ | sha1sum` and made sure that the sha was the
same before and after the commit.

We end up saving 563 bytes with this change:

./scripts/bloat-o-meter vmlinux.0.base vmlinux.1.refactor-base-paths
add/remove: 0/5 grow/shrink: 2/0 up/down: 77/-640 (-563)
Function                                     old     new   delta
sysctl_init_bases                             55     111     +56
init_fs_sysctls                               12      33     +21
vm_base_table                                128       -    -128
kernel_base_table                            128       -    -128
fs_base_table                                128       -    -128
dev_base_table                               128       -    -128
debug_base_table                             128       -    -128
Total: Before=21258215, After=21257652, chg -0.00%

[mcgrof: modified to use register_sysctl_init() over register_sysctl()
 and add bloat-o-meter stats]

Signed-off-by: Joel Granados <j.granados@samsung.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Christian Brauner <brauner@kernel.org>
fs/sysctls.c
include/linux/sysctl.h
kernel/sysctl.c

index c701273c9432bcf7000c80ca7af2bf4ef92c5303..76a0aee8c2291b18a8b98b2a3eda81b7d376cddb 100644 (file)
@@ -29,11 +29,10 @@ static struct ctl_table fs_shared_sysctls[] = {
        { }
 };
 
-DECLARE_SYSCTL_BASE(fs, fs_shared_sysctls);
-
 static int __init init_fs_sysctls(void)
 {
-       return register_sysctl_base(fs);
+       register_sysctl_init("fs", fs_shared_sysctls);
+       return 0;
 }
 
 early_initcall(init_fs_sysctls);
index 218e56a26fb0985efa00d58455e4a8bf1fe2cf2d..653b66c762b12b1fb7783c43751e5a8d0b818d16 100644 (file)
@@ -197,20 +197,6 @@ struct ctl_path {
 
 #ifdef CONFIG_SYSCTL
 
-#define DECLARE_SYSCTL_BASE(_name, _table)                             \
-static struct ctl_table _name##_base_table[] = {                       \
-       {                                                               \
-               .procname       = #_name,                               \
-               .mode           = 0555,                                 \
-               .child          = _table,                               \
-       },                                                              \
-       { },                                                            \
-}
-
-extern int __register_sysctl_base(struct ctl_table *base_table);
-
-#define register_sysctl_base(_name) __register_sysctl_base(_name##_base_table)
-
 void proc_sys_poll_notify(struct ctl_table_poll *poll);
 
 extern void setup_sysctl_set(struct ctl_table_set *p,
@@ -247,15 +233,6 @@ extern struct ctl_table sysctl_mount_point[];
 
 #else /* CONFIG_SYSCTL */
 
-#define DECLARE_SYSCTL_BASE(_name, _table)
-
-static inline int __register_sysctl_base(struct ctl_table *base_table)
-{
-       return 0;
-}
-
-#define register_sysctl_base(table) __register_sysctl_base(table)
-
 static inline void register_sysctl_init(const char *path, struct ctl_table *table)
 {
 }
index bfe53e83552457448f128e5876204386cffc4015..73fa9cf7ee1146a0d6d42b14a1eb4616bceefb58 100644 (file)
@@ -1782,11 +1782,6 @@ static struct ctl_table kern_table[] = {
                .mode           = 0644,
                .proc_handler   = sysctl_max_threads,
        },
-       {
-               .procname       = "usermodehelper",
-               .mode           = 0555,
-               .child          = usermodehelper_table,
-       },
        {
                .procname       = "overflowuid",
                .data           = &overflowuid,
@@ -1962,13 +1957,6 @@ static struct ctl_table kern_table[] = {
                .proc_handler   = proc_dointvec,
        },
 #endif
-#ifdef CONFIG_KEYS
-       {
-               .procname       = "keys",
-               .mode           = 0555,
-               .child          = key_sysctls,
-       },
-#endif
 #ifdef CONFIG_PERF_EVENTS
        /*
         * User-space scripts rely on the existence of this file
@@ -2348,17 +2336,17 @@ static struct ctl_table dev_table[] = {
        { }
 };
 
-DECLARE_SYSCTL_BASE(kernel, kern_table);
-DECLARE_SYSCTL_BASE(vm, vm_table);
-DECLARE_SYSCTL_BASE(debug, debug_table);
-DECLARE_SYSCTL_BASE(dev, dev_table);
-
 int __init sysctl_init_bases(void)
 {
-       register_sysctl_base(kernel);
-       register_sysctl_base(vm);
-       register_sysctl_base(debug);
-       register_sysctl_base(dev);
+       register_sysctl_init("kernel", kern_table);
+       register_sysctl_init("kernel/usermodehelper", usermodehelper_table);
+#ifdef CONFIG_KEYS
+       register_sysctl_init("kernel/keys", key_sysctls);
+#endif
+
+       register_sysctl_init("vm", vm_table);
+       register_sysctl_init("debug", debug_table);
+       register_sysctl_init("dev", dev_table);
 
        return 0;
 }