[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 18/18] ram: optimize migration bitmap walking
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 18/18] ram: optimize migration bitmap walking |
Date: |
Mon, 29 Oct 2012 15:11:43 +0100 |
Instead of testing each page individually, we search what is the next
dirty page with a bitmap operation. We have to reorganize the code to
move from a "for" loop, to a while(dirty) loop.
Signed-off-by: Juan Quintela <address@hidden>
---
arch_init.c | 45 ++++++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 19 deletions(-)
diff --git a/arch_init.c b/arch_init.c
index 79f466f..d760caa 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -338,18 +338,21 @@ static unsigned long *migration_bitmap;
static uint64_t migration_dirty_pages;
static uint32_t last_version;
-static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion *mr,
- ram_addr_t offset)
+static inline
+ram_addr_t migration_bitmap_find_and_reset_dirty(MemoryRegion *mr,
+ ram_addr_t start)
{
- bool ret;
- int nr = (mr->ram_addr + offset) >> TARGET_PAGE_BITS;
+ unsigned long base = mr->ram_addr >> TARGET_PAGE_BITS;
+ unsigned long nr = base + (start >> TARGET_PAGE_BITS);
+ unsigned long size = base + (int128_get64(mr->size) >> TARGET_PAGE_BITS);
- ret = test_and_clear_bit(nr, migration_bitmap);
+ unsigned long next = find_next_bit(migration_bitmap, size, nr);
- if (ret) {
+ if (next < size) {
+ clear_bit(next, migration_bitmap);
migration_dirty_pages--;
}
- return ret;
+ return (next - base) << TARGET_PAGE_BITS;
}
static inline bool migration_bitmap_set_dirty(MemoryRegion *mr,
@@ -418,6 +421,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
{
RAMBlock *block = last_block;
ram_addr_t offset = last_offset;
+ bool complete_round = false;
int bytes_sent = -1;
MemoryRegion *mr;
ram_addr_t current_addr;
@@ -425,9 +429,21 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
if (!block)
block = QLIST_FIRST(&ram_list.blocks);
- do {
+ while (true) {
mr = block->mr;
- if (migration_bitmap_test_and_reset_dirty(mr, offset)) {
+ offset = migration_bitmap_find_and_reset_dirty(mr, offset);
+ if (complete_round && block == last_block &&
+ offset >= last_offset) {
+ break;
+ }
+ if (offset >= block->length) {
+ offset = 0;
+ block = QLIST_NEXT(block, next);
+ if (!block) {
+ block = QLIST_FIRST(&ram_list.blocks);
+ complete_round = true;
+ }
+ } else {
uint8_t *p;
int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
@@ -460,16 +476,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
break;
}
}
-
- offset += TARGET_PAGE_SIZE;
- if (offset >= block->length) {
- offset = 0;
- block = QLIST_NEXT(block, next);
- if (!block)
- block = QLIST_FIRST(&ram_list.blocks);
- }
- } while (block != last_block || offset != last_offset);
-
+ }
last_block = block;
last_offset = offset;
--
1.7.11.7
- Re: [Qemu-devel] [PATCH 07/18] migration: make writes blocking, (continued)
- Re: [Qemu-devel] [PATCH 07/18] migration: make writes blocking, Juan Quintela, 2012/10/29
- Re: [Qemu-devel] [PATCH 07/18] migration: make writes blocking, Paolo Bonzini, 2012/10/29
- Re: [Qemu-devel] [PATCH 07/18] migration: make writes blocking, Markus Armbruster, 2012/10/30
- Re: [Qemu-devel] [PATCH 07/18] migration: make writes blocking, Juan Quintela, 2012/10/30
- Re: [Qemu-devel] [PATCH 07/18] migration: make writes blocking, Markus Armbruster, 2012/10/30
- Re: [Qemu-devel] [PATCH 07/18] migration: make writes blocking, Juan Quintela, 2012/10/30
[Qemu-devel] [PATCH 08/18] migration: remove unfreeze logic, Juan Quintela, 2012/10/29
[Qemu-devel] [PATCH 10/18] buffered_file: Unfold the trick to restart generating migration data, Juan Quintela, 2012/10/29
[Qemu-devel] [PATCH 12/18] buffered_file: unfold buffered_append in buffered_put_buffer, Juan Quintela, 2012/10/29
[Qemu-devel] [PATCH 11/18] buffered_file: don't flush on put buffer, Juan Quintela, 2012/10/29
[Qemu-devel] [PATCH 18/18] ram: optimize migration bitmap walking,
Juan Quintela <=
[Qemu-devel] [PATCH 15/18] migration-fd: remove duplicate include, Juan Quintela, 2012/10/29
[Qemu-devel] [PATCH 13/18] savevm: New save live migration method: pending, Juan Quintela, 2012/10/29
[Qemu-devel] [PATCH 16/18] memory: introduce memory_region_test_and_clear_dirty, Juan Quintela, 2012/10/29
[Qemu-devel] [PATCH 14/18] migration: include qemu-file.h, Juan Quintela, 2012/10/29
[Qemu-devel] [PATCH 17/18] ram: Use memory_region_test_and_clear_dirty, Juan Quintela, 2012/10/29
Re: [Qemu-devel] [PATCH 00/18] Migration thread lite (20121029), Chegu Vinod, 2012/10/29