Skip to content

Commit b1e8d71

Browse files
yukaixiongJoelgranados
authored andcommitted
mm: util: move sysctls to mm/util.c
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 <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Joel Granados <[email protected]>
1 parent 538d5ba commit b1e8d71

File tree

4 files changed

+59
-58
lines changed

4 files changed

+59
-58
lines changed

include/linux/mm.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,6 @@ extern int sysctl_max_map_count;
205205
extern unsigned long sysctl_user_reserve_kbytes;
206206
extern unsigned long sysctl_admin_reserve_kbytes;
207207

208-
extern int sysctl_overcommit_memory;
209-
extern int sysctl_overcommit_ratio;
210-
extern unsigned long sysctl_overcommit_kbytes;
211-
212-
int overcommit_ratio_handler(const struct ctl_table *, int, void *, size_t *,
213-
loff_t *);
214-
int overcommit_kbytes_handler(const struct ctl_table *, int, void *, size_t *,
215-
loff_t *);
216-
int overcommit_policy_handler(const struct ctl_table *, int, void *, size_t *,
217-
loff_t *);
218-
219208
#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
220209
#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
221210
#define folio_page_idx(folio, p) (page_to_pfn(p) - folio_pfn(folio))

include/linux/mman.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
| MAP_HUGE_1GB)
6060

6161
extern int sysctl_overcommit_memory;
62-
extern int sysctl_overcommit_ratio;
63-
extern unsigned long sysctl_overcommit_kbytes;
6462
extern struct percpu_counter vm_committed_as;
6563

6664
#ifdef CONFIG_SMP

kernel/sysctl.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,29 +2020,6 @@ static const struct ctl_table kern_table[] = {
20202020
};
20212021

