As note: `vm.swappiness = 0` does not prevent swapping, but minimizes threshold of it

There are kernel parameters to customize kernel operation mode. One of them is vm.swappiness.
What value to prefer to minimize page/swap file usage vm.swappiness: 1 or 0?

Rumors and outdated info

The vm.swappiness value of 0 was discussed many times on Internet, including here Swap consumed despite of swappiness=0 - #2 by linux-aarhus. I saw many posts where were mentioned that β€˜swapping/paging is disabled by that option, use vm.swappiness = 1’, a numerous posts in opposite vm.swappiness = 0 minimizzes of swap usage.

As note: vm.swappiness = 0 does not turn off swapping/paging feature, but it minimizes swap file usage.

details/evidence (system info terminal outputs)

Let’s try to sync with modern reality:

❯ /usr/bin/free -k
               total        used        free      shared  buff/cache   available
Mem:        65489500     4317952      571268     1337692    60600280    59052612
Swap:         524284         268      524016

❯ /usr/bin/free -g
               total        used        free      shared  buff/cache   available
Mem:              62           4           0           1          57          56
Swap:              0           0           0

❯ uname -r
6.2.0-1-MANJARO

❯ pacman -Qi linux62 | grep Ver 
Version         : 6.2.0rc3-1

❯ sudo sysctl -a | grep swap
vm.swappiness = 0

❯ cat /proc/sys/vm/swappiness
0

❯ uptime
 10:42:01 up 11:33,  4 users,  load average: 0.66, 0.75, 0.81

❯ uptime -p
up 11 hours, 34 minutes

❯ swapon -a -v
swapon: /swap/swapfile: already active -- ignored

❯ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a device; this may
# be used with UUID= as a more robust way to name devices that works even if
# disks are added and removed. See fstab(5).
#
# <file system>             <mount point>  <type>  <options>  <dump>  <pass>
UUID=261E-4AE1                            /boot/efi      vfat    umask=0077 0 2
/dev/mapper/luks-4620125f-31e5-4d3a-ac65-3104599474aa /              btrfs   subvol=/@,defaults,discard=async,ssd 0 0
/dev/mapper/luks-4620125f-31e5-4d3a-ac65-3104599474aa /home          btrfs   subvol=/@home,defaults,discard=async,ssd 0 0
/dev/mapper/luks-4620125f-31e5-4d3a-ac65-3104599474aa /var/cache     btrfs   subvol=/@cache,defaults,discard=async,ssd 0 0
/dev/mapper/luks-4620125f-31e5-4d3a-ac65-3104599474aa /var/log       btrfs   subvol=/@log,defaults,discard=async,ssd 0 0
/dev/mapper/luks-4620125f-31e5-4d3a-ac65-3104599474aa /swap          btrfs   subvol=/@swap,defaults,discard=async,ssd 0 0
/swap/swapfile                            swap           swap    defaults,noatime 0 0
tmpfs                                     /tmp           tmpfs   defaults,noatime,mode=1777 0 0

❯ cat /proc/meminfo
MemTotal:       65489500 kB
MemFree:          539940 kB
MemAvailable:   58862516 kB
Buffers:             784 kB
Cached:         60213944 kB
SwapCached:            0 kB
Active:         49295456 kB
Inactive:       14509960 kB
Active(anon):    3657472 kB
Inactive(anon):  1339308 kB
Active(file):   45637984 kB
Inactive(file): 13170652 kB
Unevictable:      456424 kB
Mlocked:               0 kB
SwapTotal:        524284 kB
SwapFree:         524016 kB
Zswap:               160 kB
Zswapped:            256 kB
Dirty:              1076 kB
Writeback:             0 kB
AnonPages:       3970888 kB
Mapped:         35083436 kB
Shmem:           1406092 kB
KReclaimable:     226376 kB
Slab:             352904 kB
SReclaimable:     226376 kB
SUnreclaim:       126528 kB
KernelStack:       16512 kB
PageTables:       135996 kB
SecPageTables:         0 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    33269032 kB
Committed_AS:   16350036 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       56168 kB
VmallocChunk:          0 kB
Percpu:             2608 kB
HardwareCorrupted:     0 kB
AnonHugePages:    593920 kB
ShmemHugePages:   821248 kB
ShmemPmdMapped:        0 kB
FileHugePages:     96256 kB
FilePmdMapped:     94208 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      299780 kB
DirectMap2M:    17160192 kB
DirectMap1G:    49283072 kB                   

❯ neofetch
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   m@pc 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   ---- 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   OS: Manjaro Linux x86_64 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   Kernel: 6.2.0-1-MANJARO 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ            β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   Uptime: 11 hours, 49 mins 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   Packages: 1095 (pacman) 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   Shell: bash 5.1.16 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   Resolution: 1920x1080 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   DE: Plasma 5.26.5 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   WM: KWin 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   Theme: [Plasma], Breeze [GTK2/3] 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   Icons: [Plasma], breeze-dark [GTK2/3] 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   Terminal: konsole 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   Terminal Font: Hack 11 
                               CPU: 11th Gen Intel i7-1195G7 (4) @ 2.900GHz 
                               GPU: Intel TigerLake-LP GT2 [Iris Xe Graphics] 
                               Memory: 5873MiB / 63954MiB 

❯ date
Mon 16 Jan 11:01:01 MSK 2023

❯ pacman-mirrors --get-branch
unstable

So at least current behavior is not 'swapping/paging '.

PS
I use default vm.vfs_cache_pressure value:

❯ sudo sysctl -a | grep "vm.vfs_cache_pressure"
vm.vfs_cache_pressure = 100

❯ cat /proc/sys/vm/vfs_cache_pressure
100

One of points of this topic could be:
if you want to minimize swapping threshold setup the vm.swappiness parameter as 0 value, not as 1.

How to setup the kernel parameter: Swap - ArchWiki

16-Jan-2023,
swapping feature used as swap to file,
Linux kernel 6.2-RC3 (newest on the moment of that posting),
Manjaro Linux (KDE),
unstable branch of updates.

This has been discussed ad nauseam - perhaps most was in the now gone archive.

:yawning_face:

Good conclusion, but why do you write it here? It left me with an impression that you use this post as a personal, but public note. Just like a Blog entry. Maybe better write a blog?

And using the manjaro forum as a digital notebook or as blog is against the rules. Just saying.

Your impression is right: just want to share β€œinvestigation”/test data.

Sorry, did not know that it against the Rules. Also as Frede said, that it was discussed many times before. And I used unstable non-yet-released kernel version (what if that effect is a bug? then it is misleading info). Please moderate it then: remove this topic.

Thank you for bringing attention to this.

Copy that.

1 Like