3

My command to start qemu looks like this:

$ qemu-system-x86_64 \
    -name guest=win10 \
    -m 4830196K \
    -enable-kvm \
    -drive file=win10.img,format=raw,index=0,media=disk,if=virtio \
    ......

qemu takes up 4G of memory according to the parameters I gave, but the memory size used by the guest machine may only be 2G.

I want to specify the maximum memory available for a guest, how much memory the guest uses, and how much memory qemu takes.

what should I do?

aszswaz
  • 237

1 Answers1

5

QEMU does not support dynamic guest memory allocation in the way, say, Hyper-V does.

It does support an API (via the QEMU Object Model) and manual control of the virtio-balloon device, if present in the VM. Simply add -device virtio-balloon to the command line and you’re good to go. (There’s also a way with dynamically adding and removing virtual memory DIMMs, but I’m not familiar with that.)

You can use the QEMU Monitor console to issue the balloon 1234 command, where 1234 is the target amount of RAM (in megabytes). You can also use info balloon to get the current allocation.

You can access QEMU Monitor using various methods, including sockets and keyboard shortcuts.

libvirt encapsulates this feature (or perhaps the dynamic DIMM thing in newer versions), too. You can define a “current” and maximum memory size on VMs.

Daniel B
  • 62,883