Blame SOURCES/kvm-migration-introduce-control_save_page.patch

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