hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I9K8D1 CVE: NA
--------------------------------
Introduce a sysctl named vm_swap_extension to add control of swap feature.
In global reclaim, set swappiness to 0 doesn't means swapout disabled, which is often misused by user. Add a control to really disable swapout by setting vm_swap_extension = 1.
Signed-off-by: Liu Shixin liushixin2@huawei.com --- Documentation/admin-guide/sysctl/vm.rst | 11 +++++++++ include/linux/swap.h | 3 +++ kernel/sysctl.c | 11 +++++++++ mm/Kconfig | 6 +++++ mm/vmscan.c | 30 +++++++++++++++++++++++++ 5 files changed, 61 insertions(+)
diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst index b508acfdde2e..3e043b9aa4b4 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -70,6 +70,7 @@ Currently, these files are in /proc/sys/vm: - stat_refresh - numa_stat - swappiness +- swap_extension - unprivileged_userfaultfd - user_reserve_kbytes - vfs_cache_pressure @@ -928,6 +929,16 @@ At 0, the kernel will not initiate swap until the amount of free and file-backed pages is less than the high watermark in a zone.
+swap_extension +============== + +This control is used for some swap extension feature. The default value is +0. Now support one extension which is to disable global swap which can't +acquired by swappiness. + +To disable global swap: + echo 1 > /proc/sys/vm/swap_extension + unprivileged_userfaultfd ========================
diff --git a/include/linux/swap.h b/include/linux/swap.h index 8e62c870517c..3241ce0a556a 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -390,6 +390,9 @@ extern unsigned long mem_cgroup_shrink_node(struct mem_cgroup *mem, unsigned long *nr_scanned); extern unsigned long shrink_all_memory(unsigned long nr_pages); extern int vm_swappiness; +#ifdef CONFIG_SWAP_EXTENSION +extern int vm_swap_extension; +#endif extern int remove_mapping(struct address_space *mapping, struct page *page);
extern unsigned long reclaim_pages(struct list_head *page_list); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index f3f43b2def7f..0eea66af812a 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2958,6 +2958,17 @@ static struct ctl_table vm_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = &two_hundred, }, +#ifdef CONFIG_SWAP_EXTENSION + { + .procname = "swap_extension", + .data = &vm_swap_extension, + .maxlen = sizeof(vm_swap_extension), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif #ifdef CONFIG_NUMA { .procname = "numa_stat", diff --git a/mm/Kconfig b/mm/Kconfig index 70c85533aada..0f9209cd969b 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -568,6 +568,12 @@ config PAGE_CACHE_LIMIT
if unsure, say N to disable the PAGE_CACHE_LIMIT.
+config SWAP_EXTENSION + bool "Support some swap extension feature" + depends on MMU && SYSCTL + default n + help + Add a sysctl swap_extension to support some swap extension feature. config CMA bool "Contiguous Memory Allocator" depends on MMU diff --git a/mm/vmscan.c b/mm/vmscan.c index 044bf496885b..0979dad6180b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -182,6 +182,27 @@ struct scan_control { */ int vm_swappiness = 60;
+#ifdef CONFIG_SWAP_EXTENSION + +#define VM_GLOBAL_SWAP_DISABLE 1 + +int vm_swap_extension; + +/* + * In global reclaim, set swappiness to 0 doesn't means swapout + * disabled, which is often misused by user. + */ +static bool should_disable_global_swap(void) +{ + return (vm_swap_extension & VM_GLOBAL_SWAP_DISABLE); +} +#else +static bool should_disable_global_swap(void) +{ + return false; +} +#endif + static void set_task_reclaim_state(struct task_struct *task, struct reclaim_state *rs) { @@ -2490,6 +2511,15 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, goto out; }
+ /* + * In global reclaim, set swappiness to 0 doesn't means swapout + * disabled, which is often misused by user. + */ + if (!cgroup_reclaim(sc) && should_disable_global_swap()) { + scan_balance = SCAN_FILE; + goto out; + } + /* * Do not apply any pressure balancing cleverness when the * system is close to OOM, scan both anon and file equally