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

1bdc94
From 81bfa8602be9c36955c451db641e66546732c59a Mon Sep 17 00:00:00 2001
1bdc94
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
1bdc94
Date: Fri, 22 Jun 2018 18:59:55 +0200
1bdc94
Subject: [PATCH 16/57] migration: move calling save_zero_page to the common
1bdc94
 place
1bdc94
1bdc94
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
1bdc94
Message-id: <20180622190005.21297-9-dgilbert@redhat.com>
1bdc94
Patchwork-id: 81006
1bdc94
O-Subject: [RHEL7.6 qemu-kvm-rhev PATCH 08/18] migration: move calling save_zero_page to the common place
1bdc94
Bugzilla: 1584139
1bdc94
RH-Acked-by: Peter Xu <peterx@redhat.com>
1bdc94
RH-Acked-by: Juan Quintela <quintela@redhat.com>
1bdc94
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
1bdc94
1bdc94
From: Xiao Guangrong <xiaoguangrong@tencent.com>
1bdc94
1bdc94
save_zero_page() is always our first approach to try, move it to
1bdc94
the common place before calling ram_save_compressed_page
1bdc94
and ram_save_page
1bdc94
1bdc94
Reviewed-by: Peter Xu <peterx@redhat.com>
1bdc94
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1bdc94
Signed-off-by: Xiao Guangrong <xiaoguangrong@tencent.com>
1bdc94
Message-Id: <20180330075128.26919-9-xiaoguangrong@tencent.com>
1bdc94
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1bdc94
(cherry picked from commit d7400a3409982a52ac451cd3ca9caee9db670ca7)
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 migration/ram.c | 105 +++++++++++++++++++++++++++++++-------------------------
1bdc94
 1 file changed, 59 insertions(+), 46 deletions(-)
1bdc94
1bdc94
diff --git a/migration/ram.c b/migration/ram.c
1bdc94
index 9d6c41c..6e8a7e2 100644
1bdc94
--- a/migration/ram.c
1bdc94
+++ b/migration/ram.c
1bdc94
@@ -1039,15 +1039,8 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_stage)
1bdc94
     trace_ram_save_page(block->idstr, (uint64_t)offset, p);
1bdc94
 
1bdc94
     XBZRLE_cache_lock();
1bdc94
-    pages = save_zero_page(rs, block, offset);
1bdc94
-    if (pages > 0) {
1bdc94
-        /* Must let xbzrle know, otherwise a previous (now 0'd) cached
1bdc94
-         * page would be stale
1bdc94
-         */
1bdc94
-        xbzrle_cache_zero_page(rs, current_addr);
1bdc94
-        ram_release_pages(block->idstr, offset, pages);
1bdc94
-    } else if (!rs->ram_bulk_stage &&
1bdc94
-               !migration_in_postcopy() && migrate_use_xbzrle()) {
1bdc94
+    if (!rs->ram_bulk_stage && !migration_in_postcopy() &&
1bdc94
+        migrate_use_xbzrle()) {
1bdc94
         pages = save_xbzrle_page(rs, &p, current_addr, block,
1bdc94
                                  offset, last_stage);
1bdc94
         if (!last_stage) {
1bdc94
@@ -1195,40 +1188,23 @@ static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss,
1bdc94
 
1bdc94
     p = block->host + offset;
1bdc94
 
1bdc94
-    /* When starting the process of a new block, the first page of
1bdc94
-     * the block should be sent out before other pages in the same
1bdc94
-     * block, and all the pages in last block should have been sent
1bdc94
-     * out, keeping this order is important, because the 'cont' flag
1bdc94
-     * is used to avoid resending the block name.
1bdc94
-     */
1bdc94
     if (block != rs->last_sent_block) {
1bdc94
-        flush_compressed_data(rs);
1bdc94
-        pages = save_zero_page(rs, block, offset);
1bdc94
-        if (pages > 0) {
1bdc94
-            ram_release_pages(block->idstr, offset, pages);
1bdc94
-        } else {
1bdc94
-            /*
1bdc94
-             * Make sure the first page is sent out before other pages.
1bdc94
-             *
1bdc94
-             * we post it as normal page as compression will take much
1bdc94
-             * CPU resource.
1bdc94
-             */
1bdc94
-            ram_counters.transferred += save_page_header(rs, rs->f, block,
1bdc94
-                                            offset | RAM_SAVE_FLAG_PAGE);
1bdc94
-            qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE,
1bdc94
-                                  migrate_release_ram() &
1bdc94
-                                  migration_in_postcopy());
1bdc94
-            ram_counters.transferred += TARGET_PAGE_SIZE;
1bdc94
-            ram_counters.normal++;
1bdc94
-            pages = 1;
1bdc94
-        }
1bdc94
+        /*
1bdc94
+         * Make sure the first page is sent out before other pages.
1bdc94
+         *
1bdc94
+         * we post it as normal page as compression will take much
1bdc94
+         * CPU resource.
1bdc94
+         */
1bdc94
+        ram_counters.transferred += save_page_header(rs, rs->f, block,
1bdc94
+                                        offset | RAM_SAVE_FLAG_PAGE);
1bdc94
+        qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE,
1bdc94
+                              migrate_release_ram() &
1bdc94
+                              migration_in_postcopy());
1bdc94
+        ram_counters.transferred += TARGET_PAGE_SIZE;
1bdc94
+        ram_counters.normal++;
1bdc94
+        pages = 1;
1bdc94
     } else {
1bdc94
-        pages = save_zero_page(rs, block, offset);
1bdc94
-        if (pages == -1) {
1bdc94
-            pages = compress_page_with_multi_thread(rs, block, offset);
1bdc94
-        } else {
1bdc94
-            ram_release_pages(block->idstr, offset, pages);
1bdc94
-        }
1bdc94
+        pages = compress_page_with_multi_thread(rs, block, offset);
1bdc94
     }
1bdc94
 
1bdc94
     return pages;
1bdc94
@@ -1470,6 +1446,24 @@ err:
1bdc94
     return -1;
1bdc94
 }
