[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [fedora-virt] swap space on virtual machines



On 07/25/2009 09:02 PM, Richard W.M. Jones wrote:
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 several terms are mixed together here:

The guest is given certain amount of ram to play with.
Various hypervisors virtualize this guest ram differently. Regardless of the hypervisor. The guest does assumes it is his ram. Even if you allocate large amount of ram to the guest, it might swap since the guest runs processes that uses virtual memory, and thus might exceed the allocated ram to the guest. Guest swapping is a reasonable scenario that should be allowed and supported. When using a fast virtual block device like virtio, it should even be almost as fast as native swapping (which is always slower then ram..).

KVM hypervisor runs a VM as standard process. As such, it allocate virtual userspace memory to the VM as ram. We can overcommit the host ram and even swap it from the host. Host swapping works nicely but might really slow down things since both host & guest will swap out/in/out the same pages.


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...

But make things better ;)


Rich.

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


So bottom line, if you have free ram, give it to the guest - why save it? Even large guest can swap, determined by the load.

Dor


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]