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