Skip to content

Commit aa779e5

Browse files
zhanglianjie-163mcgrof
authored andcommitted
mm: move page-writeback sysctls to their 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. So move the page-writeback sysctls to its own file. [[email protected]: coding-style cleanups] [email protected]: fix CONFIG_SYSCTL=n warnings] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: zhanglianjie <[email protected]> Cc: Kees Cook <[email protected]> Cc: Iurii Zaikin <[email protected]> Cc: Luis Chamberlain <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 43fe219 commit aa779e5

File tree

3 files changed

+93
-94
lines changed

3 files changed

+93
-94
lines changed

include/linux/writeback.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -345,28 +345,13 @@ void wb_domain_exit(struct wb_domain *dom);
345345
extern struct wb_domain global_wb_domain;
346346

347347
/* These are exported to sysctl. */
348-
extern int dirty_background_ratio;
349-
extern unsigned long dirty_background_bytes;
350-
extern int vm_dirty_ratio;
351-
extern unsigned long vm_dirty_bytes;
352348
extern unsigned int dirty_writeback_interval;
353349
extern unsigned int dirty_expire_interval;
354350
extern unsigned int dirtytime_expire_interval;
355-
extern int vm_highmem_is_dirtyable;
356351
extern int laptop_mode;
357352

358-
int dirty_background_ratio_handler(struct ctl_table *table, int write,
359-
void *buffer, size_t *lenp, loff_t *ppos);
360-
int dirty_background_bytes_handler(struct ctl_table *table, int write,
361-
void *buffer, size_t *lenp, loff_t *ppos);
362-
int dirty_ratio_handler(struct ctl_table *table, int write,
363-
void *buffer, size_t *lenp, loff_t *ppos);
364-
int dirty_bytes_handler(struct ctl_table *table, int write,
365-
void *buffer, size_t *lenp, loff_t *ppos);
366353
int dirtytime_interval_handler(struct ctl_table *table, int write,
367354
void *buffer, size_t *lenp, loff_t *ppos);
368-
int dirty_writeback_centisecs_handler(struct ctl_table *table, int write,
369-
void *buffer, size_t *lenp, loff_t *ppos);
370355

371356
void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
372357
unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh);

kernel/sysctl.c

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@
100100
static const int six_hundred_forty_kb = 640 * 1024;
101101
#endif
102102

103-
/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
104-
static const unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
105103

