Convert live migration to memory API
cover Convert live migration to memory API
These patches, on top of "vmstate, memory: decouple vmstate from memory API", convert live migration to use the memory API.
Patch 4 is an ABI change, please review carefully.
Avi Kivity (8):
Store MemoryRegion in RAMBlock
Switch ram_save to the memory API
Sort RAMBlocks by ID for migration, not by ram_addr Remove support for version 3 ram_load
Convert ram_load() to the memory API
memory: obsolete cpu_physical_memory_[gs]et_dirty_tracking()
xen: convert framebuffer dirty tracking to memory API
memory: obsolete more dirty memory related functions
arch_init.c | 71 +++++++++++++++++++----------------------------------- cpu-all.h | 54 +----------------------------------------- exec-obsolete.h | 51 +++++++++++++++++++++++++++++++++++++++ exec.c | 11 +------- memory.c | 2 + xen-all.c | 5 +-- 6 files changed, 82 insertions(+), 112 deletions(-)
Signature · 1 line
1.7.7.1
PATCH 1/8 Store MemoryRegion in RAMBlock
As a step in moving live migration from RAMBlocks to MemoryRegions, store the MemoryRegion in a RAMBlock.
--- cpu-all.h | 1 + exec.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
cpu-all.h +1 -0
@@ -476,6 +476,7 @@ extern ram_addr_t ram_size;#define RAM_PREALLOC_MASK (1 << 0) typedef struct RAMBlock { + struct MemoryRegion *mr; uint8_t *host; ram_addr_t offset; ram_addr_t length;
exec.c +1 -0
@@ -2793,6 +2793,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, size =TARGET_PAGE_ALIGN (size); new_block =g_malloc0 (sizeof (*new_block)); + new_block->mr = mr; new_block->offset =find_ram_offset (size);if (host) { new_block->host = host;
Signature · 1 line
1.7.7.1
PATCH 2/8 Switch ram_save to the memory API
In reply to Avi KivityAvoid using ram_addr_t, instead use (MemoryRegion *, offset) pairs.
--- arch_init.c | 34 ++++++++++++++-------------------- 1 files changed, 14 insertions(+), 20 deletions(-)
arch_init.c +14 -20
@@ -117,24 +117,22 @@ static int ram_save_block(QEMUFile *f) {RAMBlock *block = last_block;ram_addr_t offset = last_offset; -ram_addr_t current_addr;int bytes_sent =0 ; +MemoryRegion *mr;if (!block) block =QLIST_FIRST (&ram_list.blocks); - current_addr = block->offset + offset; - do { - if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) { + mr = block->mr; + if (memory_region_get_dirty(mr, offset, DIRTY_MEMORY_MIGRATION)) { uint8_t *p; int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0; - cpu_physical_memory_reset_dirty(current_addr, - current_addr + TARGET_PAGE_SIZE, - MIGRATION_DIRTY_FLAG); + memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE, + DIRTY_MEMORY_MIGRATION); - p = block->host + offset; + p = memory_region_get_ram_ptr(mr) + offset; if (is_dup_page(p, *p)) { qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS);
@@ -166,10 +164,7 @@ static int ram_save_block(QEMUFile *f)if (!block) block =QLIST_FIRST (&ram_list.blocks); } - - current_addr = block->offset + offset; - - }while (current_addr != last_block->offset + last_offset); + }while (block != last_block || offset != last_offset); last_block = block; last_offset = offset;
@@ -186,9 +181,9 @@ static ram_addr_t ram_save_remaining(void) QLIST_FOREACH(block, &ram_list.blocks, next) {ram_addr_t addr; -for (addr = block->offset; addr < block->offset + block->length; - addr +=TARGET_PAGE_SIZE ) { -if (cpu_physical_memory_get_dirty (addr,MIGRATION_DIRTY_FLAG )) { +for (addr =0 ; addr < block->length; addr +=TARGET_PAGE_SIZE ) { +if (memory_region_get_dirty (block->mr, addr, +DIRTY_MEMORY_MIGRATION )) { count++; } }
@@ -275,11 +270,10 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)/* Make sure all dirty bits are set */ QLIST_FOREACH(block, &ram_list.blocks, next) { -for (addr = block->offset; addr < block->offset + block->length; - addr +=TARGET_PAGE_SIZE ) { -if (!cpu_physical_memory_get_dirty (addr, -MIGRATION_DIRTY_FLAG )) { -cpu_physical_memory_set_dirty (addr); +for (addr =0 ; addr < block->length; addr +=TARGET_PAGE_SIZE ) { +if (!memory_region_get_dirty (block->mr, addr, +DIRTY_MEMORY_MIGRATION )) { +memory_region_set_dirty (block->mr, addr); } } }
Signature · 1 line
1.7.7.1
PATCH 3/8 Sort RAMBlocks by ID for migration, not by ram_addr
In reply to Avi Kivityram_addr is (a) unstable (b) going away. Sort by idstr instead.
--- arch_init.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)
arch_init.c +2 -6
@@ -217,12 +217,8 @@ static int block_compar(const void *a, const void *b) {RAMBlock *const *ablock = a;RAMBlock *const *bblock = b; -if ((*ablock)->offset < (*bblock)->offset) { -return -1 ; - }else if ((*ablock)->offset > (*bblock)->offset) { -return 1 ; - } -return 0 ; + +return strcmp ((*ablock)->idstr, (*bblock)->idstr); }static void sort_ram_list (void )
Signature · 1 line
1.7.7.1
Re: [Qemu-devel] [PATCH 3/8] Sort RAMBlocks by ID for migration, not by ram_addr
Quoted 3 lines · Avi Kivity
ram_addris (a) unstable (b) going away. Sort by idstr instead.Signed-off-by Avi Kivity<[email protected]>
I don't see this as a problem, per say, but this is a significant behavioral change. ram_addr does correspond roughly to the location in memory and historically we would send memory starting from 0 upward whereas now, the order that we send RAMBlocks will be random for all intents and purposes.
Again, I don't think it's a problem, but we should note this in the commit message in case it creates a problem down the road.
Regards,
Anthony Liguori
Quoted 23 lines
--- arch_init.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)arch_init.c +2
-6@@ -217,12 +217,8 @@ static int block_compar(const void *a, const void *b) {RAMBlock *const *ablock = a;RAMBlock *const *bblock = b; -if ((*ablock)->offset< (*bblock)->offset) { -return -1 ; - }else if ((*ablock)->offset> (*bblock)->offset) { -return 1 ; - } -return 0 ; + +return strcmp ((*ablock)->idstr, (*bblock)->idstr); }static void sort_ram_list (void )
Re: [Qemu-devel] [PATCH 3/8] Sort RAMBlocks by ID for migration, not by ram_addr
Quoted 5 lines · Anthony Liguori
Quoted 3 lines · Avi Kivity
ram_addris (a) unstable (b) going away. Sort by idstr instead.Signed-off-by Avi Kivity<[email protected]>
Quoted 9 lines
I don't see this as a problem, per say, but this is a significant behavioral change.
ram_addrdoes correspond roughly to the location in memory and historically we would send memory starting from 0 upward whereas now, the order that we send RAMBlocks will be random for all intents and purposes.Again, I don't think it's a problem, but we should note this in the commit message in case it creates a problem down the road.
I (and the new commit message) note that the sort order used to be random a while ago (before b2e0a138e), so this isn't entirely new.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 4/8 Remove support for version 3 ram_load
In reply to Avi KivityVersion 3 ram_load depends on ram_addrs, which are not stable. Version 4 was introduced in 0.13 (and RHEL 6), so this means live migration from 0.12 and earlier to 1.1 or later will not work.
--- arch_init.c | 18 ++++-------------- 1 files changed, 4 insertions(+), 14 deletions(-)
arch_init.c +4 -14
@@ -366,7 +366,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)int flags;int error; -if (version_id <3 || version_id >4 ) { +if (version_id <4 || version_id >4 ) {return -EINVAL ; }
@@ -377,11 +377,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) addr &=TARGET_PAGE_MASK ;if (flags &RAM_SAVE_FLAG_MEM_SIZE ) { -if (version_id ==3 ) { -if (addr !=ram_bytes_total ()) { -return -EINVAL ; - } - }else { +if (version_id ==4 ) {/* Synchronize RAM block list */ char id[256 ];ram_addr_t length;
@@ -419,10 +415,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)void *host;uint8_t ch; -if (version_id ==3 ) - host =qemu_get_ram_ptr (addr); -else - host =host_from_stream_offset (f, addr, flags); + host =host_from_stream_offset (f, addr, flags);if (!host) {return -EINVAL ; }
@@ -438,10 +431,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) }else if (flags &RAM_SAVE_FLAG_PAGE ) {void *host; -if (version_id ==3 ) - host =qemu_get_ram_ptr (addr); -else - host =host_from_stream_offset (f, addr, flags); + host =host_from_stream_offset (f, addr, flags);qemu_get_buffer (f, host,TARGET_PAGE_SIZE ); }
Signature · 1 line
1.7.7.1
Re: [Qemu-devel] [PATCH 4/8] Remove support for version 3 ram_load
Quoted 3 lines · Avi Kivity
Version 3
ram_loaddepends onram_addrs, which are not stable. Version 4 was introduced in 0.13 (and RHEL 6), so this means live migration from 0.12 and earlier to 1.1 or later will not work.
Can you please make a note on http://wiki.qemu.org/ChangeLog/Next
Regards,
Anthony Liguori
Quoted 56 lines
Signed-off-by Avi Kivity<[email protected]>--- arch_init.c | 18 ++++-------------- 1 files changed, 4 insertions(+), 14 deletions(-)arch_init.c +4
-14@@ -366,7 +366,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)int flags;int error; -if (version_id<3 || version_id>4 ) { +if (version_id<4 || version_id>4 ) {return -EINVAL ; }@@ -377,11 +377,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) addr&=TARGET_PAGE_MASK ;if (flags&RAM_SAVE_FLAG_MEM_SIZE ) { -if (version_id ==3 ) { -if (addr !=ram_bytes_total ()) { -return -EINVAL ; - } - }else { +if (version_id ==4 ) {/* Synchronize RAM block list */ char id[256 ];ram_addr_t length;@@ -419,10 +415,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)void *host;uint8_t ch; -if (version_id ==3 ) - host =qemu_get_ram_ptr (addr); -else - host =host_from_stream_offset (f, addr, flags); + host =host_from_stream_offset (f, addr, flags);if (!host) {return -EINVAL ; }@@ -438,10 +431,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) }else if (flags&RAM_SAVE_FLAG_PAGE ) {void *host; -if (version_id ==3 ) - host =qemu_get_ram_ptr (addr); -else - host =host_from_stream_offset (f, addr, flags); + host =host_from_stream_offset (f, addr, flags);qemu_get_buffer (f, host,TARGET_PAGE_SIZE ); }
Re: [Qemu-devel] [PATCH 4/8] Remove support for version 3 ram_load
Quoted 8 lines · Anthony Liguori
Quoted 5 lines · Avi Kivity
Version 3
ram_loaddepends onram_addrs, which are not stable. Version 4
was introduced in 0.13 (and RHEL 6), so this means live migration from 0.12
and earlier to 1.1 or later will not work.Can you please make a note on http://wiki.qemu.org/ChangeLog/Next
Done.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 5/8 Convert ram_load() to the memory API
In reply to Avi Kivity--- arch_init.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch_init.c +2 -2
@@ -344,7 +344,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)return NULL ; } -return block->host + offset; +return memory_region_get_ram_ptr (block->mr) + offset; } len =qemu_get_byte (f);
@@ -353,7 +353,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) QLIST_FOREACH(block, &ram_list.blocks, next) {if (!strncmp (id, block->idstr,sizeof (id))) -return block->host + offset; +return memory_region_get_ram_ptr (block->mr) + offset; }fprintf (stderr,"Can't find block %s!\n" , id);
Signature · 1 line
1.7.7.1
PATCH 6/8 memory: obsolete cpu_physical_memory_[gs]et_dirty_tracking()
In reply to Avi KivityThe getter is no longer used, so it is completely removed.
--- arch_init.c | 7 +++---- cpu-all.h | 4 ---- exec-obsolete.h | 2 ++ exec.c | 10 ---------- memory.c | 2 ++ 5 files changed, 7 insertions(+), 18 deletions(-)
arch_init.c +3 -4
@@ -251,7 +251,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)int ret;if (stage <0 ) { -cpu_physical_memory_set_dirty_tracking (0 ); +memory_global_dirty_log_stop ();return 0 ; }
@@ -274,8 +274,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) } } -/* Enable dirty memory tracking */ -cpu_physical_memory_set_dirty_tracking (1 ); +memory_global_dirty_log_start ();qemu_put_be64 (f,ram_bytes_total () |RAM_SAVE_FLAG_MEM_SIZE );
@@ -320,7 +319,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)while ((bytes_sent =ram_save_block (f)) !=0 ) { bytes_transferred += bytes_sent; } -cpu_physical_memory_set_dirty_tracking (0 ); +memory_global_dirty_log_stop (); }qemu_put_be64 (f,RAM_SAVE_FLAG_EOS );
cpu-all.h +0 -4
@@ -566,10 +566,6 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end, int dirty_flags);void cpu_tlb_update_dirty (CPUState *env); -int cpu_physical_memory_set_dirty_tracking (int enable); - -int cpu_physical_memory_get_dirty_tracking (void ); -void dump_exec_info (FILE *f,fprintf_function cpu_fprintf);#endif /* !CONFIG_USER_ONLY */
exec-obsolete.h +2 -0
@@ -61,6 +61,8 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,void qemu_register_coalesced_mmio (target_phys_addr_t addr,ram_addr_t size);void qemu_unregister_coalesced_mmio (target_phys_addr_t addr,ram_addr_t size); +int cpu_physical_memory_set_dirty_tracking (int enable); +#endif #endif
exec.c +0 -10
@@ -2008,19 +2008,9 @@ int cpu_physical_memory_set_dirty_tracking(int enable) {int ret =0 ; in_migration = enable; -if (enable) { -memory_global_dirty_log_start (); - }else { -memory_global_dirty_log_stop (); - }return ret; } -int cpu_physical_memory_get_dirty_tracking (void ) -{ -return in_migration; -} -static inline void tlb_update_dirty (CPUTLBEntry *tlb_entry) {ram_addr_t ram_addr;
memory.c +2 -0
@@ -1493,6 +1493,7 @@ void memory_global_dirty_log_start(void) {MemoryListener *listener; +cpu_physical_memory_set_dirty_tracking (1 ); global_dirty_log = true; QLIST_FOREACH(listener, &memory_listeners, link) { listener->log_global_start (listener);
@@ -1507,6 +1508,7 @@ void memory_global_dirty_log_stop(void) QLIST_FOREACH(listener, &memory_listeners, link) { listener->log_global_stop (listener); } +cpu_physical_memory_set_dirty_tracking (0 ); } static void listener_add_address_space(MemoryListener *listener,
Signature · 1 line
1.7.7.1
PATCH 7/8 xen: convert framebuffer dirty tracking to memory API
In reply to Avi Kivity--- xen-all.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
xen-all.c +2 -3
@@ -408,7 +408,6 @@ static int xen_sync_dirty_bitmap(XenIOState *state, ram_addr_t size) {target_phys_addr_t npages = size >>TARGET_PAGE_BITS ; -target_phys_addr_t vram_offset =0 ;const int width =sizeof (unsigned long ) *8 ;unsigned long bitmap[(npages + width -1 ) / width];int rc, i, j;
@@ -425,7 +424,6 @@ static int xen_sync_dirty_bitmap(XenIOState *state, }else if (state->log_for_dirtybit != physmap) {return -1 ; } - vram_offset = physmap->phys_offset; rc = xc_hvm_track_dirty_vram(xen_xc, xen_domid, start_addr >> TARGET_PAGE_BITS, npages,
@@ -439,7 +437,8 @@ static int xen_sync_dirty_bitmap(XenIOState *state,while (map !=0 ) { j =ffsl (map) -1 ; map &= ~(1ul << j); -cpu_physical_memory_set_dirty (vram_offset + (i * width + j) *TARGET_PAGE_SIZE ); +memory_region_set_dirty (framebuffer, + (i * width + j) *TARGET_PAGE_SIZE ); }; }
Signature · 1 line
1.7.7.1
PATCH 8/8 memory: obsolete more dirty memory related functions
In reply to Avi KivityNo longer used outside memory.c and exec.c.
--- cpu-all.h | 49 ------------------------------------------------- exec-obsolete.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 49 deletions(-)
cpu-all.h +0 -49
@@ -515,55 +515,6 @@ extern int mem_prealloc;/* Set if TLB entry is an IO callback. */ #define TLB_MMIO (1 << 5) -#define VGA_DIRTY_FLAG 0x01 -#define CODE_DIRTY_FLAG 0x02 -#define MIGRATION_DIRTY_FLAG 0x08 - -/* read dirty bit (return 0 or 1) */ -static inline int cpu_physical_memory_is_dirty (ram_addr_t addr) -{ -return ram_list.phys_dirty[addr >>TARGET_PAGE_BITS ] ==0xff ; -} - -static inline int cpu_physical_memory_get_dirty_flags (ram_addr_t addr) -{ -return ram_list.phys_dirty[addr >>TARGET_PAGE_BITS ]; -} - -static inline int cpu_physical_memory_get_dirty (ram_addr_t addr, -int dirty_flags) -{ -return ram_list.phys_dirty[addr >>TARGET_PAGE_BITS ] & dirty_flags; -} - -static inline void cpu_physical_memory_set_dirty (ram_addr_t addr) -{ - ram_list.phys_dirty[addr >>TARGET_PAGE_BITS ] =0xff ; -} - -static inline int cpu_physical_memory_set_dirty_flags (ram_addr_t addr, -int dirty_flags) -{ -return ram_list.phys_dirty[addr >>TARGET_PAGE_BITS ] |= dirty_flags; -} - -static inline void cpu_physical_memory_mask_dirty_range (ram_addr_t start, -int length, -int dirty_flags) -{ -int i, mask, len; -uint8_t *p; - - len = length >>TARGET_PAGE_BITS ; - mask = ~dirty_flags; - p = ram_list.phys_dirty + (start >>TARGET_PAGE_BITS ); -for (i =0 ; i < len; i++) { - p[i] &= mask; - } -} - -void cpu_physical_memory_reset_dirty (ram_addr_t start,ram_addr_t end, -int dirty_flags);void cpu_tlb_update_dirty (CPUState *env);void dump_exec_info (FILE *f,fprintf_function cpu_fprintf);
exec-obsolete.h +49 -0
55 lines not on this page · raw message
Signature · 1 line
1.7.7.1
Quoted 4 lines · Avi Kivity
These patches, on top of "vmstate, memory: decouple vmstate from memory API", convert live migration to use the memory API.
Patch 4 is an ABI change, please review carefully.
Using ram_addr_t for migration was badly, badly broken. I think it's been long enough that we can safely remove that logic.
Other than my request for a better commit message, this whole series:
Regards,
Anthony Liguori
Quoted 19 lines
Avi Kivity (8):
Store MemoryRegion in RAMBlock
Switchram_saveto the memory API
Sort RAMBlocks by ID for migration, not byram_addrRemove support for version 3ram_load
Convertram_load()to the memory API
memory: obsolete cpu_physical_memory_[gs]et_dirty_tracking()
xen: convert framebuffer dirty tracking to memory API
memory: obsolete more dirty memory related functionsarch_init.c | 71 +++++++++++++++++++----------------------------------- cpu-all.h | 54 +----------------------------------------- exec-obsolete.h | 51 +++++++++++++++++++++++++++++++++++++++ exec.c | 11 +------- memory.c | 2 + xen-all.c | 5 +-- 6 files changed, 82 insertions(+), 112 deletions(-)