Blame SOURCES/kvm-migration-move-calling-save_zero_page-to-the-common-.patch

383d26
From 81bfa8602be9c36955c451db641e66546732c59a Mon Sep 17 00:00:00 2001
383d26
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
383d26
Date: Fri, 22 Jun 2018 18:59:55 +0200
383d26
Subject: [PATCH 16/57] migration: move calling save_zero_page to the common
383d26
 place
383d26
383d26
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
383d26
Message-id: <20180622190005.21297-9-dgilbert@redhat.com>
383d26
Patchwork-id: 81006
383d26
O-Subject: [RHEL7.6 qemu-kvm-rhev PATCH 08/18] migration: move calling save_zero_page to the common place
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
save_zero_page() is always our first approach to try, move it to
383d26
the common place before calling ram_save_compressed_page
383d26
and ram_save_page
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-9-xiaoguangrong@tencent.com>
383d26
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
383d26
(cherry picked from commit d7400a3409982a52ac451cd3ca9caee9db670ca7)
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 migration/ram.c | 105 +++++++++++++++++++++++++++++++-------------------------
383d26
 1 file changed, 59 insertions(+), 46 deletions(-)
383d26
383d26
diff --git a/migration/ram.c b/migration/ram.c
383d26
index 9d6c41c..6e8a7e2 100644
383d26
--- a/migration/ram.c
383d26
+++ b/migration/ram.c
383d26
@@ -1039,15 +1039,8 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_stage)
383d26
     trace_ram_save_page(block->idstr, (uint64_t)offset, p);
383d26
 
383d26
     XBZRLE_cache_lock();
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
+    if (!rs->ram_bulk_stage && !migration_in_postcopy() &&
383d26
+        migrate_use_xbzrle()) {
383d26
         pages = save_xbzrle_page(rs, &p, current_addr, block,
383d26
                                  offset, last_stage);
383d26
         if (!last_stage) {
383d26
@@ -1195,40 +1188,23 @@ static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss,
383d26
 
383d26
     p = block->host + offset;
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
+        /*
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
     } 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
+        pages = compress_page_with_multi_thread(rs, block, offset);
383d26
     }
383d26
 
383d26
     return pages;
383d26
@@ -1470,6 +1446,24 @@ err:
383d26
     return -1;
383d26
 }
383d26
 
383d26
+static bool save_page_use_compression(RAMState *rs)
383d26
+{
383d26
+    if (!migrate_use_compression()) {
383d26
+        return false;
383d26
+    }
383d26
+
383d26
+    /*
383d26
+     * If xbzrle is on, stop using the data compression after first
383d26
+     * round of migration even if compression is enabled. In theory,
383d26
+     * xbzrle can do better than compression.
383d26
+     */
383d26
+    if (rs->ram_bulk_stage || !migrate_use_xbzrle()) {
383d26
+        return true;
383d26
+    }
383d26
+
383d26
+    return false;
383d26
+}
383d26
+
383d26
 /**
383d26
  * ram_save_target_page: save one target page
383d26
  *
383d26
@@ -1491,12 +1485,31 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss,
383d26
     }
383d26
 
383d26
     /*
383d26
-     * If xbzrle is on, stop using the data compression after first
383d26
-     * round of migration even if compression is enabled. In theory,
383d26
-     * xbzrle can do better than compression.
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 (migrate_use_compression() &&
383d26
-        (rs->ram_bulk_stage || !migrate_use_xbzrle())) {
383d26
+    if (block != rs->last_sent_block && save_page_use_compression(rs)) {
383d26
+            flush_compressed_data(rs);
383d26
+    }
383d26
+
383d26
+    res = save_zero_page(rs, block, offset);
383d26
+    if (res > 0) {
383d26
+        /* Must let xbzrle know, otherwise a previous (now 0'd) cached
383d26
+         * page would be stale
383d26
+         */
383d26
+        if (!save_page_use_compression(rs)) {
383d26
+            XBZRLE_cache_lock();
383d26
+            xbzrle_cache_zero_page(rs, block->offset + offset);
383d26
+            XBZRLE_cache_unlock();
383d26
+        }
383d26
+        ram_release_pages(block->idstr, offset, res);
383d26
+        return res;
383d26
+    }
383d26
+
383d26
+    if (save_page_use_compression(rs)) {
383d26
         return ram_save_compressed_page(rs, pss, last_stage);
383d26
     }
383d26
 
383d26
-- 
383d26
1.8.3.1
383d26