High CPU from kswapd0

Linode Staff

Our Linode is experiencing high cpu-load on weekly basis. When we run thetopcommand, 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?

3 Replies

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!

sorry, i have did the steps and i the processes still 100%+ and i can't access my website anymore

What's the size of your Linode? A nanode or something bigger?

What do you have running on it? How much swap do you have?

Do you have a static swap partition or are you using a swapfile?

What does free(1) say (n.b., -m says to give all measurements in megabytes)?

stevewi@dave:~$ free -m
              total        used        free      shared  buff/cache   available
Mem:           3946         605        1636          51        1704        3003
Swap:           255           0         255

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct