[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v8 6/6] memory: Introduce address_space_to_flatview_rcu()
From: |
Chuang Xu |
Subject: |
[PATCH v8 6/6] memory: Introduce address_space_to_flatview_rcu() |
Date: |
Fri, 17 Mar 2023 16:19:04 +0800 |
In last patch, we wrap vm_load with begin/commit, here we introduce
address_space_to_flatview_rcu() to avoid unnecessary enforce commit
during vm_load.
Signed-off-by: Chuang Xu <xuchuangxclwt@bytedance.com>
---
include/exec/memory.h | 17 +++++++++++++++++
softmmu/memory.c | 2 +-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index d6fd89db64..2bf702dc94 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1123,6 +1123,23 @@ static inline FlatView
*address_space_to_flatview(AddressSpace *as)
return qatomic_rcu_read(&as->current_map);
}
+/*
+ * We recommend using address_space_to_flatview() rather than this one.
+ * Note that if we use this during a memory region transaction, we may
+ * see obsolete flatviews. We must bear with an obsolete map until commit.
+ * And outside a memory region transaction, this is basically the same as
+ * address_space_to_flatview().
+ */
+static inline FlatView *address_space_to_flatview_rcu(AddressSpace *as)
+{
+ /*
+ * Before using any flatview, sanity check BQL or RCU is held.
+ */
+ assert(qemu_mutex_iothread_locked() || rcu_read_is_locked());
+
+ return qatomic_rcu_read(&as->current_map);
+}
+
/**
* typedef flatview_cb: callback for flatview_for_each_range()
*
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 6a8e8b4e71..33d14e967d 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -815,7 +815,7 @@ FlatView *address_space_get_flatview(AddressSpace *as)
RCU_READ_LOCK_GUARD();
do {
- view = address_space_to_flatview(as);
+ view = address_space_to_flatview_rcu(as);
/* If somebody has replaced as->current_map concurrently,
* flatview_ref returns false.
*/
--
2.20.1
- [PATCH v8 0/6] migration: reduce time of loading non-iterable vmstate, Chuang Xu, 2023/03/17
- [PATCH v8 1/6] memory: Reference as->current_map directly in memory commit, Chuang Xu, 2023/03/17
- [PATCH v8 2/6] rcu: Introduce rcu_read_is_locked(), Chuang Xu, 2023/03/17
- [PATCH v8 3/6] memory: Introduce memory_region_transaction_do_commit(), Chuang Xu, 2023/03/17
- [PATCH v8 4/6] memory: Add do_commit() and sanity check in address_space_to_flatview, Chuang Xu, 2023/03/17
- [PATCH v8 5/6] migration: Reduce time of loading non-iterable vmstate, Chuang Xu, 2023/03/17
- [PATCH v8 6/6] memory: Introduce address_space_to_flatview_rcu(),
Chuang Xu <=