Now I'm trying to create KVM templates with CentOS and I'm not sure should I create swap partition on guest OS or not. In future it will be lot's of small VPS with 256-1024Mb RAM and if swap partition is a good idea will be 256Mb of swap enough for making them more stable?

3 Answers 3


Sure. Go for it... Those sound like low-memory virtual machines. It may be helpful to have swap in place in the event memory is exhausted. If not, you can always add swap files later.

  • +1 having a bit of swap never hurts
    – dyasny
    Commented Sep 13, 2012 at 11:16

One other thing to consider... some applications, databases most notably, try to consume all the physical RAM they can. Unfortunately, if your database is large enough, your database server will take your server to the brink of no memory. If things get to constrained, the kernel will pull out its pistol and start shooting processes in the head to recover memory. In my experience, it seems the RAM munching database is the first go.

Add a little swap.


In particular for systems with small amounts of RAM some swap is most important.

I have a setup with about 100 of small vps with 384 MB RAM on one mid-sized physical machine, most of them look like this:

# free -m
         total       used       free     shared    buffers     cached
Mem:           375        330         44          0         60        215
-/+ buffers/cache:         55        320
Swap:          487          4        486

So it is good to have some swap, or the vps stated above most likely would have crashed without swap.

To reduce CPU load when the vps wants to use swap the first time and you know that would happen, it would be very good using preallocation (using qcow2 images).

On a physical machine with many vps one can imagine that a machine would get a very high load if many of the running vps want to swap in an area that has still to be allocated.

Talking of me I would rather use more RAM (about +124MB) on the vps for future installations, now that I know that some vps swap (even if only 4MB).

  • 1
    So it is good to have some swap, or the vps stated above most likely would have crashed without swap - free show many unused memory (actually used by cache but easily freed by request). Example is not valid!!
    – gavenkoa
    Commented Feb 7, 2016 at 11:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .