thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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