Dear QEMU maintainers, I am writing to discuss a possible optimization for the virtio-balloon feature on the ARM platform. The 'virtio_balloon_set_config' function is called frequently during the balloon inflation process, and its subfunction 'get_current_ram_size' needs to traverse the virtual machine's memory modules in order to count the current virtual machine's memory (i.e initial ram size + hotplugged memory). This can be very time consuming on the ARM platform, as the ARM virtual machine has much more complex memory modules than the x86 virtual machine.
Therefore, I suggest introducing a global variable, 'total_ram_size', that would be updated only when the balloon is initialized and hotplug memory has completed. This would increase the efficiency of balloon inflation by more than 60% on the ARM platform. The following code is part of the optimization for balloon: --- a/qemu/hw/virtio/virtio-balloon.c +++ b/qemu/hw/virtio/virtio-balloon.c static void virtio_balloon_set_config(...) ... - ram_addr_t vm_ram_size = get_current_ram_size(); + ram_addr_t vm_ram_size = total_ram_size; ... I hope this suggestion could be considered or discussed by QEMU developers. I would love to seeing this improvement added to QEMU in the future. Best regards, Qi