VMware Cloud Community
tomtomv
Contributor
Contributor

SWAP & memory configuration for a Linux guest

Hi folks,

So I've read loads of articles on the best practices for vSphere swap files, but I've yet to find any information on best practices for guest OS swap configuration.  The reason I'm asking this is because of the following scenario.  I have a Linux VM that has runs Apache and MySQL and is configured with 2GB vRAM.  vCenter and VCOPS report that it only actually has 400MB active, yet the guest OS reports that all memory is used and vmstat shows that the guest is actually swapping to disk.  As a Linux sysadmin I might say increase the vRAM to 4GB but as a vSphere sysadmin I might say reduce the vRAM to 1GB.  I imagine that the penalty I get for over provisioning vRAM would not be as severe as the penalty for Linux swapping to disk? How should swap be used within a guest?

Thoughts please Smiley Happy

Reply
0 Kudos
5 Replies
weinstein5
Immortal
Immortal

The key is are end users complaining about performance - if not do nothing. If they are then you might incrementally increase memory maybe to 4 GB - but remember operating systems are designed to swap so you will never want to provide enough memory that a VM will never swap -

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
Reply
0 Kudos
cykVM
Expert
Expert

I would generally avoid swapping to disk wherever possible, But is your VM constantly swapping or only from time to time (e.g. every x hours)?

Are VMWare tools installed in the Linux VM?

Maybe this sheds some light into your problem: http://serverfault.com/questions/148576/why-does-my-vmware-linux-host-slow-down-every-6-hours

Especially the answer given by ramirogn.

I would check which processes eat up memory first.

Reply
0 Kudos
tomtomv
Contributor
Contributor

Hi all, thanks for the responses.  I always have VMware tools installed.  It seems that the VM is always swapping when under any workload.  This is more of a "what is the best practice" question, there isn't a performance issue as such.  This kind of question becomes particularly pertinent when you have to justify why you are reclaiming RAM due to VCOPS recommendations.

Reply
0 Kudos
JarryG
Expert
Expert

Try to reduce "vm.swappiness". Common default value is 60 which causes swap to be used quite frequently (once disk-cache and i/o-buffers inflate, os tries to keep them big). You can reduce it down to zero, then if some application needs more memory then currently available, cache/buffer size is first reduced to minimum before swap is touched.

Next good thing is to configure your applications so that they do not use too much memory. This especially is the case for apps like mysql (plenty of memory-related configuration options) but also apache. If performance is then not acceptable, use some known solutions (i.e. db-splitting, web-accelerator, etc.).

You could also try to optimize your OS, i.e. turn off all unnecessary services, disable per package not-needed compile optioins (i.e. disable support for perl/debug/selinux in mysql if you do not need it), re-compile kernel with only necessary drivers, reduce number of ttys running, etc.

_____________________________________________ If you found my answer useful please do *not* mark it as "correct" or "helpful". It is hard to pretend being noob with all those points! 😉
tomtomv
Contributor
Contributor

Jarry, vm.swappiness is a good shout thank you.  I have since seen some performance tuning guides recommending the same so will do some experimentation.

Reply
0 Kudos