Ubuntu – How much swap space for a 32GB ubuntu virtualization server

kvm-virtualizationswapUbuntuvirtualization

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?

Best Answer

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.