ae23c9
From d66f4034a5aa54082d467584d90db79c52bd001c Mon Sep 17 00:00:00 2001
ae23c9
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
ae23c9
Date: Wed, 1 Aug 2018 13:55:13 +0100
ae23c9
Subject: [PATCH 09/21] migration: introduce save_normal_page()
ae23c9
ae23c9
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
ae23c9
Message-id: <20180801135522.11658-10-dgilbert@redhat.com>
ae23c9
Patchwork-id: 81566
ae23c9
O-Subject: [qemu-kvm RHEL8/virt212 PATCH 09/18] migration: introduce save_normal_page()
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
It directly sends the page to the stream neither checking zero nor
ae23c9
using xbzrle or compression
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-10-xiaoguangrong@tencent.com>
ae23c9
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ae23c9
(cherry picked from commit 65dacaa04fa7e6104cbcee9251c7845355769a10)
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 migration/ram.c | 50 ++++++++++++++++++++++++++++++--------------------
ae23c9
 1 file changed, 30 insertions(+), 20 deletions(-)
ae23c9
ae23c9
diff --git a/migration/ram.c b/migration/ram.c
ae23c9
index 6e8a7e2..908879f 100644
ae23c9
--- a/migration/ram.c
ae23c9
+++ b/migration/ram.c
ae23c9
@@ -1013,6 +1013,34 @@ static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t offset,
ae23c9
     return true;
ae23c9
 }
ae23c9
 
ae23c9
+/*
ae23c9
+ * directly send the page to the stream
ae23c9
+ *
ae23c9
+ * Returns the number of pages written.
ae23c9
+ *
ae23c9
+ * @rs: current RAM state
ae23c9
+ * @block: block that contains the page we want to send
ae23c9
+ * @offset: offset inside the block for the page
ae23c9
+ * @buf: the page to be sent
ae23c9
+ * @async: send to page asyncly
ae23c9
+ */
ae23c9
+static int save_normal_page(RAMState *rs, RAMBlock *block, ram_addr_t offset,
ae23c9
+                            uint8_t *buf, bool async)
ae23c9
+{
ae23c9
+    ram_counters.transferred += save_page_header(rs, rs->f, block,
ae23c9
+                                                 offset | RAM_SAVE_FLAG_PAGE);
ae23c9
+    if (async) {
ae23c9
+        qemu_put_buffer_async(rs->f, buf, TARGET_PAGE_SIZE,
ae23c9
+                              migrate_release_ram() &
ae23c9
+                              migration_in_postcopy());
ae23c9
+    } else {
ae23c9
+        qemu_put_buffer(rs->f, buf, TARGET_PAGE_SIZE);
ae23c9
+    }
ae23c9
+    ram_counters.transferred += TARGET_PAGE_SIZE;
ae23c9
+    ram_counters.normal++;
ae23c9
+    return 1;
ae23c9
+}
ae23c9
+
ae23c9
 /**
ae23c9
  * ram_save_page: send the given page to the stream
ae23c9
  *
ae23c9
@@ -1053,18 +1081,7 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_stage)
ae23c9
 
ae23c9
     /* XBZRLE overflow or normal page */
ae23c9
     if (pages == -1) {
ae23c9
-        ram_counters.transferred +=
ae23c9
-            save_page_header(rs, rs->f, block, offset | RAM_SAVE_FLAG_PAGE);
ae23c9
-        if (send_async) {
ae23c9
-            qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE,
ae23c9
-                                  migrate_release_ram() &
ae23c9
-                                  migration_in_postcopy());
ae23c9
-        } else {
ae23c9
-            qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE);
ae23c9
-        }
ae23c9
-        ram_counters.transferred += TARGET_PAGE_SIZE;
ae23c9
-        pages = 1;
ae23c9
-        ram_counters.normal++;
ae23c9
+        pages = save_normal_page(rs, block, offset, p, send_async);
ae23c9
     }
ae23c9
 
ae23c9
     XBZRLE_cache_unlock();
ae23c9
@@ -1195,14 +1212,7 @@ static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss,
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
+        pages = save_normal_page(rs, block, offset, p, true);
ae23c9
     } else {
ae23c9
         pages = compress_page_with_multi_thread(rs, block, offset);
ae23c9
     }
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9