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


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.


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...


Adding swap memory won't make it faster, but it does allow you to run more applications.

If your application(s) start to use enough memory that your swap is being used, your system will slow down considerably but at least will not crash, which is what will eventualy happen if you run out of RAM.

Looks like you have 5GB of RAM, I would recommend about a 2GB swap file in that case.

Another thing to consider, you are using a VPS which usually has poor disk I/O (depending on your neighbors) so the swap will probably be even slower than on a dedicated machine.


Swap memory comes into picture if you run out of normal memory usage. Say suppose you have opted 1GB RAM. If running application consumes 1GB memory usage then SAWP memory comes into picture It acts as a Virtual RAM of another 512 MB or 1 GB

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.