[CentOS] Swap space for kvm virtual host

Mon Mar 14 22:02:25 UTC 2011
Dr. Ed Morbius <dredmorbius at gmail.com>

on 14:24 Mon 14 Mar, Nataraj (incoming-centos at rjl.com) wrote:
> I have a kvm virtual host running on what will become CentOS 6 with 12GB
> of memory and a Quad Xeon  X5560 2.8Ghz .  The store for virtual
> machines will be a software raid 6 array of 6 disks with an LVM layered
> on top.  I'm not initially planning any major overcommitment of
> resources, though there could be a need for some overcommitment with a
> light workload on the guests.
> 
>  In recent years people seem to configure a wide range of different swap
> allocations.  I was thinking initially to spread swap across seperate
> non-raid partitions on 4 of these disks, but the downside of that is if
> I put 2gb on each disk, then I can only swap processes that will fit in
> 2gb swap space.  

Incorrect.

Linux processes aren't "swapped" to disk (the entire process memory
space), but are paged (given memory blocks are swapped out
individually).

Swap allocated over multiple spindles is effectively striped (treated as
one large RAID 0 partition).

If you've got SSD, you'll get even better swap performance.

For an excellent explanation of how Linux pages / handles memory:

    http://sourcefrog.net/weblog/software/linux-kernel/swap.html

> Also, if one of the disks fails, I have to reboot if
> anything was swapped to that drive.
> 
> My questions are as follows:
> 
>    1. What experience are others having with putting swap space on raid
>       partitions?  I was thinking about maybe swapping on a raid10
>       device, otherwise an LVM spanning multiple drives.

I'd allocate swap to the raw devices rather than the RAID devices,
particularly if using SW RAID.  In the case of HW RAID, it's a bit of a
toss-up.  Whatever's easier to manage.

>    2. In practice, what kinds of swap allocation are people finding
>       useful for a kvm virtual host of this size?

1-3x RAM is still my rule of thumb.

> I definitely don't want a system that is so overcommited that
> performance is impacted, but if some overcommitment is reasonable for
> VM's that have light workload, then I consider that.  I can increase
> system resources when that becomes necessary.

For this, you'll want to set the overcommit and swappiness kernel
parameters.  Amount of swap space is a secondary consideration.  How
much swap you /have/ and how much swap you're /doing/ are two different
things.

-- 
Dr. Ed Morbius, Chief Scientist /            |
  Robot Wrangler / Staff Psychologist        | When you seek unlimited power
Krell Power Systems Unlimited                |                  Go to Krell!