# Kswapd0 consume most CPU

## XiaoaiX

I am using kernel 4.05. I always keep open some pdf files (about 10) with okular and a lot of webpages in firefox. From time to time, the system become very slow.  top shows that kswapd0 consumes 100% CPU and changes slowly down. After a while, always if it is lucky, the kswapd0 disappears and the system come back to usual. But in seldom cases, the system will not response if I just open some resource consuming webpage in firefox, and I have to reboot. 

My system have 8G memory, 512G SSD. No swap is on.

Can I avoid such things happening without closing those pdf  files and webpages?

Or can I find out which process consumes the memory most? 

Thanks

----------

## ct85711

well, it's sounds like you are eating away all of your memory doing all that (specially on only 8GB without swap).  The common trend I was seeing for this, is just about the same you was doing, about 8GB of ram and no swap, interestingly enough, the easy fix was adding a swap file (kswapd stopped hogging the CPU)...

Well, best bet to check on memory usage would be firefox (always a hog), though on my system I have one pdf file that makes firefox's worse memory usage look like child's play (in ocular, it usually filled over 12GB of ram easily by it's self).

The 2 prime things to check, is good old top and free -m

----------

## steveL

Just to add a recommendation for sys-process/htop.

Really nice, and allows you to view by-thread, if required.

----------

## Princess Nell

Sounds like a desktop machine. I have seen kswapd problems only on servers, and most likely along the lines of https://www.centos.org/forums/viewtopic.php?t=29411 (last posting in thread): free memory imbalance on systems with NUMA enabled.

----------

## Buffoon

Have you adjusted swappiness in sysctl.conf.

----------

## XiaoaiX

 *Buffoon wrote:*   

> Have you adjusted swappiness in sysctl.conf.

 

haven't done any thing in sysctl.conf. I don't know what swappiness in sysctl.conf means? Could you explain more?

----------

## XiaoaiX

So, it seems that okular is not good at managing memory. I would change to acroread now.

 *ct85711 wrote:*   

> well, it's sounds like you are eating away all of your memory doing all that (specially on only 8GB without swap).  The common trend I was seeing for this, is just about the same you was doing, about 8GB of ram and no swap, interestingly enough, the easy fix was adding a swap file (kswapd stopped hogging the CPU)...
> 
> Well, best bet to check on memory usage would be firefox (always a hog), though on my system I have one pdf file that makes firefox's worse memory usage look like child's play (in ocular, it usually filled over 12GB of ram easily by it's self).
> 
> The 2 prime things to check, is good old top and free -m

 

----------

## XiaoaiX

But why should kswapd0 use up all the cpu but not share with others? This seem to be a bug. In my opinion, a good way to do this is when the memory is used to about 90% and this kswapd0 be called to clear the memory. It then can share the cpu with others because  the others can use the 10% left without waiting for kswapd0. Why not do like this?

----------

## steveL

 *XiaoaiX wrote:*   

> haven't done any thing in sysctl.conf. I don't know what swappiness in sysctl.conf means? Could you explain more?

 

See this tip

----------

## ct85711

 *Quote:*   

> But why should kswapd0 use up all the cpu but not share with others? This seem to be a bug. In my opinion, a good way to do this is when the memory is used to about 90% and this kswapd0 be called to clear the memory. It then can share the cpu with others because the others can use the 10% left without waiting for kswapd0. Why not do like this?

 

The issue with that, isn't the CPU usage, it's more of kswapd0 isn't finding any memory to clear out, so other stuff can start up/run. Trying to put more water in a tank that is already full does not work out, regardless of all the pushing you are doing.  As it is, your getting close to triggering the kernel's memory killer to forcibly clear out memory (by killing running programs).

I'm not sure how changing the swappiness is going to do anything, when the OP even stated there is no swap to begin with.  Now, you know you can easily just put a swap file/partition on a USB drive/external drive.

----------

## Buffoon

ct85711

what you said makes sense. I didn't read the OP thoroughly.

XiaoaiX

there is a known memory leak in QT 4.8.7, I know it because I had QT installed for MythTV and it just ate up all my RAM, downgraded to 4.8.6 and the problem went away.

----------

## XiaoaiX

 *Buffoon wrote:*   

> ct85711
> 
> what you said makes sense. I didn't read the OP thoroughly.
> 
> XiaoaiX
> ...

 

I am using QT 4.8.6-r2 not QT 4.8.7.

----------

