High CPU from kswapd0
Our Linode is experiencing high cpu-load on weekly basis. When we run the
topcommand, it shows
kswapd0 to be the main culprit for this. We use this Linode for our test servers, which gets really low traffic, so problem doesn't feel like it is on our end. Rebooting has helped with the issue temporarily. Can you help with this?
The process you referred to, kswapd0, manages virtual memory and may be having issues due to moving processes to SWAP too frequently, causing cpu spikes and decreased system performance.
You can view and analyze your settings affecting this behavior with the following:
This is where you determine when processes are moved to swap:
$ sudo cat /etc/sysctl.conf
To understand this file better, see this man page for sysctl.conf
These files affect your virtual memory performance:
$ sudo cat /proc/sys/vm/swappiness
$ sudo cat /proc/sys/vm/vfs_cache_pressure
$ sudo cat /sys/kernel/mm/transparent_hugepage/enabled
$ sudo cat /proc/sys/vm/drop_caches
To understand these settings before you adjust them, see this documentation for virtual memory.
We've seen this issue mitigated different ways, but taking all three steps in order also seems to keep it from re-occuring:
Reconfigure /etc/sysctl.conf to require a higher Ram threshold before moving processes to swap. This command will set process to SWAP only if you've exhausted RAM:
$ sudo echo vm.swappiness=$VALUE | sudo tee -a /etc/sysctl.conf
If swappiness=0, the SWAP disk will be avoided unless absolutely necessary (you run out of RAM completely), and if swappiness=100, programs will be sent to SWAP almost instantly.
Set /proc/sys/vm/drop_caches to 1
$ sudo echo 1 > /proc/sys/vm/drop_caches
Reboot for the setting changes to take effect and clear SWAP as you observed previously.
Let us know how this worked for you!