20222022
static const struct ctl_table vm_table[] = {
2023-
{
2024-
.procname = "overcommit_memory",
2025-
.data = &sysctl_overcommit_memory,
2026-
.maxlen = sizeof(sysctl_overcommit_memory),
2027-
.mode = 0644,
2028-
.proc_handler = overcommit_policy_handler,
2029-
.extra1 = SYSCTL_ZERO,
2030-
.extra2 = SYSCTL_TWO,
2031-
},
2032-
{
2033-
.procname = "overcommit_ratio",
2034-
.data = &sysctl_overcommit_ratio,
2035-
.maxlen = sizeof(sysctl_overcommit_ratio),
2036-
.mode = 0644,
2037-
.proc_handler = overcommit_ratio_handler,
2038-
},
2039-
{
2040-
.procname = "overcommit_kbytes",
2041-
.data = &sysctl_overcommit_kbytes,
2042-
.maxlen = sizeof(sysctl_overcommit_kbytes),
2043-
.mode = 0644,
2044-
.proc_handler = overcommit_kbytes_handler,
2045-
},
20462023
{
20472024
.procname = "dirtytime_expire_seconds",
20482025
.data = &dirtytime_expire_interval,
@@ -2123,20 +2100,6 @@ static const struct ctl_table vm_table[] = {
21232100
.extra1 = SYSCTL_ZERO,
21242101
},
21252102
#endif
2126-
{
2127-
.procname = "user_reserve_kbytes",
2128-
.data = &sysctl_user_reserve_kbytes,
2129-
.maxlen = sizeof(sysctl_user_reserve_kbytes),
2130-
.mode = 0644,
2131-
.proc_handler = proc_doulongvec_minmax,
2132-
},
2133-
{
2134-
.procname = "admin_reserve_kbytes",
2135-
.data = &sysctl_admin_reserve_kbytes,
2136-
.maxlen = sizeof(sysctl_admin_reserve_kbytes),
2137-
.mode = 0644,
2138-
.proc_handler = proc_doulongvec_minmax,
2139-
},
21402103
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
21412104
{
21422105
.procname = "mmap_rnd_bits",

mm/util.c

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/security.h>
1313
#include <linux/swap.h>
1414
#include <linux/swapops.h>
15+
#include <linux/sysctl.h>
1516
#include <linux/mman.h>
1617
#include <linux/hugetlb.h>
1718
#include <linux/vmalloc.h>
@@ -906,14 +907,16 @@ int folio_mc_copy(struct folio *dst, struct folio *src)
906907
EXPORT_SYMBOL(folio_mc_copy);
907908

908909
int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS;
909-
int sysctl_overcommit_ratio __read_mostly = 50;
910-
unsigned long sysctl_overcommit_kbytes __read_mostly;
910+
static int sysctl_overcommit_ratio __read_mostly = 50;
911+
static unsigned long sysctl_overcommit_kbytes __read_mostly;
911912
int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
912913
unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
913914
unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
914915

915-
int overcommit_ratio_handler(const struct ctl_table *table, int write, void *buffer,
916-
size_t *lenp, loff_t *ppos)
916+
#ifdef CONFIG_SYSCTL
917+
918+
static int overcommit_ratio_handler(const struct ctl_table *table, int write,
919+
void *buffer, size_t *lenp, loff_t *ppos)
917920
{
918921
int ret;
919922

@@ -928,8 +931,8 @@ static void sync_overcommit_as(struct work_struct *dummy)
928931
percpu_counter_sync(&vm_committed_as);
929932
}
930933

931-
int overcommit_policy_handler(const struct ctl_table *table, int write, void *buffer,
932-
size_t *lenp, loff_t *ppos)
934+
static int overcommit_policy_handler(const struct ctl_table *table, int write,
935+
void *buffer, size_t *lenp, loff_t *ppos)
933936
{
934937
struct ctl_table t;
935938
int new_policy = -1;
@@ -964,8 +967,8 @@ int overcommit_policy_handler(const struct ctl_table *table, int write, void *bu
964967
return ret;
965968
}
966969

967-
int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *buffer,
968-
size_t *lenp, loff_t *ppos)
970+
static int overcommit_kbytes_handler(const struct ctl_table *table, int write,
971+
void *buffer, size_t *lenp, loff_t *ppos)
969972
{
970973
int ret;
971974

@@ -975,6 +978,54 @@ int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *bu
975978
return ret;
976979
}
977980

981+
static const struct ctl_table util_sysctl_table[] = {
982+
{
983+
.procname = "overcommit_memory",
984+
.data = &sysctl_overcommit_memory,
985+
.maxlen = sizeof(sysctl_overcommit_memory),
986+
.mode = 0644,
987+
.proc_handler = overcommit_policy_handler,
988+
.extra1 = SYSCTL_ZERO,
989+
.extra2 = SYSCTL_TWO,
990+
},
991+
{
992+
.procname = "overcommit_ratio",
993+
.data = &sysctl_overcommit_ratio,
994+
.maxlen = sizeof(sysctl_overcommit_ratio),
995+
.mode = 0644,
996+
.proc_handler = overcommit_ratio_handler,
997+
},
998+
{
999+
.procname = "overcommit_kbytes",
1000+
.data = &sysctl_overcommit_kbytes,
1001+
.maxlen = sizeof(sysctl_overcommit_kbytes),
1002+
.mode = 0644,
1003+
.proc_handler = overcommit_kbytes_handler,
1004+
},
1005+
{
1006+
.procname = "user_reserve_kbytes",
1007+
.data = &sysctl_user_reserve_kbytes,
1008+
.maxlen = sizeof(sysctl_user_reserve_kbytes),
1009+
.mode = 0644,
1010+
.proc_handler = proc_doulongvec_minmax,
1011+
},
1012+
{
1013+
.procname = "admin_reserve_kbytes",
1014+
.data = &sysctl_admin_reserve_kbytes,
1015+
.maxlen = sizeof(sysctl_admin_reserve_kbytes),
1016+
.mode = 0644,
1017+
.proc_handler = proc_doulongvec_minmax,
1018+
},
1019+
};
1020+
1021+
static int __init init_vm_util_sysctls(void)
1022+
{
1023+
register_sysctl_init("vm", util_sysctl_table);
1024+
return 0;
1025+
}
1026+
subsys_initcall(init_vm_util_sysctls);
1027+
#endif /* CONFIG_SYSCTL */
1028+
9781029
/*
9791030
* Committed memory limit enforced when OVERCOMMIT_NEVER policy is used
9801031
*/

0 commit comments

Comments
 (0)