kswapd0 is taking 99.9% of my CPU as top shows me, the problem appeared today when gaming and first time it went away after 6 minutes and now it has been doing it for about 20 minutes. How is this fixable and what is causing this?
The process kswapd0 is the process than manages virtual memory. Your machine "should" have RAM, SWAP, and the EXT4 on your HDD/SSD. The ext4 is where everything is stored, and it is always slower to access from than RAM. RAM is like a half-way running space for programs to access information quickly. Most computers have at least 4GB of RAM, which under normal conditions is plenty. When playing a game, however, you may run low on RAM space, which is where SWAP comes in.
SWAP is a fake RAM located on your HDD/SSD next to your EXT4. It is quicker to access than the EXT4, but it is much slower than actual RAM. When you run low on memory, kswapd0 moves programs that you are not using/not using as much as other programs to the SWAP, which causes extreme lag on those processes. If your game was needing 5GB RAM, 1GB at LEAST would be in SWAP. That means when it tries to access that information, it has to wait longer to get it.
This entire process causes extreme CPU usage, moving information from and to SWAP and RAM and handling the request of information all at the same time. How to solve this issue?
That's the best that you can do. Others may say disable swap completely, but that is dangerous and I would NOT recommend that. That can cause entire systems to freeze up if there is a memory leak or too many applications running. Just realize that the SWAP is a failsafe for the RAM. It is definitely not as fast or efficient as RAM, but it's better than Window's Pagefile! (which accomplishes the same purpose)
EDIT: If you are interested in learning more about SWAP, see here.
kswapd0 runs at 99.9% of one CPU but is actually not swapping at all
To me it happens at times on Ubuntu 14.04 with kernel 3.19.0-50-generic (and earlier) running in a VMware vm. I have no clue, what made it appear, but it comes during idle time.
a reboot solved the problem - temporarily.
following the answer on serverfault (kswapd often uses 100% CPU when swap is in use) there where the same settings on my system:
the solution was actually
now it's fine:
Permanent solution (to be found)?
but since the actual reason is not yet known, and I did not fine any suitable explanation on the net, this is not a permanent solution. Actually, the selected answer could be the permanent solution. I just wanted to add this for future reference, as a reboot (to make sysctl take effect) is not always possible.
An other solution might be to set THP to either
i've set up the following batch as a cron job as a "permanent" solution: