[fedora-virt] swap space on virtual machines

Richard W.M. Jones rjones at redhat.com
Sat Jul 25 18:02:58 UTC 2009

On Fri, Jul 24, 2009 at 12:39:54PM -0400, Rich Mahn wrote:
> How big should the swap parititons be on virtual machines
> under qemu, qemu/kvm?
> It seems to me that if the VM actually needs swap space, it
> would be more efficient to allocate more virual memory to it.
> I know it's possible to allocate more virtual
> memory than there is physical memory.  Intuitively (which
> isn't always right) it would seem that allocating more
> memory is more efficient than letting the VM use swap space.
> It would seem that the host machine would have to either use
> physical memory or swap space if it's required.

A real interesting question.

One place I think you're wrong is the assumption that adding more
memory to a VM is better than having the VM use a swap disk.  The
reason would be that the VM's memory manager will assume that the
[from its point of view] physical memory will be much faster than
swap, and so will arrange memory vs swap use accordingly.  But this
assumption isn't true, this so-called physical memory is really just
as slow as swap!

You say:

> Compared to the VM using a swap space that is a virtual disk space
> that goes to real disk.

but actually virtualized block I/O isn't so bad if you use the correct
(virtio) drivers.

I think the only way you'll really answer this is to conduct tests
based on your specific workload.  I've only done this with Xen, where
this doesn't apply because Xen guest memory _is_ physical memory.

By the way, Kernel Shared Memory (KSM, [1]) complicates everything...


[1] http://lwn.net/Articles/306704/

Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.

More information about the Fedora-virt mailing list