Ricardo Silveira
Ricardo Silveira

Reputation: 25

kswapd0 takes my cpp program CPU usage to below 10%... How to overcome it?

I wrote a cpp program which reads several csv files and appends the data in a map >. The problem is that this data structure goes over 80% of my memory usage at some point, and then kswapd0 appears and takes my program CPU usage to belo 10%, which makes it extremely slow, given the nature of the program.

I do understand the nature of kswapd0, I know it wants to play around with disk and memory pagination, however I do still need my program to run!

Does anybody have a clue on how to overcome it?

The problem is not my program, I can ensure you that, because I separated the program in steps [basically grouping the files] and for some groups it doesn't happen, only for the real huge large groups take go over 85% of memory usage evoking kswapd0...

Upvotes: 0

Views: 431

Answers (1)

Tech
Tech

Reputation: 935

After certain memory usage kswapd0 starts. You can change the limits or disable it.

edit after comment:

you can check swapiness value with this code

cat /proc/sys/vm/swappiness

Mine was 60. It means after %60 of my memory use swap is kicking in. You can change this with a higher value or with "0" for disabling it.

sudo sysctl vm.swappiness=90

I don't know your hardware but I'm using aws ec2 t instances. They don't have any space for swapping. So I've disabled it and my problem solved. Hope it helps.

Upvotes: 1

Related Questions