[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/11] migration/calc-dirty-rate: replaced CRC32 with xxHash
From: |
Juan Quintela |
Subject: |
[PULL 01/11] migration/calc-dirty-rate: replaced CRC32 with xxHash |
Date: |
Mon, 15 May 2023 14:33:24 +0200 |
From: Andrei Gudkov <gudkov.andrei@huawei.com>
This significantly reduces overhead of dirty page
rate calculation in sampling mode.
Tested using 32GiB VM on E5-2690 CPU.
With CRC32:
total_pages=8388608 sampled_pages=16384 millis=71
With xxHash:
total_pages=8388608 sampled_pages=16384 millis=14
Signed-off-by: Andrei Gudkov <gudkov.andrei@huawei.com>
Message-Id:
<cd115a89fc81d5f2eeb4ea7d57a98b84f794f340.1682598010.git.gudkov.andrei@huawei.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/dirtyrate.c | 45 +++++++++++++++++++++++++++++++++---------
migration/trace-events | 4 ++--
2 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
index 388337a332..5bac984fa5 100644
--- a/migration/dirtyrate.c
+++ b/migration/dirtyrate.c
@@ -29,6 +29,7 @@
#include "sysemu/kvm.h"
#include "sysemu/runstate.h"
#include "exec/memory.h"
+#include "qemu/xxhash.h"
/*
* total_dirty_pages is procted by BQL and is used
@@ -308,6 +309,33 @@ static void update_dirtyrate(uint64_t msec)
DirtyStat.dirty_rate = dirtyrate;
}
+/*
+ * Compute hash of a single page of size TARGET_PAGE_SIZE.
+ */
+static uint32_t compute_page_hash(void *ptr)
+{
+ uint32_t i;
+ uint64_t v1, v2, v3, v4;
+ uint64_t res;
+ const uint64_t *p = ptr;
+
+ v1 = QEMU_XXHASH_SEED + XXH_PRIME64_1 + XXH_PRIME64_2;
+ v2 = QEMU_XXHASH_SEED + XXH_PRIME64_2;
+ v3 = QEMU_XXHASH_SEED + 0;
+ v4 = QEMU_XXHASH_SEED - XXH_PRIME64_1;
+ for (i = 0; i < TARGET_PAGE_SIZE / 8; i += 4) {
+ v1 = XXH64_round(v1, p[i + 0]);
+ v2 = XXH64_round(v2, p[i + 1]);
+ v3 = XXH64_round(v3, p[i + 2]);
+ v4 = XXH64_round(v4, p[i + 3]);
+ }
+ res = XXH64_mergerounds(v1, v2, v3, v4);
+ res += TARGET_PAGE_SIZE;
+ res = XXH64_avalanche(res);
+ return (uint32_t)(res & UINT32_MAX);
+}
+
+
/*
* get hash result for the sampled memory with length of TARGET_PAGE_SIZE
* in ramblock, which starts from ramblock base address.
@@ -315,13 +343,12 @@ static void update_dirtyrate(uint64_t msec)
static uint32_t get_ramblock_vfn_hash(struct RamblockDirtyInfo *info,
uint64_t vfn)
{
- uint32_t crc;
+ uint32_t hash;
- crc = crc32(0, (info->ramblock_addr +
- vfn * TARGET_PAGE_SIZE), TARGET_PAGE_SIZE);
+ hash = compute_page_hash(info->ramblock_addr + vfn * TARGET_PAGE_SIZE);
- trace_get_ramblock_vfn_hash(info->idstr, vfn, crc);
- return crc;
+ trace_get_ramblock_vfn_hash(info->idstr, vfn, hash);
+ return hash;
}
static bool save_ramblock_hash(struct RamblockDirtyInfo *info)
@@ -454,13 +481,13 @@ out:
static void calc_page_dirty_rate(struct RamblockDirtyInfo *info)
{
- uint32_t crc;
+ uint32_t hash;
int i;
for (i = 0; i < info->sample_pages_count; i++) {
- crc = get_ramblock_vfn_hash(info, info->sample_page_vfn[i]);
- if (crc != info->hash_result[i]) {
- trace_calc_page_dirty_rate(info->idstr, crc, info->hash_result[i]);
+ hash = get_ramblock_vfn_hash(info, info->sample_page_vfn[i]);
+ if (hash != info->hash_result[i]) {
+ trace_calc_page_dirty_rate(info->idstr, hash,
info->hash_result[i]);
info->sample_dirty_count++;
}
}
diff --git a/migration/trace-events b/migration/trace-events
index 92161eeac5..f39818c329 100644
--- a/migration/trace-events
+++ b/migration/trace-events
@@ -342,8 +342,8 @@ dirty_bitmap_load_success(void) ""
# dirtyrate.c
dirtyrate_set_state(const char *new_state) "new state %s"
query_dirty_rate_info(const char *new_state) "current state %s"
-get_ramblock_vfn_hash(const char *idstr, uint64_t vfn, uint32_t crc) "ramblock
name: %s, vfn: %"PRIu64 ", crc: %" PRIu32
-calc_page_dirty_rate(const char *idstr, uint32_t new_crc, uint32_t old_crc)
"ramblock name: %s, new crc: %" PRIu32 ", old crc: %" PRIu32
+get_ramblock_vfn_hash(const char *idstr, uint64_t vfn, uint32_t hash)
"ramblock name: %s, vfn: %"PRIu64 ", hash: %" PRIu32
+calc_page_dirty_rate(const char *idstr, uint32_t new_hash, uint32_t old_hash)
"ramblock name: %s, new hash: %" PRIu32 ", old hash: %" PRIu32
skip_sample_ramblock(const char *idstr, uint64_t ramblock_size) "ramblock
name: %s, ramblock size: %" PRIu64
find_page_matched(const char *idstr) "ramblock %s addr or size changed"
dirtyrate_calculate(int64_t dirtyrate) "dirty rate: %" PRIi64 " MB/s"
--
2.40.1
- [PULL 00/11] Migration 20230515 patches, Juan Quintela, 2023/05/15
- [PULL 01/11] migration/calc-dirty-rate: replaced CRC32 with xxHash,
Juan Quintela <=
- [PULL 02/11] softmmu: Create qemu_target_pages_to_MiB(), Juan Quintela, 2023/05/15
- [PULL 07/11] migration: A rate limit value of 0 is valid, Juan Quintela, 2023/05/15
- [PULL 11/11] qemu-file: Remove total from qemu_file_total_transferred_*(), Juan Quintela, 2023/05/15
- [PULL 09/11] qemu-file: make qemu_file_[sg]et_rate_limit() use an uint64_t, Juan Quintela, 2023/05/15
- [PULL 05/11] migration: Teach dirtyrate about qemu_target_page_bits(), Juan Quintela, 2023/05/15
- [PULL 06/11] migration: Make dirtyrate.c target independent, Juan Quintela, 2023/05/15
- [PULL 03/11] Use new created qemu_target_pages_to_MiB(), Juan Quintela, 2023/05/15
- [PULL 04/11] migration: Teach dirtyrate about qemu_target_page_size(), Juan Quintela, 2023/05/15
- [PULL 08/11] migration: We set the rate_limit by a second, Juan Quintela, 2023/05/15
- [PULL 10/11] qemu-file: Make rate_limit_used an uint64_t, Juan Quintela, 2023/05/15