0a122b
From 6499b6033f8aff6482cfa7942b0c16b386a519f5 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <6499b6033f8aff6482cfa7942b0c16b386a519f5.1387382496.git.minovotn@redhat.com>
0a122b
In-Reply-To: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
0a122b
References: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
0a122b
From: Nigel Croxon <ncroxon@redhat.com>
0a122b
Date: Thu, 14 Nov 2013 22:52:50 +0100
0a122b
Subject: [PATCH 14/46] rdma: introduce ram_handle_compressed()
0a122b
0a122b
RH-Author: Nigel Croxon <ncroxon@redhat.com>
0a122b
Message-id: <1384469598-13137-15-git-send-email-ncroxon@redhat.com>
0a122b
Patchwork-id: 55706
0a122b
O-Subject: [RHEL7.0 PATCH 14/42] rdma: introduce ram_handle_compressed()
0a122b
Bugzilla: 1011720
0a122b
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
0a122b
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
0a122b
Bugzilla: 1011720
0a122b
https://bugzilla.redhat.com/show_bug.cgi?id=1011720
0a122b
0a122b
>From commit ID:
0a122b
commit 44c3b58cf9b2c91a38363f0b45d20f3f40b8f2b3
0a122b
Author: Michael R. Hines <mrhines@us.ibm.com>
0a122b
Date:   Mon Jul 22 10:01:53 2013 -0400
0a122b
0a122b
    rdma: introduce ram_handle_compressed()
0a122b
0a122b
    This gives RDMA shared access to madvise() on the destination side
0a122b
    when an entire chunk is found to be zero.
0a122b
0a122b
    Reviewed-by: Juan Quintela <quintela@redhat.com>
0a122b
    Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
    Reviewed-by: Chegu Vinod <chegu_vinod@hp.com>
0a122b
    Tested-by: Chegu Vinod <chegu_vinod@hp.com>
0a122b
    Tested-by: Michael R. Hines <mrhines@us.ibm.com>
0a122b
    Signed-off-by: Michael R. Hines <mrhines@us.ibm.com>
0a122b
    Signed-off-by: Juan Quintela <quintela@redhat.com>
0a122b
---
0a122b
 arch_init.c                   |   29 +++++++++++++++++++----------
0a122b
 include/migration/migration.h |    2 ++
0a122b
 2 files changed, 21 insertions(+), 10 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 arch_init.c                   | 29 +++++++++++++++++++----------
0a122b
 include/migration/migration.h |  2 ++
0a122b
 2 files changed, 21 insertions(+), 10 deletions(-)
0a122b
0a122b
diff --git a/arch_init.c b/arch_init.c
0a122b
index e940ede..e7da520 100644
0a122b
--- a/arch_init.c
0a122b
+++ b/arch_init.c
0a122b
@@ -809,6 +809,24 @@ static inline void *host_from_stream_offset(QEMUFile *f,
0a122b
     return NULL;
0a122b
 }
0a122b
 
0a122b
+/*
0a122b
+ * If a page (or a whole RDMA chunk) has been
0a122b
+ * determined to be zero, then zap it.
0a122b
+ */
0a122b
+void ram_handle_compressed(void *host, uint8_t ch, uint64_t size)
0a122b
+{
0a122b
+    if (ch != 0 || !is_zero_page(host)) {
0a122b
+        memset(host, ch, size);
0a122b
+#ifndef _WIN32
0a122b
+        if (ch == 0 &&
0a122b
+            (!kvm_enabled() || kvm_has_sync_mmu()) &&
0a122b
+            getpagesize() <= TARGET_PAGE_SIZE) {
0a122b
+            qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
0a122b
+        }
0a122b
+#endif
0a122b
+    }
0a122b
+}
0a122b
+
0a122b
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
0a122b
 {
0a122b
     ram_addr_t addr;
0a122b
@@ -876,16 +894,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
0a122b
             }
0a122b
 
0a122b
             ch = qemu_get_byte(f);
0a122b
-            if (ch != 0 || !is_zero_page(host)) {
0a122b
-                memset(host, ch, TARGET_PAGE_SIZE);
0a122b
-#ifndef _WIN32
0a122b
-                if (ch == 0 &&
0a122b
-                    (!kvm_enabled() || kvm_has_sync_mmu()) &&
0a122b
-                    getpagesize() <= TARGET_PAGE_SIZE) {
0a122b
-                    qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
0a122b
-                }
0a122b
-#endif
0a122b
-            }
0a122b
+            ram_handle_compressed(host, ch, TARGET_PAGE_SIZE);
0a122b
         } else if (flags & RAM_SAVE_FLAG_PAGE) {
0a122b
             void *host;
0a122b
 
0a122b
diff --git a/include/migration/migration.h b/include/migration/migration.h
0a122b
index 701709a..90b5021 100644
0a122b
--- a/include/migration/migration.h
0a122b
+++ b/include/migration/migration.h
0a122b
@@ -109,6 +109,8 @@ uint64_t xbzrle_mig_pages_transferred(void);
0a122b
 uint64_t xbzrle_mig_pages_overflow(void);
0a122b
 uint64_t xbzrle_mig_pages_cache_miss(void);
0a122b
 
0a122b
+void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
0a122b
+
0a122b
 /**
0a122b
  * @migrate_add_blocker - prevent migration from proceeding
0a122b
  *
0a122b
-- 
0a122b
1.7.11.7
0a122b