DATE CHECKED THIS PAGE WAS VALID: 13/09/2023
The default swappiness of Linux in general is 60 which works very well. 100 means it moves things out of RAM into swap as soon as possible and 0 means try avoid using swap.
In General I have tried different values but found 60 offers the most convenient value, however sometimes I change it to 70 in order to use zramswap more aggressively if memory is used heavily. However if you want to experiment yourself you can try this:
Check current value:
cat /proc/sys/vm/swappiness
Change value temporarily until reboot. You can type the above command again to see it changed:
sudo sysctl vm.swappiness=50
Change permanently:
sudo nano /etc/sysctl.conf
if the 'vm.swappiness=xx' line does not exist in that file, then add it to the bottom of the file (must not be commented out) and change value as appropriate eg: vm.swappiness=50
ctrl x and y to save.
Notes: If anyone has any other notes or useful commands regarding swap, add them here.
TLDR: 60 or 70 are good values. 60 for normal systems, 70 if you use zramswap and lots of memory for some reason (eg:VM's). Im currently using 70 normally.
Notes: A value of 0 means avoid using swap as much as possible. A value of 200 means use swap for everything. Typical (sane) values would be between 50-150. If you have a raspberry pi with 1GB RAM, it may be beneficial to use a swapiness value higher than 100 eg: 101. Using 101 will mean it will prefer to move items into swap when possible. A value of 100 treats swap and RAM as identical priority and will be randomly given to one or the other. Reason on a pi you might want to push items into ram slightly more is that there is little memory and in addition if you configure zramswap this will free up real RAM and prevent the OOM killer running under heavy RAM workloads. Normal systems would use a value less than 100 as RAM is always faster than any type of SWAP (so no need to prioritize it). Unless the OOM killer is a problem, and you cannot add RAM to the system, no value over 99 should be considered. Even then I dont see much benefit to setting values other than 60-70 and leaving it at that, and setting outside that range means YOU did extensive testing over many days.