I have a CentOS Linux server. I ran Java based app and web server on it. But, swap space/memory usage is too high. Server is getting slow. I reboot daily but after few hours I see swap usage too high again. What we need to do? Please gives tips.
You need to lower the swappiness (tendency to/aggressiveness of swapping) to 1, it’s something like 60 by default. Be warned, though, that in my experience with Ubuntu, swapping will happen no matter what, but your mileage might vary:
Change the swappiness setting.
- Set the value for the running system.
sudo sh -c 'echo 0 > /proc/sys/vm/swappiness'
sudo cp -p /etc/sysctl.conf /etc/sysctl.conf.`date +%Y%m%d-%H:%M`
- Set the value in
/etc/sysctl.confso it stays after reboot.
sudo sh -c 'echo "" >> /etc/sysctl.conf' sudo sh -c 'echo "#Set swappiness to 0 to avoid swapping" >> /etc/sysctl.conf' sudo sh -c 'echo "vm.swappiness = 0" >> /etc/sysctl.conf'
Tomboi, you most likely don’t need to do anything. The way Linux works, it will always utilize all available memory. That doesn’t automatically mean that you are running low on memory – all of that memory is immediately available for reuse when needed.
Do you have any specific reason to believe that you are having a problem? Like some actual bad symptoms?
Hi @Pourko It is getting slow after reboot. The top command always says swap full. So i thought swap memory is problem. one of page on Google said add more ram when you run out of swap. But I am not sure. How can I verify I am running out of ram and it is not swap?
Hey @rautamiekka, will try it. Will it cause any problem as it is java and apache running on real production VM. It has 16 core cpu and 32 GB ram.
Add more ram has been the advice since we were running computers with 32KB of ram. 32GB is HUGE! If you have some buggy leaky program that can really eat up that much ram, then “swappiness” is not your problem, the buggy program is. When you run that top command, just how much ram/cpu is that program using?
Still, until further info, I don’t think that you even have a problem, other than you looking at the swap numbers and thinking that swap memory is a problem. When you say “it is getting slow”, in what measurable way is it getting slow? Is it network speed getting slow? Or is any benchmark taking longer to complete? Have you ran any actual tests that show that something “is getting slow”?
I run Linux with only 2 GB of ram, and disabled the swap. Occasionally I run into errors. But I generally don’t surpass 1.6GB.