From 68908ed665f4d97afb271c5d5b564d951951538c Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Tue, 28 Mar 2017 15:05:53 +0200 Subject: ram: Change num_dirty_pages_period type to uint64_t Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu --- include/exec/ram_addr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/exec') diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index b05dc84ab9..9aadc5c830 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -356,7 +356,7 @@ static inline uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest, ram_addr_t start, ram_addr_t length, - int64_t *real_dirty_pages) + uint64_t *real_dirty_pages) { ram_addr_t addr; unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS); -- cgit v1.2.3-55-g7522 From 15440dd5a08a6b10538b9e62c6d95ac8a838d78a Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Tue, 21 Mar 2017 09:35:04 +0100 Subject: ram: Pass RAMBlock to bitmap_sync We change the meaning of start to be the offset from the beggining of the block. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- include/exec/ram_addr.h | 2 ++ migration/ram.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'include/exec') diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 9aadc5c830..8a1372c66d 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -354,11 +354,13 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start, static inline uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest, + RAMBlock *rb, ram_addr_t start, ram_addr_t length, uint64_t *real_dirty_pages) { ram_addr_t addr; + start = rb->offset + start; unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS); uint64_t num_dirty = 0; diff --git a/migration/ram.c b/migration/ram.c index fe01e7ba26..3f3842a38b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -646,13 +646,13 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs, ram_addr_t addr) return ret; } -static void migration_bitmap_sync_range(RAMState *rs, ram_addr_t start, - ram_addr_t length) +static void migration_bitmap_sync_range(RAMState *rs, RAMBlock *rb, + ram_addr_t start, ram_addr_t length) { unsigned long *bitmap; bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap; rs->migration_dirty_pages += - cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length, + cpu_physical_memory_sync_dirty_bitmap(bitmap, rb, start, length, &rs->num_dirty_pages_period); } @@ -699,7 +699,7 @@ static void migration_bitmap_sync(RAMState *rs) qemu_mutex_lock(&rs->bitmap_mutex); rcu_read_lock(); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { - migration_bitmap_sync_range(rs, block->offset, block->used_length); + migration_bitmap_sync_range(rs, block, 0, block->used_length); } rcu_read_unlock(); qemu_mutex_unlock(&rs->bitmap_mutex); -- cgit v1.2.3-55-g7522 From b8c4899398126a1dd80377e14d4ba471018293d3 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Tue, 21 Mar 2017 17:44:30 +0100 Subject: ram: rename last_ram_offset() last_ram_pages() We always use it as pages anyways. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- exec.c | 6 +++--- include/exec/ram_addr.h | 2 +- migration/ram.c | 11 +++++------ 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'include/exec') diff --git a/exec.c b/exec.c index 7a640c76b6..de843f4de2 100644 --- a/exec.c +++ b/exec.c @@ -1528,7 +1528,7 @@ static ram_addr_t find_ram_offset(ram_addr_t size) return offset; } -ram_addr_t last_ram_offset(void) +unsigned long last_ram_page(void) { RAMBlock *block; ram_addr_t last = 0; @@ -1538,7 +1538,7 @@ ram_addr_t last_ram_offset(void) last = MAX(last, block->offset + block->max_length); } rcu_read_unlock(); - return last; + return last >> TARGET_PAGE_BITS; } static void qemu_ram_setup_dump(void *addr, ram_addr_t size) @@ -1727,7 +1727,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) ram_addr_t old_ram_size, new_ram_size; Error *err = NULL; - old_ram_size = last_ram_offset() >> TARGET_PAGE_BITS; + old_ram_size = last_ram_page(); qemu_mutex_lock_ramlist(); new_block->offset = find_ram_offset(new_block->max_length); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 8a1372c66d..a8411c7821 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -53,7 +53,7 @@ static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset) } long qemu_getrampagesize(void); -ram_addr_t last_ram_offset(void); +unsigned long last_ram_page(void); RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, bool share, const char *mem_path, Error **errp); diff --git a/migration/ram.c b/migration/ram.c index 932a96e510..f972882dea 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1537,7 +1537,7 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) */ void ram_debug_dump_bitmap(unsigned long *todump, bool expected) { - int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS; + unsigned long ram_pages = last_ram_page(); RAMState *rs = &ram_state; int64_t cur; int64_t linelen = 128; @@ -1904,8 +1904,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms) * Update the unsentmap to be unsentmap = unsentmap | dirty */ bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap; - bitmap_or(unsentmap, unsentmap, bitmap, - last_ram_offset() >> TARGET_PAGE_BITS); + bitmap_or(unsentmap, unsentmap, bitmap, last_ram_page()); trace_ram_postcopy_send_discard_bitmap(); @@ -1953,7 +1952,7 @@ err: static int ram_state_init(RAMState *rs) { - int64_t ram_bitmap_pages; /* Size of bitmap in pages, including gaps */ + unsigned long ram_bitmap_pages; memset(rs, 0, sizeof(*rs)); qemu_mutex_init(&rs->bitmap_mutex); @@ -1999,7 +1998,7 @@ static int ram_state_init(RAMState *rs) rs->ram_bitmap = g_new0(struct RAMBitmap, 1); /* Skip setting bitmap if there is no RAM */ if (ram_bytes_total()) { - ram_bitmap_pages = last_ram_offset() >> TARGET_PAGE_BITS; + ram_bitmap_pages = last_ram_page(); rs->ram_bitmap->bmap = bitmap_new(ram_bitmap_pages); bitmap_set(rs->ram_bitmap->bmap, 0, ram_bitmap_pages); @@ -2460,7 +2459,7 @@ static void decompress_data_with_multi_threads(QEMUFile *f, */ int ram_postcopy_incoming_init(MigrationIncomingState *mis) { - size_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS; + unsigned long ram_pages = last_ram_page(); return postcopy_ram_incoming_init(mis, ram_pages); } -- cgit v1.2.3-55-g7522 From 66103a5796d0003cb198c25d783dcdc1596aef1f Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 22 Mar 2017 17:42:01 +0100 Subject: ram: Remove migration_bitmap_extend() We have disabled memory hotplug, so we don't need to handle migration_bitamp there. Signed-off-by: Juan Quintela Reviewed-by: Eric Blake Reviewed-by: zhanghailiang --- exec.c | 1 - include/exec/ram_addr.h | 2 -- migration/ram.c | 34 ---------------------------------- 3 files changed, 37 deletions(-) (limited to 'include/exec') diff --git a/exec.c b/exec.c index de843f4de2..c2def9ecf2 100644 --- a/exec.c +++ b/exec.c @@ -1758,7 +1758,6 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) new_ram_size = MAX(old_ram_size, (new_block->offset + new_block->max_length) >> TARGET_PAGE_BITS); if (new_ram_size > old_ram_size) { - migration_bitmap_extend(old_ram_size, new_ram_size); dirty_memory_extend(old_ram_size, new_ram_size); } /* Keep the list sorted from biggest to smallest block. Unlike QTAILQ, diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index a8411c7821..c9ddcd0880 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -413,7 +413,5 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest, return num_dirty; } - -void migration_bitmap_extend(ram_addr_t old, ram_addr_t new); #endif #endif diff --git a/migration/ram.c b/migration/ram.c index 2af8080cbb..f48664ec62 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1496,40 +1496,6 @@ static void ram_state_reset(RAMState *rs) #define MAX_WAIT 50 /* ms, half buffered_file limit */ -void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) -{ - RAMState *rs = &ram_state; - - /* called in qemu main thread, so there is - * no writing race against this migration_bitmap - */ - if (rs->ram_bitmap) { - RAMBitmap *old_bitmap = rs->ram_bitmap, *bitmap; - bitmap = g_new(RAMBitmap, 1); - bitmap->bmap = bitmap_new(new); - - /* prevent migration_bitmap content from being set bit - * by migration_bitmap_sync_range() at the same time. - * it is safe to migration if migration_bitmap is cleared bit - * at the same time. - */ - qemu_mutex_lock(&rs->bitmap_mutex); - bitmap_copy(bitmap->bmap, old_bitmap->bmap, old); - bitmap_set(bitmap->bmap, old, new - old); - - /* We don't have a way to safely extend the sentmap - * with RCU; so mark it as missing, entry to postcopy - * will fail. - */ - bitmap->unsentmap = NULL; - - atomic_rcu_set(&rs->ram_bitmap, bitmap); - qemu_mutex_unlock(&rs->bitmap_mutex); - rs->migration_dirty_pages += new - old; - call_rcu(old_bitmap, migration_bitmap_free, rcu); - } -} - /* * 'expected' is the value you expect the bitmap mostly to be full * of; it won't bother printing lines that are all this value. -- cgit v1.2.3-55-g7522