From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2lVo-0002GL-U3 for qemu-devel@nongnu.org; Mon, 13 Jan 2014 12:41:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W2lVi-0006n1-U2 for qemu-devel@nongnu.org; Mon, 13 Jan 2014 12:41:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:21759) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2lVi-0006lQ-JU for qemu-devel@nongnu.org; Mon, 13 Jan 2014 12:41:14 -0500 From: Juan Quintela Date: Mon, 13 Jan 2014 18:40:11 +0100 Message-Id: <1389634834-24181-27-git-send-email-quintela@redhat.com> In-Reply-To: <1389634834-24181-1-git-send-email-quintela@redhat.com> References: <1389634834-24181-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 26/49] memory: only resize dirty bitmap when memory size increases List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: anthony@codemonkey.ws Signed-off-by: Juan Quintela Reviewed-by: Eric Blake Reviewed-by: Orit Wasserman --- exec.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/exec.c b/exec.c index 82aca4a..db369dc 100644 --- a/exec.c +++ b/exec.c @@ -1211,6 +1211,9 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr) { RAMBlock *block, *new_block; + ram_addr_t old_ram_size, new_ram_size; + + old_ram_size = last_ram_offset() >> TARGET_PAGE_BITS; size = TARGET_PAGE_ALIGN(size); new_block = g_malloc0(sizeof(*new_block)); @@ -1271,10 +1274,13 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, ram_list.version++; qemu_mutex_unlock_ramlist(); - ram_list.phys_dirty = g_realloc(ram_list.phys_dirty, - last_ram_offset() >> TARGET_PAGE_BITS); - memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS), + new_ram_size = last_ram_offset() >> TARGET_PAGE_BITS; + + if (new_ram_size > old_ram_size) { + ram_list.phys_dirty = g_realloc(ram_list.phys_dirty, new_ram_size); + memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS), 0, size >> TARGET_PAGE_BITS); + } cpu_physical_memory_set_dirty_range(new_block->offset, size); qemu_ram_setup_dump(new_block->host, size); -- 1.8.4.2