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)
906907EXPORT_SYMBOL (folio_mc_copy );
907908
908909int 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 ;
911912int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT ;
912913unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17 ; /* 128MB */
913914unsigned 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