[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 08/34] exec: sort the memory from biggest to smalles
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 08/34] exec: sort the memory from biggest to smallest |
Date: |
Wed, 19 Dec 2012 13:33:31 +0100 |
From: Paolo Bonzini <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
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
- [Qemu-devel] [PATCH 00/34] migration thread and queue, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 01/34] migration: fix migration_bitmap leak, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 02/34] buffered_file: do not send more than s->bytes_xfer bytes per tick, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 03/34] migration: remove double call to migrate_fd_close, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 04/34] migration: include qemu-file.h, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 05/34] migration-fd: remove duplicate include, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 07/34] exec: change RAM list to a TAILQ, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 06/34] exec: change ramlist from MRU order to a 1-item cache, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 09/34] add a version number to ram_list, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 08/34] exec: sort the memory from biggest to smallest,
Juan Quintela <=
- [Qemu-devel] [PATCH 11/34] buffered_file: Move from using a timer to use a thread, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 10/34] protect the ramlist with a separate mutex, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 13/34] migration: move migration thread init code to migrate_fd_put_ready, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 16/34] migration: just lock migrate_fd_put_ready, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 15/34] migration: remove unfreeze logic, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 14/34] migration: make writes blocking, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 18/34] buffered_file: don't flush on put buffer, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 17/34] buffered_file: Unfold the trick to restart generating migration data, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 22/34] migration: add XFER_LIMIT_RATIO, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 26/34] ram: rename last_block to last_seen_block, Juan Quintela, 2012/12/19