1bdc94
 
1bdc94
+static bool save_page_use_compression(RAMState *rs)
1bdc94
+{
1bdc94
+    if (!migrate_use_compression()) {
1bdc94
+        return false;
1bdc94
+    }
1bdc94
+
1bdc94
+    /*
1bdc94
+     * If xbzrle is on, stop using the data compression after first
1bdc94
+     * round of migration even if compression is enabled. In theory,
1bdc94
+     * xbzrle can do better than compression.
1bdc94
+     */
1bdc94
+    if (rs->ram_bulk_stage || !migrate_use_xbzrle()) {
1bdc94
+        return true;
1bdc94
+    }
1bdc94
+
1bdc94
+    return false;
1bdc94
+}
1bdc94
+
1bdc94
 /**
1bdc94
  * ram_save_target_page: save one target page
1bdc94
  *
1bdc94
@@ -1491,12 +1485,31 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss,
1bdc94
     }
1bdc94
 
1bdc94
     /*
1bdc94
-     * If xbzrle is on, stop using the data compression after first
1bdc94
-     * round of migration even if compression is enabled. In theory,
1bdc94
-     * xbzrle can do better than compression.
1bdc94
+     * When starting the process of a new block, the first page of
1bdc94
+     * the block should be sent out before other pages in the same
1bdc94
+     * block, and all the pages in last block should have been sent
1bdc94
+     * out, keeping this order is important, because the 'cont' flag
1bdc94
+     * is used to avoid resending the block name.
1bdc94
      */
1bdc94
-    if (migrate_use_compression() &&
1bdc94
-        (rs->ram_bulk_stage || !migrate_use_xbzrle())) {
1bdc94
+    if (block != rs->last_sent_block && save_page_use_compression(rs)) {
1bdc94
+            flush_compressed_data(rs);
1bdc94
+    }
1bdc94
+
1bdc94
+    res = save_zero_page(rs, block, offset);
1bdc94
+    if (res > 0) {
1bdc94
+        /* Must let xbzrle know, otherwise a previous (now 0'd) cached
1bdc94
+         * page would be stale
1bdc94
+         */
1bdc94
+        if (!save_page_use_compression(rs)) {
1bdc94
+            XBZRLE_cache_lock();
1bdc94
+            xbzrle_cache_zero_page(rs, block->offset + offset);
1bdc94
+            XBZRLE_cache_unlock();
1bdc94
+        }
1bdc94
+        ram_release_pages(block->idstr, offset, res);
1bdc94
+        return res;
1bdc94
+    }
1bdc94
+
1bdc94
+    if (save_page_use_compression(rs)) {
1bdc94
         return ram_save_compressed_page(rs, pss, last_stage);
1bdc94
     }
1bdc94
 
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94