2

I looked at many other questions on here regarding swap space, but none that I found really addressed my particular situation.

I have an Ubuntu 9.10 64-bit server with 32GB of RAM running as a KVM host system. I'm using LVM on top of RAID1.

The "old-school" swap recommendations suggests 2xRAM or 2xRAM+1GB, or even if MEM < 2GB then SWAP = MEM*2 else SWAP = MEM+2GB. But I just can't see allocating 66GB of disk space for swap, that seems crazy! I'm thinking 4GB or maybe 8GB would be plenty.

This system is going to be running a number of KVM virtual servers. How does swap work in this situation? Should I have a swap partition for the host server, and then each virtual server gets its own LVM root and LVM swap partition? Or do the virtual servers share the host's swap?

2 Answers 2

3

Strictly, Linux does not need any swap at all - especially when you have gobs of RAM. In the case of KVM, you will need to have enough memory to support all your machines. So, if you have 20 VMs with 1GB RAM each, you will need to have 20GB RAM on the host available. However, each individual VM can be configured with its own swap, such as having 2GB of swap each. That way, each VM can manage its own swap. You can configure swappiness separately for each.

2
  • @sybreon: where does the swap for each VM reside? Does it make sense for each VM to get their own LVM root and LVM swap partitions on disk? By default they are just stored as root and swap be files on the host, right? I'm assuming that there is no need to make a big LVM swap partition on the host unless somehow all the VMs use the host's swap space.
    – Tauren
    Mar 4, 2010 at 4:43
  • Treat the VM just like normal machines. Give each VM its own LVM partition or file image depending on how you want to do it.
    – sybreon
    Mar 4, 2010 at 6:19
1

A 4GB amount will be sufficient. I'm not entirely sure how swap works for virtual servers, but I'm assuming each of them have their own swap.

In such situations, you should leave around 2GB of RAM for the host system, or just 1GB, depending on how much you see is being used on a machine with most of the memory allocated. Swap is very slow, and on your RAID-1 system, with such a high-end machine you would never want to swap.

On a side note, you may want to consider having 4 disks running in RAID-10, preferably SAS drives to have sufficient I/O for all the virtual servers on the node, though depending on what you're running this may not be necessary.

2
  • Thanks! Actually the chassis only has room for 2 drives, so RAID1 is as good as it gets (the 1U chassis actually has 2 full systems in it, each system gets 2 of the 4 drive bays). But the virtual servers will be PXE booting from a storage server over gigabit. I would like to set things up so that local swap is available to the virtual hosts, as sending swap over the network probably not a good idea.
    – Tauren
    Mar 3, 2010 at 10:06
  • Just because they PXE boot does not mean that they consume the servers disks (eg. swap), does it?
    – Felix
    Sep 29, 2014 at 19:04

You must log in to answer this question.

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