Commit 23b8e18f authored by Liu Shixin's avatar Liu Shixin
Browse files

mm/vmscan: introduce vm_swap_extension sysctl

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: default avatarLiu Shixin <liushixin2@huawei.com>
parent f300accf
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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
========================

+3 −0
Original line number Diff line number Diff line
@@ -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);
+11 −0
Original line number Diff line number Diff line
@@ -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",
+6 −0
Original line number Diff line number Diff line
@@ -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
+30 −0
Original line number Diff line number Diff line
@@ -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