qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Optimization for the virtio-balloon feature on the ARM platform
       [not found] <8c6d264163574d8b886afdd3e4b77a2d@huawei.com>
@ 2023-02-20  1:33 ` Yangming via
  2023-02-20  9:15   ` David Hildenbrand
  0 siblings, 1 reply; 3+ messages in thread
From: Yangming via @ 2023-02-20  1:33 UTC (permalink / raw)
  To: mst@redhat.com, david@redhat.com, qemu-devel@nongnu.org
  Cc: wangzhigang (O), zhangliang (AG), xiqi

[-- Attachment #1: Type: text/plain, Size: 1296 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 5466 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Optimization for the virtio-balloon feature on the ARM platform
  2023-02-20  1:33 ` Optimization for the virtio-balloon feature on the ARM platform Yangming via
@ 2023-02-20  9:15   ` David Hildenbrand
  2023-02-20 12:11     ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand @ 2023-02-20  9:15 UTC (permalink / raw)
  To: Yangming, mst@redhat.com, qemu-devel@nongnu.org
  Cc: wangzhigang (O), zhangliang (AG), xiqi

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Optimization for the virtio-balloon feature on the ARM platform
  2023-02-20  9:15   ` David Hildenbrand
@ 2023-02-20 12:11     ` Michael S. Tsirkin
  0 siblings, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2023-02-20 12:11 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Yangming, qemu-devel@nongnu.org, wangzhigang (O), zhangliang (AG),
	xiqi

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-20 12:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <8c6d264163574d8b886afdd3e4b77a2d@huawei.com>
2023-02-20  1:33 ` Optimization for the virtio-balloon feature on the ARM platform Yangming via
2023-02-20  9:15   ` David Hildenbrand
2023-02-20 12:11     ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).