diff mbox series

[v7,3/6] memory: Introduce memory_region_transaction_do_commit()

Message ID 20230310022425.2992472-4-xuchuangxclwt@bytedance.com (mailing list archive)
State New, archived
Headers show
Series migration: reduce time of loading non-iterable vmstate | expand

Commit Message

Chuang Xu March 10, 2023, 2:24 a.m. UTC
Split memory_region_transaction_do_commit() from
memory_region_transaction_commit().

We'll call do_commit() in address_space_to_flatview() in the later patch.

Signed-off-by: Chuang Xu <xuchuangxclwt@bytedance.com>
---
 softmmu/memory.c | 47 +++++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 20 deletions(-)

Comments

Peter Xu March 10, 2023, 2:51 p.m. UTC | #1
On Fri, Mar 10, 2023 at 10:24:22AM +0800, Chuang Xu wrote:
> Split memory_region_transaction_do_commit() from
> memory_region_transaction_commit().
> 
> We'll call do_commit() in address_space_to_flatview() in the later patch.
> 
> Signed-off-by: Chuang Xu <xuchuangxclwt@bytedance.com>

[...]

> +void memory_region_transaction_commit(void)
> +{
> +    assert(memory_region_transaction_depth);
> +    assert(qemu_mutex_iothread_locked());

This context has nothing to assert BQL, so this can be dropped I think (you
have one in do_commit).

> +
> +    --memory_region_transaction_depth;
> +    if (!memory_region_transaction_depth) {
> +        memory_region_transaction_do_commit();
> +    }
>  }

With above dropped:

Reviewed-by: Peter Xu <peterx@redhat.com>
Chuang Xu March 13, 2023, 2:53 a.m. UTC | #2
Hi, Peter,

On 2023/3/10 下午10:51, Peter Xu wrote:
> On Fri, Mar 10, 2023 at 10:24:22AM +0800, Chuang Xu wrote:
>> Split memory_region_transaction_do_commit() from
>> memory_region_transaction_commit().
>>
>> We'll call do_commit() in address_space_to_flatview() in the later patch.
>>
>> Signed-off-by: Chuang Xu <xuchuangxclwt@bytedance.com>
> [...]
>
>> +void memory_region_transaction_commit(void)
>> +{
>> +    assert(memory_region_transaction_depth);
>> +    assert(qemu_mutex_iothread_locked());
> This context has nothing to assert BQL, so this can be dropped I think (you
> have one in do_commit).

do_commit() will be triggered only when depth is 0. Before do_commit() is
triggered, we must ensure that the BQL is held when the depth is modified.

>> +
>> +    --memory_region_transaction_depth;
>> +    if (!memory_region_transaction_depth) {
>> +        memory_region_transaction_do_commit();
>> +    }
>>   }
> With above dropped:
>
> Reviewed-by: Peter Xu <peterx@redhat.com>
>
Thanks!
diff mbox series

Patch

diff --git a/softmmu/memory.c b/softmmu/memory.c
index a992a365d9..33ecc62ee9 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1093,34 +1093,41 @@  void memory_region_transaction_begin(void)
     ++memory_region_transaction_depth;
 }
 
-void memory_region_transaction_commit(void)
+void memory_region_transaction_do_commit(void)
 {
     AddressSpace *as;
 
-    assert(memory_region_transaction_depth);
     assert(qemu_mutex_iothread_locked());
 
-    --memory_region_transaction_depth;
-    if (!memory_region_transaction_depth) {
-        if (memory_region_update_pending) {
-            flatviews_reset();
+    if (memory_region_update_pending) {
+        flatviews_reset();
 
-            MEMORY_LISTENER_CALL_GLOBAL(begin, Forward);
+        MEMORY_LISTENER_CALL_GLOBAL(begin, Forward);
 
-            QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
-                address_space_set_flatview(as);
-                address_space_update_ioeventfds(as);
-            }
-            memory_region_update_pending = false;
-            ioeventfd_update_pending = false;
-            MEMORY_LISTENER_CALL_GLOBAL(commit, Forward);
-        } else if (ioeventfd_update_pending) {
-            QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
-                address_space_update_ioeventfds(as);
-            }
-            ioeventfd_update_pending = false;
+        QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
+            address_space_set_flatview(as);
+            address_space_update_ioeventfds(as);
+        }
+        memory_region_update_pending = false;
+        ioeventfd_update_pending = false;
+        MEMORY_LISTENER_CALL_GLOBAL(commit, Forward);
+    } else if (ioeventfd_update_pending) {
+        QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
+            address_space_update_ioeventfds(as);
         }
-   }
+        ioeventfd_update_pending = false;
+    }
+}
+
+void memory_region_transaction_commit(void)
+{
+    assert(memory_region_transaction_depth);
+    assert(qemu_mutex_iothread_locked());
+
+    --memory_region_transaction_depth;
+    if (!memory_region_transaction_depth) {
+        memory_region_transaction_do_commit();
+    }
 }
 
 static void memory_region_destructor_none(MemoryRegion *mr)