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

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