Fix long vm downtime during live migration
cover Fix long vm downtime during live migration
Some cleanup operations take long time during the pause and copy stage, especially with the KVM patch 3ea3b7fa9af067, do these operation after the completion of live migration can help to reduce VM downtime.
Liang Li (2):
migration: do cleanup operation after completion
migration: rename qemu_savevm_state_cancel
include/sysemu/sysemu.h | 2 +- migration/block.c | 1 - migration/migration.c | 7 +++++-- migration/ram.c | 1 - migration/savevm.c | 6 +++--- trace-events | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/2 migration: do cleanup operation after completion
Because of the patch 3ea3b7fa9af067982f34b of kvm, now the migration_end() is a time consuming operation, which takes about dozens of milliseconds, and will prolong VM downtime. Such an operation should be done after migration completion.
For a VM with 8G RAM, this patch can reduce the VM downtime about 32 ms during live migration.
--- migration/block.c | 1 - migration/migration.c | 5 ++++- migration/ram.c | 1 - 3 files changed, 4 insertions(+), 3 deletions(-)
migration/block.c +0 -1
@@ -750,7 +750,6 @@ static int block_save_complete(QEMUFile *f, void *opaque)qemu_put_be64 (f,BLK_MIG_FLAG_EOS ); -blk_mig_cleanup ();return 0 ; }
migration/migration.c +4 -1
@@ -923,6 +923,7 @@ static void *migration_thread(void *opaque)int64_t initial_bytes =0 ;int64_t max_size =0 ;int64_t start_time = initial_time; +int64_t end_time;bool old_vm_running = false;rcu_register_thread ();
@@ -1008,8 +1009,10 @@ static void *migration_thread(void *opaque) }qemu_mutex_lock_iothread (); + end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME ); +qemu_savevm_state_cancel (); +if (s->state ==MIGRATION_STATUS_COMPLETED ) { -int64_t end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );uint64_t transferred_bytes =qemu_ftell (s->file); s->total_time = end_time - s->total_time; s->downtime = end_time - start_time;
migration/ram.c +0 -1
@@ -1269,7 +1269,6 @@ static int ram_save_complete(QEMUFile *f, void *opaque)rcu_read_unlock (); -migration_end ();qemu_put_be64 (f,RAM_SAVE_FLAG_EOS );return 0 ;
Signature · 1 line
1.9.1
PATCH 2/2 migration: rename qemu_savevm_state_cancel
In reply to Liang LiThe function qemu_savevm_state_cancel is called after the migration in migration_thread, it seems strange to 'cancel' it after completion, rename it to qemu_savevm_state_cleanup looks better.
--- include/sysemu/sysemu.h | 2 +- migration/migration.c | 4 ++-- migration/savevm.c | 6 +++--- trace-events | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
include/sysemu/sysemu.h +1 -1
@@ -88,7 +88,7 @@ void qemu_savevm_state_begin(QEMUFile *f,void qemu_savevm_state_header (QEMUFile *f);int qemu_savevm_state_iterate (QEMUFile *f);void qemu_savevm_state_complete (QEMUFile *f); -void qemu_savevm_state_cancel (void ); +void qemu_savevm_state_cleanup (void );uint64_t qemu_savevm_state_pending (QEMUFile *f,uint64_t max_size);int qemu_loadvm_state (QEMUFile *f);
migration/migration.c +2 -2
@@ -561,7 +561,7 @@ static void migrate_fd_cleanup(void *opaque)assert (s->state !=MIGRATION_STATUS_ACTIVE );if (s->state !=MIGRATION_STATUS_COMPLETED ) { -qemu_savevm_state_cancel (); +qemu_savevm_state_cleanup ();if (s->state ==MIGRATION_STATUS_CANCELLING ) {migrate_set_state (s,MIGRATION_STATUS_CANCELLING ,MIGRATION_STATUS_CANCELLED );
@@ -1010,7 +1010,7 @@ static void *migration_thread(void *opaque)qemu_mutex_lock_iothread (); end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME ); -qemu_savevm_state_cancel (); +qemu_savevm_state_cleanup ();if (s->state ==MIGRATION_STATUS_COMPLETED ) {uint64_t transferred_bytes =qemu_ftell (s->file);
migration/savevm.c +3 -3
@@ -905,11 +905,11 @@ uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size)return ret; } -void qemu_savevm_state_cancel (void ) +void qemu_savevm_state_cleanup (void ) {SaveStateEntry *se; -trace_savevm_state_cancel (); +trace_savevm_state_cleanup (); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {if (se->ops && se->ops->cancel) { se->ops->cancel (se->opaque);
@@ -946,7 +946,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp) ret =qemu_file_get_error (f); }if (ret !=0 ) { -qemu_savevm_state_cancel (); +qemu_savevm_state_cleanup ();error_setg_errno (errp, -ret,"Error while writing VM state" ); }return ret;
trace-events +1 -1
@@ -1195,7 +1195,7 @@ savevm_state_begin(void) "" savevm_state_header(void) "" savevm_state_iterate(void) "" savevm_state_complete(void) "" -savevm_state_cancel(void) "" +savevm_state_cleanup(void) "" vmstate_save(const char *idstr, const char *vmsd_name) "%s, %s" vmstate_load(const char *idstr, const char *vmsd_name) "%s, %s" qemu_announce_self_iter(const char *mac) "%s"
Signature · 1 line
1.9.1
Quoted 9 lines · Liang Li
Some cleanup operations take long time during the pause and copy stage, especially with the KVM patch
3ea3b7fa9af067, do these operation after the completion of live migration can help to reduce VM downtime.Liang Li (2):
migration: do cleanup operation after completion
migration: renameqemu_savevm_state_cancel
Quoted 8 lines
include/sysemu/sysemu.h | 2 +- migration/block.c | 1 - migration/migration.c | 7 +++++-- migration/ram.c | 1 - migration/savevm.c | 6 +++--- trace-events | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-)
That's really a clever solution!
Re: [Qemu-devel] [PATCH 1/2] migration: do cleanup operation after completion
In reply to Liang Limigration/migration.c static void *migration_thread(void *opaque) · line 1014
Quoted 7 lines · Liang Li
migration/migration.c +3
-0@@ -1008,8 +1009,10 @@ static void *migration_thread(void *opaque) }qemu_mutex_lock_iothread (); + end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME ); +qemu_savevm_state_cancel (); +
You can remove the qemu_savevm_state_cancel() call from migrate_fd_cleanup, too. Probably best to post a v2 with that change as well.
Paolo
Re: [Qemu-devel] [PATCH 1/2] migration: do cleanup operation after completion
Quoted 13 lines · Liang Li
migration/migration.c static void *migration_thread(void *opaque) · line 1014
Quoted 7 lines
migration/migration.c +3
-0@@ -1008,8 +1009,10 @@ static void *migration_thread(void *opaque) }qemu_mutex_lock_iothread (); + end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME ); +qemu_savevm_state_cancel (); +You can remove the
qemu_savevm_state_cancel()call frommigrate_fd_cleanup, too. Probably best to post a v2 with that change as well.
Quoted 1 line
Paolo
You are right. Done.
Liang