Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
@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 '10 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 '10 at 6:19

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.

share|improve this answer
    
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 '10 at 10:06
    
Just because they PXE boot does not mean that they consume the servers disks (eg. swap), does it? –  Felix Sep 29 at 19:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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