|
|
ae23c9 |
From 6d52c264fa9a7a78ee532f45d24704491ce4c431 Mon Sep 17 00:00:00 2001
|
|
|
ae23c9 |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
ae23c9 |
Date: Wed, 1 Aug 2018 13:55:09 +0100
|
|
|
ae23c9 |
Subject: [PATCH 05/21] migration: introduce control_save_page()
|
|
|
ae23c9 |
|
|
|
ae23c9 |
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ae23c9 |
Message-id: <20180801135522.11658-6-dgilbert@redhat.com>
|
|
|
ae23c9 |
Patchwork-id: 81581
|
|
|
ae23c9 |
O-Subject: [qemu-kvm RHEL8/virt212 PATCH 05/18] migration: introduce control_save_page()
|
|
|
ae23c9 |
Bugzilla: 1594384
|
|
|
ae23c9 |
RH-Acked-by: Peter Xu <peterx@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Juan Quintela <quintela@redhat.com>
|
|
|
ae23c9 |
|
|
|
ae23c9 |
From: Xiao Guangrong <xiaoguangrong@tencent.com>
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Abstract the common function control_save_page() to cleanup the code,
|
|
|
ae23c9 |
no logic is changed
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Reviewed-by: Peter Xu <peterx@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ae23c9 |
Signed-off-by: Xiao Guangrong <xiaoguangrong@tencent.com>
|
|
|
ae23c9 |
Message-Id: <20180330075128.26919-6-xiaoguangrong@tencent.com>
|
|
|
ae23c9 |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ae23c9 |
(cherry picked from commit 059ff0fb29dd3a56ac2843676915efc279938c6b)
|
|
|
ae23c9 |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
ae23c9 |
---
|
|
|
ae23c9 |
migration/ram.c | 174 +++++++++++++++++++++++++++++---------------------------
|
|
|
ae23c9 |
1 file changed, 89 insertions(+), 85 deletions(-)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/migration/ram.c b/migration/ram.c
|
|
|
ae23c9 |
index cd6d98a..8dc98a5 100644
|
|
|
ae23c9 |
--- a/migration/ram.c
|
|
|
ae23c9 |
+++ b/migration/ram.c
|
|
|
ae23c9 |
@@ -975,6 +975,44 @@ static void ram_release_pages(const char *rbname, uint64_t offset, int pages)
|
|
|
ae23c9 |
ram_discard_range(rbname, offset, pages << TARGET_PAGE_BITS);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
+/*
|
|
|
ae23c9 |
+ * @pages: the number of pages written by the control path,
|
|
|
ae23c9 |
+ * < 0 - error
|
|
|
ae23c9 |
+ * > 0 - number of pages written
|
|
|
ae23c9 |
+ *
|
|
|
ae23c9 |
+ * Return true if the pages has been saved, otherwise false is returned.
|
|
|
ae23c9 |
+ */
|
|
|
ae23c9 |
+static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t offset,
|
|
|
ae23c9 |
+ int *pages)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ uint64_t bytes_xmit = 0;
|
|
|
ae23c9 |
+ int ret;
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ *pages = -1;
|
|
|
ae23c9 |
+ ret = ram_control_save_page(rs->f, block->offset, offset, TARGET_PAGE_SIZE,
|
|
|
ae23c9 |
+ &bytes_xmit);
|
|
|
ae23c9 |
+ if (ret == RAM_SAVE_CONTROL_NOT_SUPP) {
|
|
|
ae23c9 |
+ return false;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ if (bytes_xmit) {
|
|
|
ae23c9 |
+ ram_counters.transferred += bytes_xmit;
|
|
|
ae23c9 |
+ *pages = 1;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ if (ret == RAM_SAVE_CONTROL_DELAYED) {
|
|
|
ae23c9 |
+ return true;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ if (bytes_xmit > 0) {
|
|
|
ae23c9 |
+ ram_counters.normal++;
|
|
|
ae23c9 |
+ } else if (bytes_xmit == 0) {
|
|
|
ae23c9 |
+ ram_counters.duplicate++;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ return true;
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
/**
|
|
|
ae23c9 |
* ram_save_page: send the given page to the stream
|
|
|
ae23c9 |
*
|
|
|
ae23c9 |
@@ -991,56 +1029,36 @@ static void ram_release_pages(const char *rbname, uint64_t offset, int pages)
|
|
|
ae23c9 |
static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_stage)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
int pages = -1;
|
|
|
ae23c9 |
- uint64_t bytes_xmit;
|
|
|
ae23c9 |
- ram_addr_t current_addr;
|
|
|
ae23c9 |
uint8_t *p;
|
|
|
ae23c9 |
- int ret;
|
|
|
ae23c9 |
bool send_async = true;
|
|
|
ae23c9 |
RAMBlock *block = pss->block;
|
|
|
ae23c9 |
ram_addr_t offset = pss->page << TARGET_PAGE_BITS;
|
|
|
ae23c9 |
+ ram_addr_t current_addr = block->offset + offset;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
p = block->host + offset;
|
|
|
ae23c9 |
trace_ram_save_page(block->idstr, (uint64_t)offset, p);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
- /* In doubt sent page as normal */
|
|
|
ae23c9 |
- bytes_xmit = 0;
|
|
|
ae23c9 |
- ret = ram_control_save_page(rs->f, block->offset,
|
|
|
ae23c9 |
- offset, TARGET_PAGE_SIZE, &bytes_xmit);
|
|
|
ae23c9 |
- if (bytes_xmit) {
|
|
|
ae23c9 |
- ram_counters.transferred += bytes_xmit;
|
|
|
ae23c9 |
- pages = 1;
|
|
|
ae23c9 |
+ if (control_save_page(rs, block, offset, &pages)) {
|
|
|
ae23c9 |
+ return pages;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
XBZRLE_cache_lock();
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
- current_addr = block->offset + offset;
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
- if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
|
|
|
ae23c9 |
- if (ret != RAM_SAVE_CONTROL_DELAYED) {
|
|
|
ae23c9 |
- if (bytes_xmit > 0) {
|
|
|
ae23c9 |
- ram_counters.normal++;
|
|
|
ae23c9 |
- } else if (bytes_xmit == 0) {
|
|
|
ae23c9 |
- ram_counters.duplicate++;
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
- } else {
|
|
|
ae23c9 |
- pages = save_zero_page(rs, block, offset);
|
|
|
ae23c9 |
- if (pages > 0) {
|
|
|
ae23c9 |
- /* Must let xbzrle know, otherwise a previous (now 0'd) cached
|
|
|
ae23c9 |
- * page would be stale
|
|
|
ae23c9 |
+ pages = save_zero_page(rs, block, offset);
|
|
|
ae23c9 |
+ if (pages > 0) {
|
|
|
ae23c9 |
+ /* Must let xbzrle know, otherwise a previous (now 0'd) cached
|
|
|
ae23c9 |
+ * page would be stale
|
|
|
ae23c9 |
+ */
|
|
|
ae23c9 |
+ xbzrle_cache_zero_page(rs, current_addr);
|
|
|
ae23c9 |
+ ram_release_pages(block->idstr, offset, pages);
|
|
|
ae23c9 |
+ } else if (!rs->ram_bulk_stage &&
|
|
|
ae23c9 |
+ !migration_in_postcopy() && migrate_use_xbzrle()) {
|
|
|
ae23c9 |
+ pages = save_xbzrle_page(rs, &p, current_addr, block,
|
|
|
ae23c9 |
+ offset, last_stage);
|
|
|
ae23c9 |
+ if (!last_stage) {
|
|
|
ae23c9 |
+ /* Can't send this cached data async, since the cache page
|
|
|
ae23c9 |
+ * might get updated before it gets to the wire
|
|
|
ae23c9 |
*/
|
|
|
ae23c9 |
- xbzrle_cache_zero_page(rs, current_addr);
|
|
|
ae23c9 |
- ram_release_pages(block->idstr, offset, pages);
|
|
|
ae23c9 |
- } else if (!rs->ram_bulk_stage &&
|
|
|
ae23c9 |
- !migration_in_postcopy() && migrate_use_xbzrle()) {
|
|
|
ae23c9 |
- pages = save_xbzrle_page(rs, &p, current_addr, block,
|
|
|
ae23c9 |
- offset, last_stage);
|
|
|
ae23c9 |
- if (!last_stage) {
|
|
|
ae23c9 |
- /* Can't send this cached data async, since the cache page
|
|
|
ae23c9 |
- * might get updated before it gets to the wire
|
|
|
ae23c9 |
- */
|
|
|
ae23c9 |
- send_async = false;
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
+ send_async = false;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
@@ -1175,63 +1193,49 @@ static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss,
|
|
|
ae23c9 |
bool last_stage)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
int pages = -1;
|
|
|
ae23c9 |
- uint64_t bytes_xmit = 0;
|
|
|
ae23c9 |
uint8_t *p;
|
|
|
ae23c9 |
- int ret;
|
|
|
ae23c9 |
RAMBlock *block = pss->block;
|
|
|
ae23c9 |
ram_addr_t offset = pss->page << TARGET_PAGE_BITS;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
p = block->host + offset;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
- ret = ram_control_save_page(rs->f, block->offset,
|
|
|
ae23c9 |
- offset, TARGET_PAGE_SIZE, &bytes_xmit);
|
|
|
ae23c9 |
- if (bytes_xmit) {
|
|
|
ae23c9 |
- ram_counters.transferred += bytes_xmit;
|
|
|
ae23c9 |
- pages = 1;
|
|
|
ae23c9 |
+ if (control_save_page(rs, block, offset, &pages)) {
|
|
|
ae23c9 |
+ return pages;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
- if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
|
|
|
ae23c9 |
- if (ret != RAM_SAVE_CONTROL_DELAYED) {
|
|
|
ae23c9 |
- if (bytes_xmit > 0) {
|
|
|
ae23c9 |
- ram_counters.normal++;
|
|
|
ae23c9 |
- } else if (bytes_xmit == 0) {
|
|
|
ae23c9 |
- ram_counters.duplicate++;
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ /* When starting the process of a new block, the first page of
|
|
|
ae23c9 |
+ * the block should be sent out before other pages in the same
|
|
|
ae23c9 |
+ * block, and all the pages in last block should have been sent
|
|
|
ae23c9 |
+ * out, keeping this order is important, because the 'cont' flag
|
|
|
ae23c9 |
+ * is used to avoid resending the block name.
|
|
|
ae23c9 |
+ */
|
|
|
ae23c9 |
+ if (block != rs->last_sent_block) {
|
|
|
ae23c9 |
+ flush_compressed_data(rs);
|
|
|
ae23c9 |
+ pages = save_zero_page(rs, block, offset);
|
|
|
ae23c9 |
+ if (pages > 0) {
|
|
|
ae23c9 |
+ ram_release_pages(block->idstr, offset, pages);
|
|
|
ae23c9 |
+ } else {
|
|
|
ae23c9 |
+ /*
|
|
|
ae23c9 |
+ * Make sure the first page is sent out before other pages.
|
|
|
ae23c9 |
+ *
|
|
|
ae23c9 |
+ * we post it as normal page as compression will take much
|
|
|
ae23c9 |
+ * CPU resource.
|
|
|
ae23c9 |
+ */
|
|
|
ae23c9 |
+ ram_counters.transferred += save_page_header(rs, rs->f, block,
|
|
|
ae23c9 |
+ offset | RAM_SAVE_FLAG_PAGE);
|
|
|
ae23c9 |
+ qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE,
|
|
|
ae23c9 |
+ migrate_release_ram() &
|
|
|
ae23c9 |
+ migration_in_postcopy());
|
|
|
ae23c9 |
+ ram_counters.transferred += TARGET_PAGE_SIZE;
|
|
|
ae23c9 |
+ ram_counters.normal++;
|
|
|
ae23c9 |
+ pages = 1;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
} else {
|
|
|
ae23c9 |
- /* When starting the process of a new block, the first page of
|
|
|
ae23c9 |
- * the block should be sent out before other pages in the same
|
|
|
ae23c9 |
- * block, and all the pages in last block should have been sent
|
|
|
ae23c9 |
- * out, keeping this order is important, because the 'cont' flag
|
|
|
ae23c9 |
- * is used to avoid resending the block name.
|
|
|
ae23c9 |
- */
|
|
|
ae23c9 |
- if (block != rs->last_sent_block) {
|
|
|
ae23c9 |
- flush_compressed_data(rs);
|
|
|
ae23c9 |
- pages = save_zero_page(rs, block, offset);
|
|
|
ae23c9 |
- if (pages > 0) {
|
|
|
ae23c9 |
- ram_release_pages(block->idstr, offset, pages);
|
|
|
ae23c9 |
- } else {
|
|
|
ae23c9 |
- /*
|
|
|
ae23c9 |
- * Make sure the first page is sent out before other pages.
|
|
|
ae23c9 |
- *
|
|
|
ae23c9 |
- * we post it as normal page as compression will take much
|
|
|
ae23c9 |
- * CPU resource.
|
|
|
ae23c9 |
- */
|
|
|
ae23c9 |
- ram_counters.transferred += save_page_header(rs, rs->f, block,
|
|
|
ae23c9 |
- offset | RAM_SAVE_FLAG_PAGE);
|
|
|
ae23c9 |
- qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE,
|
|
|
ae23c9 |
- migrate_release_ram() &
|
|
|
ae23c9 |
- migration_in_postcopy());
|
|
|
ae23c9 |
- ram_counters.transferred += TARGET_PAGE_SIZE;
|
|
|
ae23c9 |
- ram_counters.normal++;
|
|
|
ae23c9 |
- pages = 1;
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
+ pages = save_zero_page(rs, block, offset);
|
|
|
ae23c9 |
+ if (pages == -1) {
|
|
|
ae23c9 |
+ pages = compress_page_with_multi_thread(rs, block, offset);
|
|
|
ae23c9 |
} else {
|
|
|
ae23c9 |
- pages = save_zero_page(rs, block, offset);
|
|
|
ae23c9 |
- if (pages == -1) {
|
|
|
ae23c9 |
- pages = compress_page_with_multi_thread(rs, block, offset);
|
|
|
ae23c9 |
- } else {
|
|
|
ae23c9 |
- ram_release_pages(block->idstr, offset, pages);
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
+ ram_release_pages(block->idstr, offset, pages);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
--
|
|
|
ae23c9 |
1.8.3.1
|
|
|
ae23c9 |
|