All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2, 1/1] memory: avoid updating ioeventfds for some address_space
@ 2023-08-30  3:29 hongmianquan via
  2023-09-04 12:51 ` [PATCH v2,1/1] " hongmainquan
  0 siblings, 1 reply; 5+ messages in thread
From: hongmianquan via @ 2023-08-30  3:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, david, philmd, peterx, hongmianquan

When updating ioeventfds, we need to iterate all address spaces,
but some address spaces do not register eventfd_add|del call when
memory_listener_register() and they do nothing when updating ioeventfds.
So we can skip these AS in address_space_update_ioeventfds().

The overhead of memory_region_transaction_commit() can be significantly
reduced. For example, a VM with 8 vhost net devices and each one has
64 vectors, can reduce the time spent on memory_region_transaction_commit by 20%.

Signed-off-by: hongmianquan <hongmianquan@bytedance.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
---
v2:
-nothing has changed, just pick PeterXu's review.
---
 include/exec/memory.h |  1 +
 softmmu/memory.c      | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 7f5c11a0cc..556f4f1871 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1089,6 +1089,7 @@ struct AddressSpace {
     struct FlatView *current_map;
 
     int ioeventfd_nb;
+    int ioeventfd_notifiers;
     struct MemoryRegionIoeventfd *ioeventfds;
     QTAILQ_HEAD(, MemoryListener) listeners;
     QTAILQ_ENTRY(AddressSpace) address_spaces_link;
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 7d9494ce70..178816c845 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -842,6 +842,10 @@ static void address_space_update_ioeventfds(AddressSpace *as)
     AddrRange tmp;
     unsigned i;
 
+    if (!as->ioeventfd_notifiers) {
+        return;
+    }
+
     /*
      * It is likely that the number of ioeventfds hasn't changed much, so use
      * the previous size as the starting value, with some headroom to avoid
@@ -3075,6 +3079,10 @@ void memory_listener_register(MemoryListener *listener, AddressSpace *as)
     }
 
     listener_add_address_space(listener, as);
+
+    if (listener->eventfd_add || listener->eventfd_del) {
+        as->ioeventfd_notifiers++;
+    }
 }
 
 void memory_listener_unregister(MemoryListener *listener)
@@ -3083,6 +3091,10 @@ void memory_listener_unregister(MemoryListener *listener)
         return;
     }
 
+    if (listener->eventfd_add || listener->eventfd_del) {
+        listener->address_space->ioeventfd_notifiers--;
+    }
+
     listener_del_address_space(listener, listener->address_space);
     QTAILQ_REMOVE(&memory_listeners, listener, link);
     QTAILQ_REMOVE(&listener->address_space->listeners, listener, link_as);
-- 
2.11.0



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

* Re: [PATCH v2,1/1] memory: avoid updating ioeventfds for some address_space
  2023-08-30  3:29 [PATCH v2, 1/1] memory: avoid updating ioeventfds for some address_space hongmianquan via
@ 2023-09-04 12:51 ` hongmainquan
  2023-09-11 16:28   ` Peter Xu
  0 siblings, 1 reply; 5+ messages in thread
From: hongmainquan @ 2023-09-04 12:51 UTC (permalink / raw)
  To: qemu-devel, pbonzini; +Cc: david, philmd, peterx


Friendly ping...
Hello, this patch has already received a R-b from PeterXu. Could you 
please help me review it as well and see if there are any issues? If 
everything is fine, could you please consider merging it? Thank you!

在 2023/8/30 11:29 上午, hongmianquan 写道:
> When updating ioeventfds, we need to iterate all address spaces,
> but some address spaces do not register eventfd_add|del call when
> memory_listener_register() and they do nothing when updating ioeventfds.
> So we can skip these AS in address_space_update_ioeventfds().
> 
> The overhead of memory_region_transaction_commit() can be significantly
> reduced. For example, a VM with 8 vhost net devices and each one has
> 64 vectors, can reduce the time spent on memory_region_transaction_commit by 20%.
> 
> Signed-off-by: hongmianquan <hongmianquan@bytedance.com>
> Reviewed-by: Peter Xu <peterx@redhat.com>
> ---
> v2:
> -nothing has changed, just pick PeterXu's review.
> ---
>   include/exec/memory.h |  1 +
>   softmmu/memory.c      | 12 ++++++++++++
>   2 files changed, 13 insertions(+)
> 
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 7f5c11a0cc..556f4f1871 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -1089,6 +1089,7 @@ struct AddressSpace {
>       struct FlatView *current_map;
>   
>       int ioeventfd_nb;
> +    int ioeventfd_notifiers;
>       struct MemoryRegionIoeventfd *ioeventfds;
>       QTAILQ_HEAD(, MemoryListener) listeners;
>       QTAILQ_ENTRY(AddressSpace) address_spaces_link;
> diff --git a/softmmu/memory.c b/softmmu/memory.c
> index 7d9494ce70..178816c845 100644
> --- a/softmmu/memory.c
> +++ b/softmmu/memory.c
> @@ -842,6 +842,10 @@ static void address_space_update_ioeventfds(AddressSpace *as)
>       AddrRange tmp;
>       unsigned i;
>   
> +    if (!as->ioeventfd_notifiers) {
> +        return;
> +    }
> +
>       /*
>        * It is likely that the number of ioeventfds hasn't changed much, so use
>        * the previous size as the starting value, with some headroom to avoid
> @@ -3075,6 +3079,10 @@ void memory_listener_register(MemoryListener *listener, AddressSpace *as)
>       }
>   
>       listener_add_address_space(listener, as);
> +
> +    if (listener->eventfd_add || listener->eventfd_del) {
> +        as->ioeventfd_notifiers++;
> +    }
>   }
>   
>   void memory_listener_unregister(MemoryListener *listener)
> @@ -3083,6 +3091,10 @@ void memory_listener_unregister(MemoryListener *listener)
>           return;
>       }
>   
> +    if (listener->eventfd_add || listener->eventfd_del) {
> +        listener->address_space->ioeventfd_notifiers--;
> +    }
> +
>       listener_del_address_space(listener, listener->address_space);
>       QTAILQ_REMOVE(&memory_listeners, listener, link);
>       QTAILQ_REMOVE(&listener->address_space->listeners, listener, link_as);


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

* Re: [PATCH v2,1/1] memory: avoid updating ioeventfds for some address_space
  2023-09-04 12:51 ` [PATCH v2,1/1] " hongmainquan
