yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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