diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2012-11-14 16:00:51 +0100 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2012-12-20 23:08:47 +0100 |
commit | abb26d63e7e4492d306c13b7e0e799d4c11a067c (patch) | |
tree | 4c84f372228f2cd71ce4aafe5eb87d36a2e408db /exec.c | |
parent | a3161038a1fd17a638a0c606f71e1f799f65f41b (diff) | |
download | qemu-abb26d63e7e4492d306c13b7e0e799d4c11a067c.zip qemu-abb26d63e7e4492d306c13b7e0e799d4c11a067c.tar.gz qemu-abb26d63e7e4492d306c13b7e0e799d4c11a067c.tar.bz2 |
exec: sort the memory from biggest to smallest
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'exec.c')
-rw-r--r-- | exec.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -1007,7 +1007,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)); @@ -1043,7 +1043,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, |