From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlIqn-0003uF-9L for qemu-devel@nongnu.org; Wed, 19 Dec 2012 07:34:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TlIqi-0004EB-Dm for qemu-devel@nongnu.org; Wed, 19 Dec 2012 07:34:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlIqi-0004Ds-5t for qemu-devel@nongnu.org; Wed, 19 Dec 2012 07:34:12 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBJCYBpG014692 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 Dec 2012 07:34:11 -0500 From: Juan Quintela Date: Wed, 19 Dec 2012 13:33:31 +0100 Message-Id: <1355920437-29882-9-git-send-email-quintela@redhat.com> In-Reply-To: <1355920437-29882-1-git-send-email-quintela@redhat.com> References: <1355920437-29882-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 08/34] exec: sort the memory from biggest to smallest List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini From: Paolo Bonzini Signed-off-by: Paolo Bonzini Signed-off-by: Juan Quintela --- arch_init.c | 30 ------------------------------ exec.c | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/arch_init.c b/arch_init.c index 3c1aa00..8b5980f 100644 --- a/arch_init.c +++ b/arch_init.c @@ -505,35 +505,6 @@ uint64_t ram_bytes_total(void) return total; } -static int block_compar(const void *a, const void *b) -{ - RAMBlock * const *ablock = a; - RAMBlock * const *bblock = b; - - return strcmp((*ablock)->idstr, (*bblock)->idstr); -} - -static void sort_ram_list(void) -{ - RAMBlock *block, *nblock, **blocks; - int n; - n = 0; - QTAILQ_FOREACH(block, &ram_list.blocks, next) { - ++n; - } - blocks = g_malloc(n * sizeof *blocks); - n = 0; - QTAILQ_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) { - blocks[n++] = block; - QTAILQ_REMOVE(&ram_list.blocks, block, next); - } - qsort(blocks, n, sizeof *blocks, block_compar); - while (--n >= 0) { - QTAILQ_INSERT_HEAD(&ram_list.blocks, blocks[n], next); - } - g_free(blocks); -} - static void migration_end(void) { if (migration_bitmap) { @@ -562,7 +533,6 @@ static void reset_ram_globals(void) { last_block = NULL; last_offset = 0; - sort_ram_list(); } #define MAX_WAIT 50 /* ms, half buffered_file limit */ diff --git a/exec.c b/exec.c index 13c894d..5f501d4 100644 --- a/exec.c +++ b/exec.c @@ -1006,7 +1006,7 @@ static int memory_try_enable_merging(void *addr, size_t len) ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr) { - RAMBlock *new_block; + RAMBlock *block, *new_block; size = TARGET_PAGE_ALIGN(size); new_block = g_malloc0(sizeof(*new_block)); @@ -1042,7 +1042,17 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, } new_block->length = size; - QTAILQ_INSERT_HEAD(&ram_list.blocks, new_block, next); + /* Keep the list sorted from biggest to smallest block. */ + QTAILQ_FOREACH(block, &ram_list.blocks, next) { + if (block->length < new_block->length) { + break; + } + } + if (block) { + QTAILQ_INSERT_BEFORE(block, new_block, next); + } else { + QTAILQ_INSERT_TAIL(&ram_list.blocks, new_block, next); + } ram_list.mru_block = NULL; ram_list.phys_dirty = g_realloc(ram_list.phys_dirty, -- 1.7.11.7