代码拉取完成,页面将自动刷新
From 3b09c85198f4970be18ba8597d545d5dc73a0ba1 Mon Sep 17 00:00:00 2001
From: libai <libai12@huawei.com>
Date: Thu, 10 Apr 2025 16:13:49 +0800
Subject: [PATCH] memory:Optimize flatview ioeventfd processing
When updating memory regions, do not repeat updates for the same memory region
to optimize the memory region update process
Signed-off-by: libai <libai12@huawei.com>
---
include/exec/memory.h | 2 ++
system/memory.c | 26 +++++++++++++++++++++++++-
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 69021ba491..fe27f323b2 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1201,6 +1201,8 @@ struct FlatView {
unsigned nr_allocated;
struct AddressSpaceDispatch *dispatch;
MemoryRegion *root;
+ #define FLATVIEW_FLAG_LAST_PROCESSED (1 << 0)
+ unsigned flags;
};
static inline FlatView *address_space_to_flatview(AddressSpace *as)
diff --git a/system/memory.c b/system/memory.c
index 08d34262c3..7858aa1878 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -856,6 +856,13 @@ static void address_space_update_ioeventfds(AddressSpace *as)
return;
}
+ view = address_space_get_flatview(as);
+ if (view->flags & FLATVIEW_FLAG_LAST_PROCESSED) {
+ flatview_unref(view);
+ return;
+ }
+ view->flags |= FLATVIEW_FLAG_LAST_PROCESSED;
+
/*
* 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
@@ -864,7 +871,6 @@ static void address_space_update_ioeventfds(AddressSpace *as)
ioeventfd_max = QEMU_ALIGN_UP(as->ioeventfd_nb, 4);
ioeventfds = g_new(MemoryRegionIoeventfd, ioeventfd_max);
- view = address_space_get_flatview(as);
FOR_EACH_FLAT_RANGE(fr, view) {
for (i = 0; i < fr->mr->ioeventfd_nb; ++i) {
tmp = addrrange_shift(fr->mr->ioeventfds[i].addr,
@@ -1111,6 +1117,17 @@ static void address_space_update_topology(AddressSpace *as)
address_space_set_flatview(as);
}
+static void address_space_update_view(AddressSpace *as)
+{
+ FlatView *view;
+
+ view = address_space_get_flatview(as);
+ if (view->flags & FLATVIEW_FLAG_LAST_PROCESSED) {
+ view->flags &= ~FLATVIEW_FLAG_LAST_PROCESSED;
+ }
+ flatview_unref(view);
+}
+
void memory_region_transaction_begin(void)
{
qemu_flush_coalesced_mmio_buffer();
@@ -1132,6 +1149,9 @@ void memory_region_commit(void)
}
memory_region_update_pending = false;
ioeventfd_update_pending = false;
+ QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
+ address_space_update_view(as);
+ }
MEMORY_LISTENER_CALL_GLOBAL(commit, Forward);
} else if (ioeventfd_update_pending) {
MEMORY_LISTENER_CALL_GLOBAL(eventfd_begin, Forward);
@@ -1139,6 +1159,9 @@ void memory_region_commit(void)
address_space_update_ioeventfds(as);
}
ioeventfd_update_pending = false;
+ QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
+ address_space_update_view(as);
+ }
MEMORY_LISTENER_CALL_GLOBAL(eventfd_end, Forward);
}
}
@@ -3149,6 +3172,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
as->name = g_strdup(name ? name : "anonymous");
address_space_update_topology(as);
address_space_update_ioeventfds(as);
+ address_space_update_view(as);
}
static void do_address_space_destroy(AddressSpace *as)
--
2.41.0.windows.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。