106104
static const int ngroups_max = NGROUPS_MAX;
107105
static const int cap_last_cap = CAP_LAST_CAP;
@@ -2263,55 +2261,6 @@ static struct ctl_table vm_table[] = {
22632261
.proc_handler = proc_dointvec_minmax,
22642262
.extra1 = SYSCTL_ZERO,
22652263
},
2266-
{
2267-
.procname = "dirty_background_ratio",
2268-
.data = &dirty_background_ratio,
2269-
.maxlen = sizeof(dirty_background_ratio),
2270-
.mode = 0644,
2271-
.proc_handler = dirty_background_ratio_handler,
2272-
.extra1 = SYSCTL_ZERO,
2273-
.extra2 = SYSCTL_ONE_HUNDRED,
2274-
},
2275-
{
2276-
.procname = "dirty_background_bytes",
2277-
.data = &dirty_background_bytes,
2278-
.maxlen = sizeof(dirty_background_bytes),
2279-
.mode = 0644,
2280-
.proc_handler = dirty_background_bytes_handler,
2281-
.extra1 = SYSCTL_LONG_ONE,
2282-
},
2283-
{
2284-
.procname = "dirty_ratio",
2285-
.data = &vm_dirty_ratio,
2286-
.maxlen = sizeof(vm_dirty_ratio),
2287-
.mode = 0644,
2288-
.proc_handler = dirty_ratio_handler,
2289-
.extra1 = SYSCTL_ZERO,
2290-
.extra2 = SYSCTL_ONE_HUNDRED,
2291-
},
2292-
{
2293-
.procname = "dirty_bytes",
2294-
.data = &vm_dirty_bytes,
2295-
.maxlen = sizeof(vm_dirty_bytes),
2296-
.mode = 0644,
2297-
.proc_handler = dirty_bytes_handler,
2298-
.extra1 = (void *)&dirty_bytes_min,
2299-
},
2300-
{
2301-
.procname = "dirty_writeback_centisecs",
2302-
.data = &dirty_writeback_interval,
2303-
.maxlen = sizeof(dirty_writeback_interval),
2304-
.mode = 0644,
2305-
.proc_handler = dirty_writeback_centisecs_handler,
2306-
},
2307-
{
2308-
.procname = "dirty_expire_centisecs",
2309-
.data = &dirty_expire_interval,
2310-
.maxlen = sizeof(dirty_expire_interval),
2311-
.mode = 0644,
2312-
.proc_handler = proc_dointvec_minmax,
2313-
.extra1 = SYSCTL_ZERO,
2314-
},
23152264
{
23162265
.procname = "dirtytime_expire_seconds",
23172266
.data = &dirtytime_expire_interval,
@@ -2483,13 +2432,6 @@ static struct ctl_table vm_table[] = {
24832432
.extra1 = SYSCTL_ZERO,
24842433
},
24852434
#endif
2486-
{
2487-
.procname = "laptop_mode",
2488-
.data = &laptop_mode,
2489-
.maxlen = sizeof(laptop_mode),
2490-
.mode = 0644,
2491-
.proc_handler = proc_dointvec_jiffies,
2492-
},
24932435
{
24942436
.procname = "vfs_cache_pressure",
24952437
.data = &sysctl_vfs_cache_pressure,
@@ -2587,17 +2529,6 @@ static struct ctl_table vm_table[] = {
25872529
.extra1 = SYSCTL_ZERO,
25882530
},
25892531
#endif
2590-
#ifdef CONFIG_HIGHMEM
2591-
{
2592-
.procname = "highmem_is_dirtyable",
2593-
.data = &vm_highmem_is_dirtyable,
2594-
.maxlen = sizeof(vm_highmem_is_dirtyable),
2595-
.mode = 0644,
2596-
.proc_handler = proc_dointvec_minmax,
2597-
.extra1 = SYSCTL_ZERO,
2598-
.extra2 = SYSCTL_ONE,
2599-
},
2600-
#endif
26012532
#ifdef CONFIG_MEMORY_FAILURE
26022533
{
26032534
.procname = "memory_failure_early_kill",

mm/page-writeback.c

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,33 @@ static long ratelimit_pages = 32;
7070
/*
7171
* Start background writeback (via writeback threads) at this percentage
7272
*/
73-
int dirty_background_ratio = 10;
73+
static int dirty_background_ratio = 10;
7474

7575
/*
7676
* dirty_background_bytes starts at 0 (disabled) so that it is a function of
7777
* dirty_background_ratio * the amount of dirtyable memory
7878
*/
79-
unsigned long dirty_background_bytes;
79+
static unsigned long dirty_background_bytes;
8080

8181
/*
8282
* free highmem will not be subtracted from the total free memory
8383
* for calculating free ratios if vm_highmem_is_dirtyable is true
8484
*/
85-
int vm_highmem_is_dirtyable;
85+
static int vm_highmem_is_dirtyable;
8686

8787
/*
8888
* The generator of dirty data starts writeback at this percentage
8989
*/
90-
int vm_dirty_ratio = 20;
90+
static int vm_dirty_ratio = 20;
91+
92+
/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93+
static const unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
9194

9295
/*
9396
* vm_dirty_bytes starts at 0 (disabled) so that it is a function of
9497
* vm_dirty_ratio * the amount of dirtyable memory
9598
*/
96-
unsigned long vm_dirty_bytes;
99+
static unsigned long vm_dirty_bytes;
97100

98101
/*
99102
* The interval between `kupdate'-style writebacks
@@ -491,7 +494,8 @@ bool node_dirty_ok(struct pglist_data *pgdat)
491494
return nr_pages <= limit;
492495
}
493496

494-
int dirty_background_ratio_handler(struct ctl_table *table, int write,
497+
#ifdef CONFIG_SYSCTL
498+
static int dirty_background_ratio_handler(struct ctl_table *table, int write,
495499
void *buffer, size_t *lenp, loff_t *ppos)
496500
{
497501
int ret;
@@ -502,7 +506,7 @@ int dirty_background_ratio_handler(struct ctl_table *table, int write,
502506
return ret;
503507
}
504508

505-
int dirty_background_bytes_handler(struct ctl_table *table, int write,
509+
static int dirty_background_bytes_handler(struct ctl_table *table, int write,
506510
void *buffer, size_t *lenp, loff_t *ppos)
507511
{
508512
int ret;
@@ -513,7 +517,7 @@ int dirty_background_bytes_handler(struct ctl_table *table, int write,
513517
return ret;
514518
}
515519

516-
int dirty_ratio_handler(struct ctl_table *table, int write, void *buffer,
520+
static int dirty_ratio_handler(struct ctl_table *table, int write, void *buffer,
517521
size_t *lenp, loff_t *ppos)
518522
{
519523
int old_ratio = vm_dirty_ratio;
@@ -527,7 +531,7 @@ int dirty_ratio_handler(struct ctl_table *table, int write, void *buffer,
527531
return ret;
528532
}
529533

530-
int dirty_bytes_handler(struct ctl_table *table, int write,
534+
static int dirty_bytes_handler(struct ctl_table *table, int write,
531535
void *buffer, size_t *lenp, loff_t *ppos)
532536
{
533537
unsigned long old_bytes = vm_dirty_bytes;
@@ -540,6 +544,7 @@ int dirty_bytes_handler(struct ctl_table *table, int write,
540544
}
541545
return ret;
542546
}
547+
#endif
543548

544549
static unsigned long wp_next_time(unsigned long cur_time)
545550
{
@@ -1981,10 +1986,11 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
19811986
return false;
19821987
}
19831988

1989+
#ifdef CONFIG_SYSCTL
19841990
/*
19851991
* sysctl handler for /proc/sys/vm/dirty_writeback_centisecs
19861992
*/
1987-
int dirty_writeback_centisecs_handler(struct ctl_table *table, int write,
1993+
static int dirty_writeback_centisecs_handler(struct ctl_table *table, int write,
19881994
void *buffer, size_t *length, loff_t *ppos)
19891995
{
19901996
unsigned int old_interval = dirty_writeback_interval;
@@ -2005,6 +2011,7 @@ int dirty_writeback_centisecs_handler(struct ctl_table *table, int write,
20052011

20062012
return ret;
20072013
}
2014+
#endif
20082015

20092016
void laptop_mode_timer_fn(struct timer_list *t)
20102017
{
@@ -2069,6 +2076,79 @@ static int page_writeback_cpu_online(unsigned int cpu)
20692076
return 0;
20702077
}
20712078

2079+
#ifdef CONFIG_SYSCTL
2080+
static struct ctl_table vm_page_writeback_sysctls[] = {
2081+
{
2082+
.procname = "dirty_background_ratio",
2083+
.data = &dirty_background_ratio,
2084+
.maxlen = sizeof(dirty_background_ratio),
2085+
.mode = 0644,
2086+
.proc_handler = dirty_background_ratio_handler,
2087+
.extra1 = SYSCTL_ZERO,
2088+
.extra2 = SYSCTL_ONE_HUNDRED,
2089+
},
2090+
{
2091+
.procname = "dirty_background_bytes",
2092+
.data = &dirty_background_bytes,
2093+
.maxlen = sizeof(dirty_background_bytes),
2094+
.mode = 0644,
2095+
.proc_handler = dirty_background_bytes_handler,
2096+
.extra1 = SYSCTL_LONG_ONE,
2097+
},
2098+
{
2099+
.procname = "dirty_ratio",
2100+
.data = &vm_dirty_ratio,
2101+
.maxlen = sizeof(vm_dirty_ratio),
2102+
.mode = 0644,
2103+
.proc_handler = dirty_ratio_handler,
2104+
.extra1 = SYSCTL_ZERO,
2105+
.extra2 = SYSCTL_ONE_HUNDRED,
2106+
},
2107+
{
2108+
.procname = "dirty_bytes",
2109+
.data = &vm_dirty_bytes,
2110+
.maxlen = sizeof(vm_dirty_bytes),
2111+
.mode = 0644,
2112+
.proc_handler = dirty_bytes_handler,
2113+
.extra1 = (void *)&dirty_bytes_min,
2114+
},
2115+
{
2116+
.procname = "dirty_writeback_centisecs",
2117+
.data = &dirty_writeback_interval,
2118+
.maxlen = sizeof(dirty_writeback_interval),
2119+
.mode = 0644,
2120+
.proc_handler = dirty_writeback_centisecs_handler,
2121+
},
2122+
{
2123+
.procname = "dirty_expire_centisecs",
2124+
.data = &dirty_expire_interval,
2125+
.maxlen = sizeof(dirty_expire_interval),
2126+
.mode = 0644,
2127+
.proc_handler = proc_dointvec_minmax,
2128+
.extra1 = SYSCTL_ZERO,
2129+
},
2130+
#ifdef CONFIG_HIGHMEM
2131+
{
2132+
.procname = "highmem_is_dirtyable",
2133+
.data = &vm_highmem_is_dirtyable,
2134+
.maxlen = sizeof(vm_highmem_is_dirtyable),
2135+
.mode = 0644,
2136+
.proc_handler = proc_dointvec_minmax,
2137+
.extra1 = SYSCTL_ZERO,
2138+
.extra2 = SYSCTL_ONE,
2139+
},
2140+
#endif
2141+
{
2142+
.procname = "laptop_mode",
2143+
.data = &laptop_mode,
2144+
.maxlen = sizeof(laptop_mode),
2145+
.mode = 0644,
2146+
.proc_handler = proc_dointvec_jiffies,
2147+
},
2148+
{}
2149+
};
2150+
#endif
2151+
20722152
/*
20732153
* Called early on to tune the page writeback dirty limits.
20742154
*
@@ -2093,6 +2173,9 @@ void __init page_writeback_init(void)
20932173
page_writeback_cpu_online, NULL);
20942174
cpuhp_setup_state(CPUHP_MM_WRITEBACK_DEAD, "mm/writeback:dead", NULL,
20952175
page_writeback_cpu_online);
2176+
#ifdef CONFIG_SYSCTL
2177+
register_sysctl_init("vm", vm_page_writeback_sysctls);
2178+
#endif
20962179
}
20972180

20982181
/**

0 commit comments

Comments
 (0)