Blame SOURCES/kvm-memory-only-resize-dirty-bitmap-when-memory-size-inc.patch

0a122b
From 1e5621a56dcf27b1b9d04bc749e7fbeaa1e17729 Mon Sep 17 00:00:00 2001
0a122b
From: Juan Quintela <quintela@redhat.com>
0a122b
Date: Tue, 14 Jan 2014 15:07:26 +0100
0a122b
Subject: [PATCH 15/40] memory: only resize dirty bitmap when memory size increases
0a122b
0a122b
RH-Author: Juan Quintela <quintela@redhat.com>
0a122b
Message-id: <1389712071-23303-16-git-send-email-quintela@redhat.com>
0a122b
Patchwork-id: 56672
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH 15/40] memory: only resize dirty bitmap when memory size increases
0a122b
Bugzilla: 997559
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
0a122b
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
0a122b
0a122b
Signed-off-by: Juan Quintela <quintela@redhat.com>
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
0a122b
(cherry picked from commit 2152f5ca782e51a4d05a1f7d9bfa83286323cbc9)
0a122b
Signed-off-by: Juan Quintela <quintela@trasno.org>
0a122b
---
0a122b
 exec.c | 12 +++++++++---
0a122b
 1 file changed, 9 insertions(+), 3 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 exec.c |   12 +++++++++---
0a122b
 1 files changed, 9 insertions(+), 3 deletions(-)
0a122b
0a122b
diff --git a/exec.c b/exec.c
0a122b
index 8942d50..be99d45 100644
0a122b
--- a/exec.c
0a122b
+++ b/exec.c
0a122b
@@ -1098,6 +1098,9 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
0a122b
                                    MemoryRegion *mr)
0a122b
 {
0a122b
     RAMBlock *block, *new_block;
0a122b
+    ram_addr_t old_ram_size, new_ram_size;
0a122b
+
0a122b
+    old_ram_size = last_ram_offset() >> TARGET_PAGE_BITS;
0a122b
 
0a122b
     size = TARGET_PAGE_ALIGN(size);
0a122b
     new_block = g_malloc0(sizeof(*new_block));
0a122b
@@ -1158,10 +1161,13 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
0a122b
     ram_list.version++;
0a122b
     qemu_mutex_unlock_ramlist();
0a122b
 
0a122b
-    ram_list.phys_dirty = g_realloc(ram_list.phys_dirty,
0a122b
-                                       last_ram_offset() >> TARGET_PAGE_BITS);
0a122b
-    memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
0a122b
+    new_ram_size = last_ram_offset() >> TARGET_PAGE_BITS;
0a122b
+
0a122b
+    if (new_ram_size > old_ram_size) {
0a122b
+        ram_list.phys_dirty = g_realloc(ram_list.phys_dirty, new_ram_size);
0a122b
+        memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
0a122b
            0, size >> TARGET_PAGE_BITS);
0a122b
+    }
0a122b
     cpu_physical_memory_set_dirty_range(new_block->offset, size);
0a122b
 
0a122b
     qemu_ram_setup_dump(new_block->host, size);
0a122b
-- 
0a122b
1.7.1
0a122b