As @Signalrunner already mentioned, using 1 for these values will not help you.
cc @nikgnomic as I see you’re making the same mistake.
TL;DR
Swapping is normal: the kernel knows better than you when to swap stuff out. Don’t focus on not having any swap at all!
The Long version:
You will always see some swapping going on, because the kernel knows better than you and will swap unused services out; so you’re better off debugging what’s not needed by looking at what gets swapped out exactly and deleting / disabling that instead of trying to having no swapping happen at all!
E.G. If you’ve installed samba but only wanted the client and not the server, well, guess what? The server will be swapped out because it’s not being used.
So, please use these (pretty self-explanatory) values to swap late, but once swapped out, don’t swap in again aggressively as that slows down things as well:
cat /etc/sysctl.d/30-swap_usage.conf
# Fabrizio: 2014-03-02: change "swappiness" from default 60 to 10:
# Theoretically, only swap when RAM usage reaches around 80 or 90 percent
# Fabrizio: 2014-03-29: lower to 5 as swapping is still occurring with low mem usage
# Fabrizio: 2014-11-21: Bring back up to 10 as vm.vfs_cache_pressure was introduced
vm.swappiness = 10
# Fabrizio: 2014-11-29: Lower vm.vfs_cache_pressure to 75%
# (once swapped, probably not immediately needed any more)
#
# This value used to be a percentage value that controls the tendency of the kernel to reclaim
# the memory which is used for caching of directory and inode objects.
#
# At the default value of vfs_cache_pressure=100 the kernel will attempt to
# reclaim dentries and inodes at a "fair" rate with respect to pagecache and
# swapcache reclaim. Decreasing vfs_cache_pressure causes the kernel to prefer
# to retain dentry and inode caches.
# Nowadays the value can be >100!
vm.vfs_cache_pressure = 75
Also know that hibernation works by swapping all programs out to disk and then shutting down, so when you come out of hibernation, any swapped-out applications not taking any CPU cycles will stay swapped until you use them!This is by design!
(I.E. Don’t debug swapping when coming out of hibernation: the figures always look awful!)
How to debug what is getting swapped, you ask?
sudo nano --backup /usr/local/bin/swapusage
copy-paste this:
#!/bin/sh
for szFile in /proc/*/status ; do
awk '/VmSwap|Name/{printf $2 "\t" $3}END{ print "" }' $szFile
done | sort --key 2 --numeric --reverse | more
Execute:
chmod a+x /usr/local/bin/swapusage
Execute:
swapusage
Start debugging what gets swapped out and disable it.
E.G. On my system; right now; coming out of hibernate yesterday:
Result of free --human:
total used free shared buff/cache available
Mem: 15Gi 5.8Gi 678Mi 431Mi 9.1Gi 9.1Gi
Swap: 19Gi 283Mi 19Gi
Result of swapusage:
Application
size
unit
qbittorrent
81968
kB
telegram-deskto
32704
kB
plasmashell
17132
kB
dolphin
9736
kB
konsole
7792
kB
geany
6280
kB
vlc
6196
kB
mono
5944
kB
Xorg
5928
kB
baloorunner
5260
kB
xdg-desktop-por
5000
kB
bash
3928
kB
kglobalaccel5
3600
kB
xdg-desktop-por
2440
kB
kactivitymanage
1684
kB
bash
1264
kB
skypeforlinux
1216
kB
kdeconnectd
1172
kB
gsettings-helpe
1084
kB
kdeinit5
948
kB
pulseaudio
932
kB
file.so
884
kB
file.so
884
kB
file.so
880
kB
systemd
704
kB
But:
I have a lot of finished torrents that I should convert to a lower resolution and then delete but they’re not taking up any RAM now.
There are a lot of conversations inside Telegram that are not active right now, so I’ll see a slight delay when opening those
I dunno why plasmashell is taking up that amount of swap
Dolphin has not been used for a while on my 4th desktop
bash: I have 3 consoles open but only one was being used recently
etc, etc
I was only answering the question of setting the values permanently using the values OP wanted
I don’t expect OP will be happy with the values requested, but it will help towards finding the optimal setting one way or another
I have posted before about swappiness value but users still try things that may not be good, I did the same myself when I was trying to find the right balance on settings
I have 8GB RAM and found vm.swappiness = 10 to be optimal for my use
I tried lower values 10 but found it delayed swap too much and system could stall hard for a moment. I found swapping too late to be just as annoying as swapping too early
Folks, I’m just marking this as solved. it looks like the underlying issue on this thread was solved long time ago. Probably the OP forgot to mark this thread as solved.
I don’t think there is a need to revive this discussion.