I have: vm.swappiness = 1
as suggested here to prevent using Swap when there is plenty of available memory.
(0 would completely disable swap, as far as I understand)
In frequent cases, I end up with, say, 5GB swap used (total 16GB),
while I have 9GB free available memory (total 32GB)
(only 1GB free if we count cached RAM).
As my application starts to get slow (since most of the Swap is from MariaDB), I run:
swapoff -a
swapon -a
And all the swap memory is moved to the main RAM.
I end up with 5.6GB available RAM, 4GB if we count cached.
There is no apparent reason to have so much Swap.
I've been researching about this, and I cannot find a way to prevent using Swap when it's not needed.
vm.swappiness = 1
is definitely "permanently saved", since it is on the sysctl.conf file, and there have been reboots, etc.
I don't want to disable swap, but the only workaround I can think of is:
- disable swap
- have a cron running every 1 minute to check how much free RAM there is
- enable swap if available RAM is low
But, this is VERY risky to do, and I wish the OS was smart enough to manage this better!
Is there absolutely no way to only use swap when absolutely needed?