Skip to content

Commit c843966

Browse files
hnaztorvalds
authored andcommitted
mm: allow swappiness that prefers reclaiming anon over the file workingset
With the advent of fast random IO devices (SSDs, PMEM) and in-memory swap devices such as zswap, it's possible for swap to be much faster than filesystems, and for swapping to be preferable over thrashing filesystem caches. Allow setting swappiness - which defines the rough relative IO cost of cache misses between page cache and swap-backed pages - to reflect such situations by making the swap-preferred range configurable. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Rik van Riel <riel@surriel.com> Link: http://lkml.kernel.org/r/20200520232525.798933-4-hannes@cmpxchg.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 497a6c1 commit c843966

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

Documentation/admin-guide/sysctl/vm.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -831,14 +831,27 @@ tooling to work, you can do::
831831
swappiness
832832
==========
833833

834-
This control is used to define how aggressive the kernel will swap
835-
memory pages. Higher values will increase aggressiveness, lower values
836-
decrease the amount of swap. A value of 0 instructs the kernel not to
837-
initiate swap until the amount of free and file-backed pages is less
838-
than the high water mark in a zone.
834+
This control is used to define the rough relative IO cost of swapping
835+
and filesystem paging, as a value between 0 and 200. At 100, the VM
836+
assumes equal IO cost and will thus apply memory pressure to the page
837+
cache and swap-backed pages equally; lower values signify more
838+
expensive swap IO, higher values indicates cheaper.
839+
840+
Keep in mind that filesystem IO patterns under memory pressure tend to
841+
be more efficient than swap's random IO. An optimal value will require
842+
experimentation and will also be workload-dependent.
839843

840844
The default value is 60.
841845

846+
For in-memory swap, like zram or zswap, as well as hybrid setups that
847+
have swap on faster devices than the filesystem, values beyond 100 can
848+
be considered. For example, if the random IO against the swap device
849+
is on average 2x faster than IO from the filesystem, swappiness should
850+
be 133 (x + 2x = 200, 2x = 133.33).
851+
852+
At 0, the kernel will not initiate swap until the amount of free and
853+
file-backed pages is less than the high watermark in a zone.
854+
842855

843856
unprivileged_userfaultfd
844857
========================

kernel/sysctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static unsigned long zero_ul;
131131
static unsigned long one_ul = 1;
132132
static unsigned long long_max = LONG_MAX;
133133
static int one_hundred = 100;
134+
static int two_hundred = 200;
134135
static int one_thousand = 1000;
135136
#ifdef CONFIG_PRINTK
136137
static int ten_thousand = 10000;
@@ -1391,7 +1392,7 @@ static struct ctl_table vm_table[] = {
13911392
.mode = 0644,
13921393
.proc_handler = proc_dointvec_minmax,
13931394
.extra1 = SYSCTL_ZERO,
1394-
.extra2 = &one_hundred,
1395+
.extra2 = &two_hundred,
13951396
},
13961397
#ifdef CONFIG_HUGETLB_PAGE
13971398
{

mm/vmscan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct scan_control {
161161
#endif
162162

163163
/*
164-
* From 0 .. 100. Higher means more swappy.
164+
* From 0 .. 200. Higher means more swappy.
165165
*/
166166
int vm_swappiness = 60;
167167
/*

0 commit comments

Comments
 (0)