0

Using Libvirt / KVM on Ubuntu 16.04

Compiled against library: libvirt 1.3.1
Using library: libvirt 1.3.1
Using API: QEMU 1.3.1
Running hypervisor: QEMU 2.5.0

# dpkg -s qemu-kvm | grep Version
Version: 1:2.5+dfsg-5ubuntu10.

Is it safe to set the "MaxMemory" (reference) above the total physical memory of the host machine, if "currentMemory" will never exceed the actual available memory on the host machine?

Imagine a situation like:

  1. Host machine has 8GB of RAM
  2. VM is configured with 16GB of "MaxMemory", and 4GB of "currentMemory"

... is it possible for the VM to in any way utilize more than the currentMemory to crash the host, especially during the boot process?

To quote from the referenced link, "currentMemory" refers to:

The actual allocation of memory for the guest.

Which seems to imply the real limit of the VM's memory use is the "currentMemory"; however, this quote:

The run time maximum memory allocation of the guest.

... which is in reference to the "MaxMemory" sort of implies "at run time" maybe it can use more than the currentMemory?

Can someone shed some light on this? The way I sort of assume this all works is that KVM boots the VM and tells it that it has the "MaxMemory" available to it, and then shortly after that tells the VM that it can only use the "currentMemory". I'm concerned there may be a bit of a race condition there where the VM might be allowed to quickly claim the "MaxMemory". Though I suppose even if it did, OOM Killer would likely just kill the VM's process on the host machine.

The reason I want to do this is so that I can live migrate to other hosts which potentially can give 16GB of "currentMemory", even if it's not possible on the host machine the VM is originally configured on.

GoldenNewby
  • 45
  • 1
  • 2
  • 13

1 Answers1

3

When the guest first boots up it will see MaxMemory worth of RAM registered and can theoretically use it at this time. When the balloon driver in the guest loads, it will reduce the guest RAM to CurrentMemory. For Linux guests at least, the guest will never actually touch all RAM allowed by MaxMemory, before the balloon driver loads, so you shouldn't risk memory pressure on the host. Some guest OS (at least some versions of Windows) like to zero all RAM pages at startup, which could cause QEMU to consume the full MaxMemory. Also, if no balloon driver is loaded in the guest, it'll never reduce its RAM to the CurrentMemory level. Also if the guest is malicious it can choose to not honour the CurrentMemory level just ignoring the balloon requests.

Essentially, if you're using trusted Linux guest and have balloon driver in the guest (it should be there by default in any modern Linux OS), you should be fine.

DanielB
  • 1,618
  • 7
  • 7