From: Vasilis Liaskovitis <vasilis.liaskovi...@profitbricks.com> query-balloon and "info balloon" should report total memory available to the guest.
balloon inflate/ deflate can also use all memory available to the guest (initial + hotplugged memory) Ballon driver has been minimaly tested with the patch, please review and test. Caveat: if the guest does not online hotplugged-memory, it's easy for a balloon inflate command to OOM a guest. Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovi...@profitbricks.com> --- hw/virtio/virtio-balloon.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index d669756..c866000 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -30,6 +30,7 @@ #endif #include "hw/virtio/virtio-bus.h" +#include "hw/mem-hotplug/dimm.h" static void balloon_page(void *addr, int deflate) { @@ -271,10 +272,11 @@ static void virtio_balloon_set_config(VirtIODevice *vdev, VirtIOBalloon *dev = VIRTIO_BALLOON(vdev); struct virtio_balloon_config config; uint32_t oldactual = dev->actual; + uint64_t hotplugged_ram_size = get_hp_memory_total(); memcpy(&config, config_data, 8); dev->actual = le32_to_cpu(config.actual); if (dev->actual != oldactual) { - qemu_balloon_changed(ram_size - + qemu_balloon_changed(ram_size + hotplugged_ram_size - ((ram_addr_t) dev->actual << VIRTIO_BALLOON_PFN_SHIFT)); } } @@ -290,18 +292,21 @@ static void virtio_balloon_stat(void *opaque, BalloonInfo *info) VirtIOBalloon *dev = opaque; info->actual = ram_size - ((uint64_t) dev->actual << VIRTIO_BALLOON_PFN_SHIFT); + info->actual += get_hp_memory_total(); } static void virtio_balloon_to_target(void *opaque, ram_addr_t target) { VirtIOBalloon *dev = VIRTIO_BALLOON(opaque); VirtIODevice *vdev = VIRTIO_DEVICE(dev); + uint64_t hotplugged_ram_size = get_hp_memory_total(); - if (target > ram_size) { - target = ram_size; + if (target > ram_size + hotplugged_ram_size) { + target = ram_size + hotplugged_ram_size; } if (target) { - dev->num_pages = (ram_size - target) >> VIRTIO_BALLOON_PFN_SHIFT; + dev->num_pages = (ram_size + hotplugged_ram_size - target) >> + VIRTIO_BALLOON_PFN_SHIFT; virtio_notify_config(vdev); } } -- 1.8.3.1