[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 9/9] hvf: remove the need to lookup memory slots when clearing
From: |
Yan-Jie Wang |
Subject: |
[PATCH v2 9/9] hvf: remove the need to lookup memory slots when clearing dirty-bits |
Date: |
Wed, 2 Mar 2022 20:26:11 +0800 |
Originally, when log_clear gets called, log_clear calls
hvf_set_dirty_tracking to write-protect memory slots whose dirty-bits
are cleared.
Calling hvf_set_dirty_tracking means that memory slots will be
look up and the lock for memory slots will be held during the call.
We can use the parameter `section` passed by the caller to determine the
pages that need to be write-protected. Compared to the original method,
this saves time.
Moreover, this makes only pages whose dirty-bits
are cleared write-protected instead of making the whole memory slot
write-protected.
Signed-off-by: Yan-Jie Wang <ubzeme@gmail.com>
---
accel/hvf/hvf-mem.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/accel/hvf/hvf-mem.c b/accel/hvf/hvf-mem.c
index b215386bc8..7a588b70e1 100644
--- a/accel/hvf/hvf-mem.c
+++ b/accel/hvf/hvf-mem.c
@@ -84,7 +84,10 @@ static hwaddr hvf_align_section(MemoryRegionSection *section,
size = (size - _delta) & qemu_real_host_page_mask;
*start = _start;
- *delta = _delta;
+
+ if (delta) {
+ *delta = _delta;
+ }
return size;
}
@@ -229,11 +232,21 @@ static void hvf_log_stop(MemoryListener *listener,
static void hvf_log_clear(MemoryListener *listener,
MemoryRegionSection *section)
{
+ hwaddr start, size;
+
+ if (!memory_region_is_ram(section->mr) || memory_region_is_rom(section)) {
+ /* do not consider memory regions which are not directly writeable */
+ return;
+ }
+
/*
* The dirty bits are being cleared.
* Make the section write-protected again.
*/
- hvf_set_dirty_tracking(section, 1);
+ size = hvf_align_section(section, &start, NULL);
+ if (size) {
+ hv_vm_protect(start, size, HV_MEMORY_READ | HV_MEMORY_EXEC);
+ }
}
static void hvf_region_add(MemoryListener *listener,
--
2.32.0 (Apple Git-132)
- [PATCH v2 0/9] Many improvements to HVF memory-related codes, Yan-Jie Wang, 2022/03/02
- [PATCH v2 1/9] hvf: move memory related functions from hvf-accel-ops.c to hvf-mem.c, Yan-Jie Wang, 2022/03/02
- [PATCH v2 2/9] hvf: simplify data structures and codes of memory related functions, Yan-Jie Wang, 2022/03/02
- [PATCH v2 3/9] hvf: use correct data types for addresses in memory related functions, Yan-Jie Wang, 2022/03/02
- [PATCH v2 4/9] hvf: rename struct hvf_slot to HVFSlot, Yan-Jie Wang, 2022/03/02
- [PATCH v2 5/9] hvf: fix memory dirty-tracking, Yan-Jie Wang, 2022/03/02
- [PATCH v2 6/9] hvf: add a lock for memory related functions, Yan-Jie Wang, 2022/03/02
- [PATCH v2 7/9] hvf: use GTree to store memory slots instead of fixed-size array, Yan-Jie Wang, 2022/03/02
- [PATCH v2 8/9] hvf: only consider directly writeable memory regions for dirty-tracking, Yan-Jie Wang, 2022/03/02
- [PATCH v2 9/9] hvf: remove the need to lookup memory slots when clearing dirty-bits,
Yan-Jie Wang <=