Skip to content

Commit 637e47d

Browse files
zhanglianjie-163sfrothwell
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. 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: Stephen Rothwell <[email protected]>
1 parent b693e9b commit 637e47d

File tree

3 files changed

+89
-94
lines changed

3 files changed

+89
-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;
@@ -2401,55 +2399,6 @@ static struct ctl_table vm_table[] = {
24012399
.proc_handler = proc_dointvec_minmax,
24022400
.extra1 = SYSCTL_ZERO,
24032401
},
2404-
{
2405-
.procname = "dirty_background_ratio",
2406-
.data = &dirty_background_ratio,
2407-
.maxlen = sizeof(dirty_background_ratio),
2408-
.mode = 0644,
2409-
.proc_handler = dirty_background_ratio_handler,
2410-
.extra1 = SYSCTL_ZERO,
2411-
.extra2 = SYSCTL_ONE_HUNDRED,
2412-
},
2413-
{
2414-
.procname = "dirty_background_bytes",
2415-
.data = &dirty_background_bytes,
2416-
.maxlen = sizeof(dirty_background_bytes),
2417-
.mode = 0644,
2418-
.proc_handler = dirty_background_bytes_handler,
2419-
.extra1 = SYSCTL_LONG_ONE,
2420-
},
2421-
{
2422-
.procname = "dirty_ratio",
2423-
.data = &vm_dirty_ratio,
2424-
.maxlen = sizeof(vm_dirty_ratio),
2425-
.mode = 0644,
2426-
.proc_handler = dirty_ratio_handler,
2427-
.extra1 = SYSCTL_ZERO,
2428-
.extra2 = SYSCTL_ONE_HUNDRED,
2429-
},
2430-
{
2431-
.procname = "dirty_bytes",
2432-
.data = &vm_dirty_bytes,
2433-
.maxlen = sizeof(vm_dirty_bytes),
2434-
.mode = 0644,
2435-
.proc_handler = dirty_bytes_handler,
2436-
.extra1 = (void *)&dirty_bytes_min,
2437-
},
2438-
{
2439-
.procname = "dirty_writeback_centisecs",
2440-
.data = &dirty_writeback_interval,
2441-
.maxlen = sizeof(dirty_writeback_interval),
2442-
.mode = 0644,
2443-
.proc_handler = dirty_writeback_centisecs_handler,
2444-
},
2445-
{
2446-
.procname = "dirty_expire_centisecs",
2447-
.data = &dirty_expire_interval,
2448-
.maxlen = sizeof(dirty_expire_interval),
2449-
.mode = 0644,
2450-
.proc_handler = proc_dointvec_minmax,
2451-
.extra1 = SYSCTL_ZERO,
2452-
},
24532402
{
24542403
.procname = "dirtytime_expire_seconds",
24552404
.data = &dirtytime_expire_interval,
@@ -2621,13 +2570,6 @@ static struct ctl_table vm_table[] = {
26212570
.extra1 = SYSCTL_ZERO,
26222571
},
26232572
#endif
2624-
{
2625-
.procname = "laptop_mode",
2626-
.data = &laptop_mode,
2627-
.maxlen = sizeof(laptop_mode),
2628-
.mode = 0644,
2629-
.proc_handler = proc_dointvec_jiffies,
2630-
},
26312573
{
26322574
.procname = "vfs_cache_pressure",
26332575
.data = &sysctl_vfs_cache_pressure,
@@ -2725,17 +2667,6 @@ static struct ctl_table vm_table[] = {
27252667
.extra1 = SYSCTL_ZERO,
27262668
},
27272669
#endif
2728-
#ifdef CONFIG_HIGHMEM
2729-
{
2730-
.procname = "highmem_is_dirtyable",
2731-
.data = &vm_highmem_is_dirtyable,
2732-
.maxlen = sizeof(vm_highmem_is_dirtyable),
2733-
.mode = 0644,
2734-
.proc_handler = proc_dointvec_minmax,
2735-
.extra1 = SYSCTL_ZERO,
2736-
.extra2 = SYSCTL_ONE,
2737-
},
2738-
#endif
27392670
#ifdef CONFIG_MEMORY_FAILURE
27402671
{
27412672
.procname = "memory_failure_early_kill",

mm/page-writeback.c

Lines changed: 89 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
@@ -503,7 +506,7 @@ bool node_dirty_ok(struct pglist_data *pgdat)
503506
return nr_pages <= limit;
504507
}
505508

506-
int dirty_background_ratio_handler(struct ctl_table *table, int write,
509+
static int dirty_background_ratio_handler(struct ctl_table *table, int write,
507510
void *buffer, size_t *lenp, loff_t *ppos)
508511
{
509512
int ret;
@@ -514,7 +517,7 @@ int dirty_background_ratio_handler(struct ctl_table *table, int write,
514517
return ret;
515518
}
516519

517-
int dirty_background_bytes_handler(struct ctl_table *table, int write,
520+
static int dirty_background_bytes_handler(struct ctl_table *table, int write,
518521
void *buffer, size_t *lenp, loff_t *ppos)
519522
{
520523
int ret;
@@ -525,7 +528,7 @@ int dirty_background_bytes_handler(struct ctl_table *table, int write,
525528
return ret;
526529
}
527530

528-
int dirty_ratio_handler(struct ctl_table *table, int write, void *buffer,
531+
static int dirty_ratio_handler(struct ctl_table *table, int write, void *buffer,
529532
size_t *lenp, loff_t *ppos)
530533
{
531534
int old_ratio = vm_dirty_ratio;
@@ -539,7 +542,7 @@ int dirty_ratio_handler(struct ctl_table *table, int write, void *buffer,
539542
return ret;
540543
}
541544

542-
int dirty_bytes_handler(struct ctl_table *table, int write,
545+
static int dirty_bytes_handler(struct ctl_table *table, int write,
543546
void *buffer, size_t *lenp, loff_t *ppos)
544547
{
545548
unsigned long old_bytes = vm_dirty_bytes;
@@ -1996,7 +1999,7 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
19961999
/*
19972000
* sysctl handler for /proc/sys/vm/dirty_writeback_centisecs
19982001
*/
1999-
int dirty_writeback_centisecs_handler(struct ctl_table *table, int write,
2002+
static int dirty_writeback_centisecs_handler(struct ctl_table *table, int write,
20002003
void *buffer, size_t *length, loff_t *ppos)
20012004
{
20022005
unsigned int old_interval = dirty_writeback_interval;
@@ -2081,6 +2084,79 @@ static int page_writeback_cpu_online(unsigned int cpu)
20812084
return 0;
20822085
}
20832086

2087+
#ifdef CONFIG_SYSCTL
2088+
static struct ctl_table vm_page_writeback_sysctls[] = {
2089+
{
2090+
.procname = "dirty_background_ratio",
2091+
.data = &dirty_background_ratio,
2092+
.maxlen = sizeof(dirty_background_ratio),
2093+
.mode = 0644,
2094+
.proc_handler = dirty_background_ratio_handler,
2095+
.extra1 = SYSCTL_ZERO,
2096+
.extra2 = SYSCTL_ONE_HUNDRED,
2097+
},
2098+
{
2099+
.procname = "dirty_background_bytes",
2100+
.data = &dirty_background_bytes,
2101+
.maxlen = sizeof(dirty_background_bytes),
2102+
.mode = 0644,
2103+
.proc_handler = dirty_background_bytes_handler,
2104+
.extra1 = SYSCTL_LONG_ONE,
2105+
},
2106+
{
2107+
.procname = "dirty_ratio",
2108+
.data = &vm_dirty_ratio,
2109+
.maxlen = sizeof(vm_dirty_ratio),
2110+
.mode = 0644,
2111+
.proc_handler = dirty_ratio_handler,
2112+
.extra1 = SYSCTL_ZERO,
2113+
.extra2 = SYSCTL_ONE_HUNDRED,
2114+
},
2115+
{
2116+
.procname = "dirty_bytes",
2117+
.data = &vm_dirty_bytes,
2118+
.maxlen = sizeof(vm_dirty_bytes),
2119+
.mode = 0644,
2120+
.proc_handler = dirty_bytes_handler,
2121+
.extra1 = (void *)&dirty_bytes_min,
2122+
},
2123+
{
2124+
.procname = "dirty_writeback_centisecs",
2125+
.data = &dirty_writeback_interval,
2126+
.maxlen = sizeof(dirty_writeback_interval),
2127+
.mode = 0644,
2128+
.proc_handler = dirty_writeback_centisecs_handler,
2129+
},
2130+
{
2131+
.procname = "dirty_expire_centisecs",
2132+
.data = &dirty_expire_interval,
2133+
.maxlen = sizeof(dirty_expire_interval),
2134+
.mode = 0644,
2135+
.proc_handler = proc_dointvec_minmax,
2136+
.extra1 = SYSCTL_ZERO,
2137+
},
2138+
#ifdef CONFIG_HIGHMEM
2139+
{
2140+
.procname = "highmem_is_dirtyable",
2141+
.data = &vm_highmem_is_dirtyable,
2142+
.maxlen = sizeof(vm_highmem_is_dirtyable),
2143+
.mode = 0644,
2144+
.proc_handler = proc_dointvec_minmax,
2145+
.extra1 = SYSCTL_ZERO,
2146+
.extra2 = SYSCTL_ONE,
2147+
},
2148+
#endif
2149+
{
2150+
.procname = "laptop_mode",
2151+
.data = &laptop_mode,
2152+
.maxlen = sizeof(laptop_mode),
2153+
.mode = 0644,
2154+
.proc_handler = proc_dointvec_jiffies,
2155+
},
2156+
{}
2157+
};
2158+
#endif
2159+
20842160
/*
20852161
* Called early on to tune the page writeback dirty limits.
20862162
*
@@ -2105,6 +2181,9 @@ void __init page_writeback_init(void)
21052181
page_writeback_cpu_online, NULL);
21062182
cpuhp_setup_state(CPUHP_MM_WRITEBACK_DEAD, "mm/writeback:dead", NULL,
21072183
page_writeback_cpu_online);
2184+
#ifdef CONFIG_SYSCTL
2185+
register_sysctl_init("vm", vm_page_writeback_sysctls);
2186+
#endif
21082187
}
21092188

21102189
/**

0 commit comments

Comments
 (0)