Test hook is disabled by default. To set it, a normal page ratio
between 0 and 100 are valid. If the ratio is set to 50, it means
at least 50% of all pages are sent as normal pages.
Set the option:
migrate_set_parameter multifd-normal-page-ratio 60
Signed-off-by: Hao Xiang <hao.xiang@bytedance.com>
---
include/qemu/dsa.h | 5 ++++-
migration/migration-hmp-cmds.c | 7 +++++++
migration/multifd.c | 33 +++++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h
index fe7772107a..ac3d8b51f4 100644
--- a/include/qemu/dsa.h
+++ b/include/qemu/dsa.h
@@ -38,7 +38,7 @@ typedef struct dsa_batch_task {
QemuSemaphore sem_task_complete;
DsaTaskType task_type;
DsaTaskStatus status;
- int batch_size;
+ uint32_t batch_size;
bool *results;
QSIMPLEQ_ENTRY(dsa_batch_task) entry;
} dsa_batch_task;
@@ -50,6 +50,9 @@ struct batch_task {
ram_addr_t *addr;
/* Zero page checking results */
bool *results;
+ /* Set normal page ratio test hook. */
+ uint32_t normal_page_index;
+ uint32_t normal_page_counter;
#ifdef CONFIG_DSA_OPT
struct dsa_batch_task *dsa_batch;
#endif
diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c
index 761d6d54de..8219d112d6 100644
--- a/migration/migration-hmp-cmds.c
+++ b/migration/migration-hmp-cmds.c
@@ -356,6 +356,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
monitor_printf(mon, "%s: '%s'\n",
MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_DSA_ACCEL),
params->multifd_dsa_accel);
+ monitor_printf(mon, "%s: %u\n",
+ MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_NORMAL_PAGE_RATIO),
+ params->multifd_normal_page_ratio);
if (params->has_block_bitmap_mapping) {
const BitmapMigrationNodeAliasList *bmnal;
@@ -675,6 +678,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
error_setg(&err, "The block-bitmap-mapping parameter can only be set "
"through QMP");
break;
+ case MIGRATION_PARAMETER_MULTIFD_NORMAL_PAGE_RATIO:
+ p->has_multifd_normal_page_ratio = true;
+ visit_type_uint8(v, param, &p->multifd_normal_page_ratio, &err);
+ break;
case MIGRATION_PARAMETER_X_VCPU_DIRTY_LIMIT_PERIOD:
p->has_x_vcpu_dirty_limit_period = true;
visit_type_size(v, param, &p->x_vcpu_dirty_limit_period, &err);
diff --git a/migration/multifd.c b/migration/multifd.c
index 6e73d995b0..cfae5401a9 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -683,6 +683,37 @@ int multifd_send_sync_main(QEMUFile *f)
return 0;
}
+static void multifd_normal_page_test_hook(MultiFDSendParams *p)
+{
+ /*
+ * The value is between 0 to 100. If the value is 10, it means at
+ * least 10% of the pages are normal page. A zero page can be made
+ * a normal page but not the other way around.
+ */
+ uint8_t multifd_normal_page_ratio =
+ migrate_multifd_normal_page_ratio();
+ struct batch_task *batch_task = p->batch_task;
+
+ /* Set normal page test hook is disabled. */
+ if (multifd_normal_page_ratio > 100) {
+ return;
+ }
+
+ for (int i = 0; i < p->pages->num; i++) {
+ if (batch_task->normal_page_counter < multifd_normal_page_ratio) {
+ /* Turn a zero page into a normal page. */
+ batch_task->results[i] = false;
+ }
+ batch_task->normal_page_index++;
+ batch_task->normal_page_counter++;
+
+ if (batch_task->normal_page_index >= 100) {
+ batch_task->normal_page_index = 0;
+ batch_task->normal_page_counter = 0;
+ }
+ }
+}
+
static void set_page(MultiFDSendParams *p, bool zero_page, uint64_t offset)
{
RAMBlock *rb = p->pages->block;
@@ -748,6 +779,8 @@ static void multifd_zero_page_check(MultiFDSendParams *p)
set_normal_pages(p);
}
+ multifd_normal_page_test_hook(p);
+
for (int i = 0; i < p->pages->num; i++) {
uint64_t offset = p->pages->offset[i];
bool zero_page = p->batch_task->results[i];
--
2.30.2