kswapd0 is taking 99.9% of my CPU as top shows me, no any other process consume more CPU then this process.
1. Tell kswapd0 to only move stuff to SWAP when you are completely OUT of RAM. Run below command to avoid this SWAP issue.
echo vm.swappiness=0 | sudo tee -a /etc/sysctl.conf
Meaning of this command is if your RAM is fully consume then after it will used the SWAP partition which is created on your HDD.
2. A reboot can resolved the problem temporarily.
3. Check output of below command
# cat /proc/sys/vm/vfs_cache_pressure
100
The solution for dropping cache is
the solution was actually # echo 1 > /proc/sys/vm/drop_caches:
4. For permanent solution you can create shell script and set it in cron.
#!/bin/bash## run as cron, thus no $PATH, thus need to define all absolute pathstop=/usr/bin/topgrep=/bin/greptop=$($top -bn1 -o %CPU -u0 | $grep -m2 -E "%CPU|kswapd0")IFS=''set -fi=0for line in $topdo #echo $i $line if ! (( i++ )) then pos=${line%%%CPU*} pos=${#pos} #echo $pos else cpu=${line:(($pos-1)):3} cpu=${cpu// /} #echo $cpu fidone[[ -n $cpu ]] && (( $cpu >= 90 )) && echo 1 > /proc/sys/vm/drop_caches && echo "$$ $0: cache dropped (kswapd0 %CPU=$cpu)" >&2 && exit 1exit 0Invoked with
# m h dom mon dow command * 4 * * * /bin/bash /path/to/batch/drop_caches.sh >> /var/log/syslog 2>&1This command will run at every 4 hours so set timings as per your need.

