My original problem with swap(piness) was that it was swapping too often (even with swappiness=1
! ).
I also thought 0 would turn off the swappiness - which was a misconception,
Swap still works even if you set sudo sysctl -w vm.swappiness=0
! :-)
(To set permanently, edit /etc/sysctl.conf
and add/update vm.swappiness = 0
- for GUI text editor I recommend a "linux notepad" "gedit", you can then do sudo gedit /etc/sysctl.conf
)
Only with swappiness 0
it started to behave more like one would expect (swapping starting at about 98% of RAM full), however I am still experiencing one more problem - and that when enough RAM is actually freed again, the swap does not automatically go back to RAM, not even over time.
Of course you could manually do sudo swapoff -a; sudo swapon -a
every time which turns off the swap which ultimatelly forces the swap to be emptied out to the RAM and then swap gets started again.
However that's unhandy for 2 reasons a) the swap gets turned off for a moment b) it's a manual extra checking/running
Is there a way how to achieve this in some, preferably "native", way automatically?
[ "$(free | awk '/Swap:/{print $3}')" -lt "$(free | awk '/Mem:/{print $7}')" ] && echo "Free memory more than used swap" || echo "Free memory less than used swap"
– Raffa Jun 21 '21 at 11:22free -h
andswapon -s
andsysctl vm.swappiness
. – heynnema Jun 21 '21 at 12:59