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