How To resolve High CPU occupation from kswapd0


kswapd0, manages virtual memory and may be having issues due to moving processes to SWAP too frequently, causing cpu spikes and decreased system performance.

High CPU Usage of kswapd0 indicates insufficient memory and memory swapping is in progress.



cat /proc/sys/vm/swappiness

This control is used to define how aggressive the kernel will swap
memory pages.  Higher values will increase aggressiveness, lower values
decrease the amount of swap.  A value of 0 instructs the kernel not to
initiate swap until the amount of free and file-backed pages is less
than the high water mark in a zone.

The default value is 60.

Set to 0 can prevent swap activity in unnecessary.


cat /proc/sys/vm/vfs_cache_pressure

default value is 100, when set to 0, it will never reclaim dentries and inodes due to memory pressure and this can easily lead to out-of-memory conditions. With vfs_cache_pressure=1000, it will look for ten times more freeable objects than there are.


cat /sys/kernel/mm/transparent_hugepage/enabled

In short it should be set to always


Prevent swappiness

echo vm.swappiness=0 | tee -a /etc/sysctl.conf

Clear Cache

echo 1 > /proc/sys/vm/drop_caches


Documentation for /proc/sys/vm/*