Do i need swap memory on my CentOS vps?

Do i need a swap memory for my centos vps?

Will it increase performance and if so how do i go about setting it up?

I've found this link (http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-swap-adding.html) but it shows three methods of setting up swap memory. I'm not sure which one i need.

Image (not enough rep to embed): http://s15.postimage.org/manb5yu6j/Capture.png


Solution 1:

Swap is beneficial, because it allows inactive memory blocks to be written to disk, freeing up real memory for stuff like file system caching. Swap also (to some extent) protects you against short bursts of memory demand. Linux (by default) over commits real memory, relying on the fact that most applications ask for more than they need, but if they suddenly all need that memory swap can buffer you against applications crashing.

Long term use of swap instead of real memory can kill performance, but in the short term, swap can improve performance and protect against some failure scenarios. I would run without swap in only a few very limited situations.

Without knowing how your VPS is configured, it's not easy to suggest which method to use to add swap, however, my experience of VPS's in general is that your disk space is already carved up, so I would use option 3 (which creates a regular file), it's less efficient than using a logical volume but I don't know if you can create any on your vps. Option 1 is only useful for extending existing swap which you apparently don't have.

Solution 2:

If you have leased a virtual machine using Parallels Virtuozzo/OpenVZ containers, then you cannot have swap space. This technology does not permit containers to have their own swap space since all containers use a shared kernel. Therefore only the host can have swap space.

Ironically, the newest version of OpenVZ has a fake swap feature called VSwap which, instead of actually giving your container real swap space, gives it fake swap space that, if your container uses it, slows down your container to simulate the speed penalty of using swap. And of course you also get the additional slowdown if the host machine starts swapping because it's oversubscribed...