Re: Optimization for the virtio-balloon feature on the ARM platform

2023-02-20 Thread Michael S. Tsirkin
On Mon, Feb 20, 2023 at 10:15:37AM +0100, David Hildenbrand wrote:
> On 20.02.23 02:33, Yangming via wrote:
> > 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.
> 
> I'd suggest keeping track of the plugged DIMM size inside
> ms->device_memory->dimm_size. We can update it from
> pc_dimm_plug/pc_dimm_unplug. We just have to make sure to exclude NVDIMMs.
> 
> We can then optimize get_current_ram_size() to return "ms->ram_size +
> ms->device_memory->dimm_size", of course taking care of ms->device_memory ==
> NULL on some machines.


And as any optimization, patches are welcome accompanied by
a measurement showing it's a net improvement.

> -- 
> Thanks,
> 
> David / dhildenb




Re: Optimization for the virtio-balloon feature on the ARM platform

2023-02-20 Thread David Hildenbrand

On 20.02.23 02:33, Yangming via wrote:

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.


I'd suggest keeping track of the plugged DIMM size inside 
ms->device_memory->dimm_size. We can update it from 
pc_dimm_plug/pc_dimm_unplug. We just have to make sure to exclude NVDIMMs.


We can then optimize get_current_ram_size() to return "ms->ram_size + 
ms->device_memory->dimm_size", of course taking care of 
ms->device_memory == NULL on some machines.


--
Thanks,

David / dhildenb




Optimization for the virtio-balloon feature on the ARM platform

2023-02-19 Thread Yangming via
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