@ 2023-09-11 16:28   ` Peter Xu
  2023-09-11 17:55     ` David Hildenbrand
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Xu @ 2023-09-11 16:28 UTC (permalink / raw)
  To: hongmainquan, Paolo Bonzini, David Hildenbrand
  Cc: qemu-devel, pbonzini, david, philmd

On Mon, Sep 04, 2023 at 08:51:43PM +0800, hongmainquan wrote:
> 
> Friendly ping...
> Hello, this patch has already received a R-b from PeterXu. Could you please
> help me review it as well and see if there are any issues? If everything is
> fine, could you please consider merging it? Thank you!

Paolo, wanna pick this one up?

David, I know you're preparing a pull with a lot of memory changes, if you
like to pick this up it'll be good too.

If no one will pick it up, I can try to send a pull just to have this
patch, as long as it will work out.

Thanks,

-- 
Peter Xu



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

* Re: [PATCH v2,1/1] memory: avoid updating ioeventfds for some address_space
  2023-09-11 16:28   ` Peter Xu
@ 2023-09-11 17:55     ` David Hildenbrand
  2023-09-12  2:35       ` [External] " hongmainquan
  0 siblings, 1 reply; 5+ messages in thread
From: David Hildenbrand @ 2023-09-11 17:55 UTC (permalink / raw)
  To: Peter Xu, hongmainquan, Paolo Bonzini; +Cc: qemu-devel, philmd

On 11.09.23 18:28, Peter Xu wrote:
> On Mon, Sep 04, 2023 at 08:51:43PM +0800, hongmainquan wrote:
>>
>> Friendly ping...
>> Hello, this patch has already received a R-b from PeterXu. Could you please
>> help me review it as well and see if there are any issues? If everything is
>> fine, could you please consider merging it? Thank you!
> 
> Paolo, wanna pick this one up?
> 
> David, I know you're preparing a pull with a lot of memory changes, if you
> like to pick this up it'll be good too.

I queued it to

https://github.com/davidhildenbrand/qemu.git mem-next

If nobody beats me to it (or requests me to drop it), I'll send it 
upstream next week.

-- 
Cheers,

David / dhildenb



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

* Re: [External] Re: [PATCH v2,1/1] memory: avoid updating ioeventfds for some address_space
  2023-09-11 17:55     ` David Hildenbrand
@ 2023-09-12  2:35       ` hongmainquan
  0 siblings, 0 replies; 5+ messages in thread
From: hongmainquan @ 2023-09-12  2:35 UTC (permalink / raw)
  To: David Hildenbrand, Peter Xu; +Cc: qemu-devel, philmd, Paolo Bonzini



在 2023/9/12 1:55 上午, David Hildenbrand 写道:
> On 11.09.23 18:28, Peter Xu wrote:
>> On Mon, Sep 04, 2023 at 08:51:43PM +0800, hongmainquan wrote:
>>>
>>> Friendly ping...
>>> Hello, this patch has already received a R-b from PeterXu. Could you 
>>> please
>>> help me review it as well and see if there are any issues? If 
>>> everything is
>>> fine, could you please consider merging it? Thank you!
>>
>> Paolo, wanna pick this one up?
>>
>> David, I know you're preparing a pull with a lot of memory changes, if 
>> you
>> like to pick this up it'll be good too.
> 
> I queued it to
> 
> https://github.com/davidhildenbrand/qemu.git mem-next
> 
> If nobody beats me to it (or requests me to drop it), I'll send it 
> upstream next week.
> 
Thanks for that! I hope it can be successfully merged.


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

end of thread, other threads:[~2023-09-12  2:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-30  3:29 [PATCH v2, 1/1] memory: avoid updating ioeventfds for some address_space hongmianquan via
2023-09-04 12:51 ` [PATCH v2,1/1] " hongmainquan
2023-09-11 16:28   ` Peter Xu
2023-09-11 17:55     ` David Hildenbrand
2023-09-12  2:35       ` [External] " hongmainquan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.