Skip to content

Commit 2f5edd0

Browse files
Joelgranadosmcgrof
authored andcommitted
sysctl: Refactor base paths registrations
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>
1 parent 19c4e61 commit 2f5edd0

3 files changed

Lines changed: 11 additions & 47 deletions

File tree

fs/sysctls.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ static struct ctl_table fs_shared_sysctls[] = {
2929
{ }
3030
};
3131

32-
DECLARE_SYSCTL_BASE(fs, fs_shared_sysctls);
33-
3432
static int __init init_fs_sysctls(void)
3533
{
36-
return register_sysctl_base(fs);
34+
register_sysctl_init("fs", fs_shared_sysctls);
35+
return 0;
3736
}
3837

3938
early_initcall(init_fs_sysctls);

include/linux/sysctl.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,6 @@ struct ctl_path {
197197

198198
#ifdef CONFIG_SYSCTL
199199

200-
#define DECLARE_SYSCTL_BASE(_name, _table) \
201-
static struct ctl_table _name##_base_table[] = { \
202-
{ \
203-
.procname = #_name, \
204-
.mode = 0555, \
205-
.child = _table, \
206-
}, \
207-
{ }, \
208-
}
209-
210-
extern int __register_sysctl_base(struct ctl_table *base_table);
211-
212-
#define register_sysctl_base(_name) __register_sysctl_base(_name##_base_table)
213-
214200
void proc_sys_poll_notify(struct ctl_table_poll *poll);
215201

216202
extern void setup_sysctl_set(struct ctl_table_set *p,
@@ -247,15 +233,6 @@ extern struct ctl_table sysctl_mount_point[];
247233

248234
#else /* CONFIG_SYSCTL */
249235

250-
#define DECLARE_SYSCTL_BASE(_name, _table)
251-
252-
static inline int __register_sysctl_base(struct ctl_table *base_table)
253-
{
254-
return 0;
255-
}
256-
257-
#define register_sysctl_base(table) __register_sysctl_base(table)
258-
259236
static inline void register_sysctl_init(const char *path, struct ctl_table *table)
260237
{
261238
}

kernel/sysctl.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,11 +1782,6 @@ static struct ctl_table kern_table[] = {
17821782
.mode = 0644,
17831783
.proc_handler = sysctl_max_threads,
17841784
},
1785-
{
1786-
.procname = "usermodehelper",
1787-
.mode = 0555,
1788-
.child = usermodehelper_table,
1789-
},
17901785
{
17911786
.procname = "overflowuid",
17921787
.data = &overflowuid,
@@ -1962,13 +1957,6 @@ static struct ctl_table kern_table[] = {
19621957
.proc_handler = proc_dointvec,
19631958
},
19641959
#endif
1965-
#ifdef CONFIG_KEYS
1966-
{
1967-
.procname = "keys",
1968-
.mode = 0555,
1969-
.child = key_sysctls,
1970-
},
1971-
#endif
19721960
#ifdef CONFIG_PERF_EVENTS
19731961
/*
19741962
* User-space scripts rely on the existence of this file
@@ -2348,17 +2336,17 @@ static struct ctl_table dev_table[] = {
23482336
{ }
23492337
};
23502338

2351-
DECLARE_SYSCTL_BASE(kernel, kern_table);
2352-
DECLARE_SYSCTL_BASE(vm, vm_table);
2353-
DECLARE_SYSCTL_BASE(debug, debug_table);
2354-
DECLARE_SYSCTL_BASE(dev, dev_table);
2355-
23562339
int __init sysctl_init_bases(void)
23572340
{
2358-
register_sysctl_base(kernel);
2359-
register_sysctl_base(vm);
2360-
register_sysctl_base(debug);
2361-
register_sysctl_base(dev);
2341+
register_sysctl_init("kernel", kern_table);
2342+
register_sysctl_init("kernel/usermodehelper", usermodehelper_table);
2343+
#ifdef CONFIG_KEYS
2344+
register_sysctl_init("kernel/keys", key_sysctls);
2345+
#endif
2346+
2347+
register_sysctl_init("vm", vm_table);
2348+
register_sysctl_init("debug", debug_table);
2349+
register_sysctl_init("dev", dev_table);
23622350

23632351
return 0;
23642352
}

0 commit comments

Comments
 (0)