summary refs log tree commit diff stats
path: root/exec.c
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2010-06-25 11:08:38 -0600
committerAnthony Liguori <aliguori@us.ibm.com>2010-07-06 10:36:27 -0500
commitd17b5288d91c935cc8795fa0620721da0a3865e1 (patch)
tree23d324b4fd378a8fd2e1f285758a76a11ce19459 /exec.c
parentf292787d9addffd5f0a2df9516c158bfb5792b61 (diff)
downloadfocaccia-qemu-d17b5288d91c935cc8795fa0620721da0a3865e1.tar.gz
focaccia-qemu-d17b5288d91c935cc8795fa0620721da0a3865e1.zip
Remove uses of ram.last_offset (aka last_ram_offset)
We currently need this either to allocate the next ram_addr_t for a
new block, or for total memory to be migrated.  Both of which we can
calculate without need of this to keep us in a contiguous address space.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/exec.c b/exec.c
index 137175caa0..a6b3f21a15 100644
--- a/exec.c
+++ b/exec.c
@@ -2767,6 +2767,17 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path)
 }
 #endif
 
+static ram_addr_t find_ram_offset(ram_addr_t size)
+{
+    RAMBlock *block;
+    ram_addr_t last = 0;
+
+    QLIST_FOREACH(block, &ram_list.blocks, next)
+        last = MAX(last, block->offset + block->length);
+
+    return last;
+}
+
 ram_addr_t qemu_ram_alloc(ram_addr_t size)
 {
     RAMBlock *new_block;
@@ -2800,18 +2811,16 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size)
         madvise(new_block->host, size, MADV_MERGEABLE);
 #endif
     }
-    new_block->offset = ram_list.last_offset;
+    new_block->offset = find_ram_offset(size);
     new_block->length = size;
 
     QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
 
     ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty,
-        (ram_list.last_offset + size) >> TARGET_PAGE_BITS);
-    memset(ram_list.phys_dirty + (ram_list.last_offset >> TARGET_PAGE_BITS),
+        (new_block->offset + size) >> TARGET_PAGE_BITS);
+    memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
            0xff, size >> TARGET_PAGE_BITS);
 
-    ram_list.last_offset += size;
-
     if (kvm_enabled())
         kvm_setup_guest_memory(new_block->host, size);