* [PATCH v4 0/2] migration: switchover-hold flag @ 2023-07-05 16:31 Peter Xu 2023-07-05 16:31 ` [PATCH v4 1/2] migration: switchover-hold parameter Peter Xu 2023-07-05 16:31 ` [PATCH v4 2/2] qtest/migration: Use switchover-hold to speedup Peter Xu 0 siblings, 2 replies; 5+ messages in thread From: Peter Xu @ 2023-07-05 16:31 UTC (permalink / raw) To: qemu-devel Cc: Eric Blake, Laszlo Ersek, Thomas Huth, Daniel P . Berrangé, Markus Armbruster, Juan Quintela, peterx, Avihai Horon, Leonardo Bras Soares Passos, Laurent Vivier, Paolo Bonzini This v4 patchset is based on master. Since I'm not sure how long this series will take for review, we could probably apply Dan's previous patch 10 first, then when I repost I can provide a revert patch when needed. v4: - Remove one unused var (accident after the rebase..) v3: - Rebase only (v2 is not yet applicable after switchover-ack series merged) A new flag "switchover-hold" is added to allow src qemu explicitly hold switchover for precopy migration. Note that this flag will not affect postcopy switchover because src qemu already has migrate-start-postcopy, which is a finer grained knob just for that. In general this flag only affects reaching migration completion phase, when set it'll block it from happening while keep the migration iteration going. This can be used in two cases so far in my mind: (1) One can use this parameter to start pre-heating migration (but not really migrating, so a migrate-cancel will cancel the preheat). When the user wants to really migrate, just clear the flag. It'll in most cases migrate immediately because most pages are already synced. (2) Can also be used as a clean way to do qtest, in many of the precopy tests we have requirement to run after 1 iteration without completing the precopy migration. Before that we have either set bandwidth to ridiculous low value, or tricks on detecting guest memory change over some adhoc guest memory position. Now we can simply set this flag then we know precopy won't complete and will just keep going. The 1st use case may look a bit like COLO where we can actually keep both QEMU _mostly_ in sync. I'm not sure whether it can be useful anywhere, though. Patch 1 will introduce the new flag. Patch 2 will leverage the new flag to speed up migration-test. An initial test is this can make migration-test finish within a little bit less than 1m. Please have a look, thanks. Peter Xu (2): migration: switchover-hold parameter qtest/migration: Use switchover-hold to speedup qapi/migration.json | 25 ++++++++++-- migration/migration.h | 17 +++++++++ migration/migration-hmp-cmds.c | 3 ++ migration/migration.c | 69 ++++++++++++++++++++++++++++++++-- migration/options.c | 17 +++++++++ tests/qtest/migration-test.c | 39 ++++++++++++++----- 6 files changed, 153 insertions(+), 17 deletions(-) -- 2.41.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/2] migration: switchover-hold parameter 2023-07-05 16:31 [PATCH v4 0/2] migration: switchover-hold flag Peter Xu @ 2023-07-05 16:31 ` Peter Xu 2023-07-06 8:40 ` Avihai Horon 2023-07-05 16:31 ` [PATCH v4 2/2] qtest/migration: Use switchover-hold to speedup Peter Xu 1 sibling, 1 reply; 5+ messages in thread From: Peter Xu @ 2023-07-05 16:31 UTC (permalink / raw) To: qemu-devel Cc: Eric Blake, Laszlo Ersek, Thomas Huth, Daniel P . Berrangé, Markus Armbruster, Juan Quintela, peterx, Avihai Horon, Leonardo Bras Soares Passos, Laurent Vivier, Paolo Bonzini Add a new migration parameter switchover-hold which can block src qemu migration from switching over to dest from running. One can set this flag to true so src qemu will keep iterating the VM data, not switching over to dest even if it can. It means now live migration works somehow like COLO; we keep syncing data from src to dst without stopping. When the user is ready for the switchover, one can set the parameter from true->false. That'll contain a implicit kick to migration thread to be alive and re-evaluate the switchover decision. This can be used in two cases so far in my mind: (1) One can use this parameter to start pre-heating migration (but not really migrating, so a migrate-cancel will cancel the preheat). When the user wants to really migrate, just clear the flag. It'll in most cases migrate immediately because most pages are already synced. (2) Can also be used as a clean way to do qtest, in many of the precopy tests we have requirement to run after 1 iteration without completing the precopy migration. Before that we have either set bandwidth to ridiculous low value, or tricks on detecting guest memory change over some adhoc guest memory position. Now we can simply set this flag then we know precopy won't complete and will just keep going. Here we leveraged a sem to make sure migration thread won't busy spin on a physical cpu, meanwhile provide a timedwait() of 10ms so it can still try its best to sync with dest QEMU from time to time. Note that the sem is prone to outdated counts but it's benign, please refer to the comment above the semaphore definition for more information. Signed-off-by: Peter Xu <peterx@redhat.com> --- qapi/migration.json | 25 ++++++++++-- migration/migration.h | 17 +++++++++ migration/migration-hmp-cmds.c | 3 ++ migration/migration.c | 69 ++++++++++++++++++++++++++++++++-- migration/options.c | 17 +++++++++ 5 files changed, 124 insertions(+), 7 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 47dfef0278..c050081555 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -789,6 +789,15 @@ # Nodes are mapped to their block device name if there is one, and # to their node name otherwise. (Since 5.2) # +# @switchover-hold: Whether we should hold-off precopy switchover from +# src to dest QEMU, even if we can finish migration in the +# downtime specified. By default off, so precopy migration will +# complete as soon as possible. One can set it to explicitly keep +# iterating during precopy migration until set the flag to false +# again to kick off the final switchover. Note, this does not +# affect postcopy switchover, because the user can control that +# using "migrate-start-postcopy" command explicitly. (Since 8.1) +# # Features: # # @unstable: Member @x-checkpoint-delay is experimental. @@ -810,7 +819,7 @@ 'xbzrle-cache-size', 'max-postcopy-bandwidth', 'max-cpu-throttle', 'multifd-compression', 'multifd-zlib-level' ,'multifd-zstd-level', - 'block-bitmap-mapping' ] } + 'block-bitmap-mapping', 'switchover-hold' ] } ## # @MigrateSetParameters: @@ -945,6 +954,10 @@ # Nodes are mapped to their block device name if there is one, and # to their node name otherwise. (Since 5.2) # +# @switchover-hold: Whether we should hold-off precopy switchover from +# src to dest QEMU. For more details, please refer to +# MigrationParameter entry of the same field. (Since 8.1) +# # Features: # # @unstable: Member @x-checkpoint-delay is experimental. @@ -982,7 +995,8 @@ '*multifd-compression': 'MultiFDCompression', '*multifd-zlib-level': 'uint8', '*multifd-zstd-level': 'uint8', - '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } + '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ], + '*switchover-hold': 'bool' } } ## # @migrate-set-parameters: @@ -1137,6 +1151,10 @@ # Nodes are mapped to their block device name if there is one, and # to their node name otherwise. (Since 5.2) # +# @switchover-hold: Whether we should hold-off precopy switchover from +# src to dest QEMU. For more details, please refer to +# MigrationParameter entry of the same field. (Since 8.1) +# # Features: # # @unstable: Member @x-checkpoint-delay is experimental. @@ -1171,7 +1189,8 @@ '*multifd-compression': 'MultiFDCompression', '*multifd-zlib-level': 'uint8', '*multifd-zstd-level': 'uint8', - '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } + '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ], + '*switchover-hold': 'bool' } } ## # @query-migrate-parameters: diff --git a/migration/migration.h b/migration/migration.h index a80b22b703..6b31a4b371 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -453,6 +453,23 @@ struct MigrationState { * switchover has been received. */ bool switchover_acked; + + /* + * Only migration thread will wait on it when switchover_hold==true. + * + * Only qmp set param will kick it when switching switchover_hold from + * true->false. + * + * NOTE: outdated sem count here is benign. E.g., when this is posted, + * the 1st migration got cancelled, then start the 2nd migration, or + * when someone sets the flag from true->false->true->false.. because + * any outdated sem count will only let the migration thread to run one + * more loop (timedwait() will eat the outdated count) when reaching + * the completion phase, then in the next loop it'll sleep again. The + * important thing here OTOH is when the migration thread is sleeping + * we can always kick it out of the sleep, which we will always do. + */ + QemuSemaphore switchover_hold_sem; }; void migrate_set_state(int *state, int old_state, int new_state); diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 9885d7c9f7..63a2c8a4a3 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -338,6 +338,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) monitor_printf(mon, "%s: '%s'\n", MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), params->tls_authz); + monitor_printf(mon, "%s: %s\n", + MigrationParameter_str(MIGRATION_PARAMETER_SWITCHOVER_HOLD), + params->switchover_hold ? "on" : "off"); if (params->has_block_bitmap_mapping) { const BitmapMigrationNodeAliasList *bmnal; diff --git a/migration/migration.c b/migration/migration.c index 096e8191d1..d75c2bd63c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2721,6 +2721,67 @@ static bool migration_can_switchover(MigrationState *s) return s->switchover_acked; } +static bool +migration_should_complete(MigrationState *s, uint64_t pending_size) +{ + /* Need an explicit ACK from dst? */ + if (!migration_can_switchover(s)) { + return false; + } + + /* We still have large pending data to send? */ + if (pending_size && (pending_size >= s->threshold_size)) { + return false; + } + + /* The user doesn't want us to switchover yet for precopy */ + if (!migration_in_postcopy() && s->parameters.switchover_hold) { + /* + * Note: when reaching here it probably means we've migrated almost + * everything and ready to switchover. If user asked not to switch + * wait for a short period and respond to kicks immediately. + * + * If we wait too long, there can be a lot of dirty data generated, + * while we could have done something to sync data between src/dst. + * + * If we wait too short, migration thread can eat most/all cpu + * resource looping over switchover_hold. + * + * Make it 10ms which seems to be a good intermediate value. + */ + qemu_sem_timedwait(&s->switchover_hold_sem, 10); + + /* + * Return false here always even if user changed it, because we'd + * like to re-evaluate everything (e.g. pending_size). + */ + return false; + } + + return true; +} + +static bool +migration_should_start_postcopy(MigrationState *s, uint64_t must_precopy) +{ + /* If we're already in postcopy phase, don't bother */ + if (migration_in_postcopy()) { + return false; + } + + /* Need an explicit ACK from dst? */ + if (!migration_can_switchover(s)) { + return false; + } + + /* We still have lots of thing that must be migrated in precopy */ + if (must_precopy > s->threshold_size) { + return false; + } + + return qatomic_read(&s->start_postcopy); +} + /* Migration thread iteration status */ typedef enum { MIG_ITERATE_RESUME, /* Resume current iteration */ @@ -2736,7 +2797,6 @@ static MigIterateState migration_iteration_run(MigrationState *s) { uint64_t must_precopy, can_postcopy; bool in_postcopy = s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE; - bool can_switchover = migration_can_switchover(s); qemu_savevm_state_pending_estimate(&must_precopy, &can_postcopy); uint64_t pending_size = must_precopy + can_postcopy; @@ -2749,15 +2809,14 @@ static MigIterateState migration_iteration_run(MigrationState *s) trace_migrate_pending_exact(pending_size, must_precopy, can_postcopy); } - if ((!pending_size || pending_size < s->threshold_size) && can_switchover) { + if (migration_should_complete(s, pending_size)) { trace_migration_thread_low_pending(pending_size); migration_completion(s); return MIG_ITERATE_BREAK; } /* Still a significant amount to transfer */ - if (!in_postcopy && must_precopy <= s->threshold_size && can_switchover && - qatomic_read(&s->start_postcopy)) { + if (migration_should_start_postcopy(s, must_precopy)) { if (postcopy_start(s)) { error_report("%s: postcopy failed to start", __func__); } @@ -3314,6 +3373,7 @@ static void migration_instance_finalize(Object *obj) qemu_sem_destroy(&ms->rp_state.rp_sem); qemu_sem_destroy(&ms->rp_state.rp_pong_acks); qemu_sem_destroy(&ms->postcopy_qemufile_src_sem); + qemu_sem_destroy(&ms->switchover_hold_sem); error_free(ms->error); } @@ -3336,6 +3396,7 @@ static void migration_instance_init(Object *obj) qemu_sem_init(&ms->rate_limit_sem, 0); qemu_sem_init(&ms->wait_unplug_sem, 0); qemu_sem_init(&ms->postcopy_qemufile_src_sem, 0); + qemu_sem_init(&ms->switchover_hold_sem, 0); qemu_mutex_init(&ms->qemu_file_lock); } diff --git a/migration/options.c b/migration/options.c index 5a9505adf7..aac658fb2d 100644 --- a/migration/options.c +++ b/migration/options.c @@ -163,6 +163,8 @@ Property migration_properties[] = { DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds), DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname), DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz), + DEFINE_PROP_BOOL("switchover-hold", MigrationState, + parameters.switchover_hold, false), /* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), @@ -900,6 +902,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->announce_rounds = s->parameters.announce_rounds; params->has_announce_step = true; params->announce_step = s->parameters.announce_step; + params->has_switchover_hold = true; + params->switchover_hold = s->parameters.switchover_hold; if (s->parameters.has_block_bitmap_mapping) { params->has_block_bitmap_mapping = true; @@ -940,6 +944,7 @@ void migrate_params_init(MigrationParameters *params) params->has_announce_max = true; params->has_announce_rounds = true; params->has_announce_step = true; + params->has_switchover_hold = true; } /* @@ -1194,6 +1199,9 @@ static void migrate_params_test_apply(MigrateSetParameters *params, if (params->has_announce_step) { dest->announce_step = params->announce_step; } + if (params->has_switchover_hold) { + dest->switchover_hold = params->switchover_hold; + } if (params->has_block_bitmap_mapping) { dest->has_block_bitmap_mapping = true; @@ -1307,6 +1315,15 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp) if (params->has_announce_step) { s->parameters.announce_step = params->announce_step; } + if (params->has_switchover_hold) { + bool old = s->parameters.switchover_hold; + bool new = params->switchover_hold; + + s->parameters.switchover_hold = params->switchover_hold; + if (old && !new) { + qemu_sem_post(&s->switchover_hold_sem); + } + } if (params->has_block_bitmap_mapping) { qapi_free_BitmapMigrationNodeAliasList( -- 2.41.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4 1/2] migration: switchover-hold parameter 2023-07-05 16:31 ` [PATCH v4 1/2] migration: switchover-hold parameter Peter Xu @ 2023-07-06 8:40 ` Avihai Horon 2023-07-06 12:27 ` Peter Xu 0 siblings, 1 reply; 5+ messages in thread From: Avihai Horon @ 2023-07-06 8:40 UTC (permalink / raw) To: Peter Xu, qemu-devel Cc: Eric Blake, Laszlo Ersek, Thomas Huth, Daniel P . Berrangé, Markus Armbruster, Juan Quintela, Leonardo Bras Soares Passos, Laurent Vivier, Paolo Bonzini Hi Peter, On 05/07/2023 19:31, Peter Xu wrote: > External email: Use caution opening links or attachments > > > Add a new migration parameter switchover-hold which can block src qemu > migration from switching over to dest from running. > > One can set this flag to true so src qemu will keep iterating the VM data, > not switching over to dest even if it can. > > It means now live migration works somehow like COLO; we keep syncing data > from src to dst without stopping. > > When the user is ready for the switchover, one can set the parameter from > true->false. That'll contain a implicit kick to migration thread to be > alive and re-evaluate the switchover decision. > > This can be used in two cases so far in my mind: > > (1) One can use this parameter to start pre-heating migration (but not > really migrating, so a migrate-cancel will cancel the preheat). When > the user wants to really migrate, just clear the flag. It'll in most > cases migrate immediately because most pages are already synced. > > (2) Can also be used as a clean way to do qtest, in many of the precopy > tests we have requirement to run after 1 iteration without completing > the precopy migration. Before that we have either set bandwidth to > ridiculous low value, or tricks on detecting guest memory change over > some adhoc guest memory position. Now we can simply set this flag > then we know precopy won't complete and will just keep going. > > Here we leveraged a sem to make sure migration thread won't busy spin on a > physical cpu, meanwhile provide a timedwait() of 10ms so it can still try > its best to sync with dest QEMU from time to time. Note that the sem is > prone to outdated counts but it's benign, please refer to the comment above > the semaphore definition for more information. > > Signed-off-by: Peter Xu <peterx@redhat.com> > --- > qapi/migration.json | 25 ++++++++++-- > migration/migration.h | 17 +++++++++ > migration/migration-hmp-cmds.c | 3 ++ > migration/migration.c | 69 ++++++++++++++++++++++++++++++++-- > migration/options.c | 17 +++++++++ > 5 files changed, 124 insertions(+), 7 deletions(-) > > diff --git a/qapi/migration.json b/qapi/migration.json > index 47dfef0278..c050081555 100644 > --- a/qapi/migration.json > +++ b/qapi/migration.json > @@ -789,6 +789,15 @@ > # Nodes are mapped to their block device name if there is one, and > # to their node name otherwise. (Since 5.2) > # > +# @switchover-hold: Whether we should hold-off precopy switchover from > +# src to dest QEMU, even if we can finish migration in the > +# downtime specified. By default off, so precopy migration will > +# complete as soon as possible. One can set it to explicitly keep > +# iterating during precopy migration until set the flag to false > +# again to kick off the final switchover. Note, this does not > +# affect postcopy switchover, because the user can control that > +# using "migrate-start-postcopy" command explicitly. (Since 8.1) > +# > # Features: > # > # @unstable: Member @x-checkpoint-delay is experimental. > @@ -810,7 +819,7 @@ > 'xbzrle-cache-size', 'max-postcopy-bandwidth', > 'max-cpu-throttle', 'multifd-compression', > 'multifd-zlib-level' ,'multifd-zstd-level', > - 'block-bitmap-mapping' ] } > + 'block-bitmap-mapping', 'switchover-hold' ] } > > ## > # @MigrateSetParameters: > @@ -945,6 +954,10 @@ > # Nodes are mapped to their block device name if there is one, and > # to their node name otherwise. (Since 5.2) > # > +# @switchover-hold: Whether we should hold-off precopy switchover from > +# src to dest QEMU. For more details, please refer to > +# MigrationParameter entry of the same field. (Since 8.1) > +# > # Features: > # > # @unstable: Member @x-checkpoint-delay is experimental. > @@ -982,7 +995,8 @@ > '*multifd-compression': 'MultiFDCompression', > '*multifd-zlib-level': 'uint8', > '*multifd-zstd-level': 'uint8', > - '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } > + '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ], > + '*switchover-hold': 'bool' } } > > ## > # @migrate-set-parameters: > @@ -1137,6 +1151,10 @@ > # Nodes are mapped to their block device name if there is one, and > # to their node name otherwise. (Since 5.2) > # > +# @switchover-hold: Whether we should hold-off precopy switchover from > +# src to dest QEMU. For more details, please refer to > +# MigrationParameter entry of the same field. (Since 8.1) > +# > # Features: > # > # @unstable: Member @x-checkpoint-delay is experimental. > @@ -1171,7 +1189,8 @@ > '*multifd-compression': 'MultiFDCompression', > '*multifd-zlib-level': 'uint8', > '*multifd-zstd-level': 'uint8', > - '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } > + '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ], > + '*switchover-hold': 'bool' } } > > ## > # @query-migrate-parameters: > diff --git a/migration/migration.h b/migration/migration.h > index a80b22b703..6b31a4b371 100644 > --- a/migration/migration.h > +++ b/migration/migration.h > @@ -453,6 +453,23 @@ struct MigrationState { > * switchover has been received. > */ > bool switchover_acked; > + > + /* > + * Only migration thread will wait on it when switchover_hold==true. > + * > + * Only qmp set param will kick it when switching switchover_hold from > + * true->false. > + * > + * NOTE: outdated sem count here is benign. E.g., when this is posted, > + * the 1st migration got cancelled, then start the 2nd migration, or > + * when someone sets the flag from true->false->true->false.. because > + * any outdated sem count will only let the migration thread to run one > + * more loop (timedwait() will eat the outdated count) when reaching > + * the completion phase, then in the next loop it'll sleep again. The > + * important thing here OTOH is when the migration thread is sleeping > + * we can always kick it out of the sleep, which we will always do. > + */ > + QemuSemaphore switchover_hold_sem; > }; > > void migrate_set_state(int *state, int old_state, int new_state); > diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c > index 9885d7c9f7..63a2c8a4a3 100644 > --- a/migration/migration-hmp-cmds.c > +++ b/migration/migration-hmp-cmds.c > @@ -338,6 +338,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) > monitor_printf(mon, "%s: '%s'\n", > MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), > params->tls_authz); > + monitor_printf(mon, "%s: %s\n", > + MigrationParameter_str(MIGRATION_PARAMETER_SWITCHOVER_HOLD), > + params->switchover_hold ? "on" : "off"); > > if (params->has_block_bitmap_mapping) { > const BitmapMigrationNodeAliasList *bmnal; > diff --git a/migration/migration.c b/migration/migration.c > index 096e8191d1..d75c2bd63c 100644 > --- a/migration/migration.c > +++ b/migration/migration.c > @@ -2721,6 +2721,67 @@ static bool migration_can_switchover(MigrationState *s) > return s->switchover_acked; > } > > +static bool > +migration_should_complete(MigrationState *s, uint64_t pending_size) > +{ > + /* Need an explicit ACK from dst? */ > + if (!migration_can_switchover(s)) { > + return false; > + } > + > + /* We still have large pending data to send? */ > + if (pending_size && (pending_size >= s->threshold_size)) { > + return false; > + } > + > + /* The user doesn't want us to switchover yet for precopy */ > + if (!migration_in_postcopy() && s->parameters.switchover_hold) { > + /* > + * Note: when reaching here it probably means we've migrated almost > + * everything and ready to switchover. If user asked not to switch > + * wait for a short period and respond to kicks immediately. > + * > + * If we wait too long, there can be a lot of dirty data generated, > + * while we could have done something to sync data between src/dst. > + * > + * If we wait too short, migration thread can eat most/all cpu > + * resource looping over switchover_hold. > + * > + * Make it 10ms which seems to be a good intermediate value. > + */ > + qemu_sem_timedwait(&s->switchover_hold_sem, 10); > + > + /* > + * Return false here always even if user changed it, because we'd > + * like to re-evaluate everything (e.g. pending_size). > + */ > + return false; > + } > + > + return true; > +} > + > +static bool > +migration_should_start_postcopy(MigrationState *s, uint64_t must_precopy) > +{ > + /* If we're already in postcopy phase, don't bother */ > + if (migration_in_postcopy()) { > + return false; > + } > + > + /* Need an explicit ACK from dst? */ > + if (!migration_can_switchover(s)) { > + return false; > + } > + > + /* We still have lots of thing that must be migrated in precopy */ > + if (must_precopy > s->threshold_size) { > + return false; > + } > + > + return qatomic_read(&s->start_postcopy); > +} > + > /* Migration thread iteration status */ > typedef enum { > MIG_ITERATE_RESUME, /* Resume current iteration */ > @@ -2736,7 +2797,6 @@ static MigIterateState migration_iteration_run(MigrationState *s) > { > uint64_t must_precopy, can_postcopy; > bool in_postcopy = s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE; > - bool can_switchover = migration_can_switchover(s); > > qemu_savevm_state_pending_estimate(&must_precopy, &can_postcopy); > uint64_t pending_size = must_precopy + can_postcopy; > @@ -2749,15 +2809,14 @@ static MigIterateState migration_iteration_run(MigrationState *s) > trace_migrate_pending_exact(pending_size, must_precopy, can_postcopy); > } > > - if ((!pending_size || pending_size < s->threshold_size) && can_switchover) { > + if (migration_should_complete(s, pending_size)) { > trace_migration_thread_low_pending(pending_size); > migration_completion(s); > return MIG_ITERATE_BREAK; > } > > /* Still a significant amount to transfer */ > - if (!in_postcopy && must_precopy <= s->threshold_size && can_switchover && > - qatomic_read(&s->start_postcopy)) { > + if (migration_should_start_postcopy(s, must_precopy)) { > if (postcopy_start(s)) { > error_report("%s: postcopy failed to start", __func__); > } > @@ -3314,6 +3373,7 @@ static void migration_instance_finalize(Object *obj) > qemu_sem_destroy(&ms->rp_state.rp_sem); > qemu_sem_destroy(&ms->rp_state.rp_pong_acks); > qemu_sem_destroy(&ms->postcopy_qemufile_src_sem); > + qemu_sem_destroy(&ms->switchover_hold_sem); > error_free(ms->error); > } > > @@ -3336,6 +3396,7 @@ static void migration_instance_init(Object *obj) > qemu_sem_init(&ms->rate_limit_sem, 0); > qemu_sem_init(&ms->wait_unplug_sem, 0); > qemu_sem_init(&ms->postcopy_qemufile_src_sem, 0); > + qemu_sem_init(&ms->switchover_hold_sem, 0); > qemu_mutex_init(&ms->qemu_file_lock); > } > > diff --git a/migration/options.c b/migration/options.c > index 5a9505adf7..aac658fb2d 100644 > --- a/migration/options.c > +++ b/migration/options.c > @@ -163,6 +163,8 @@ Property migration_properties[] = { > DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds), > DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname), > DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz), > + DEFINE_PROP_BOOL("switchover-hold", MigrationState, > + parameters.switchover_hold, false), > > /* Migration capabilities */ > DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), > @@ -900,6 +902,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) > params->announce_rounds = s->parameters.announce_rounds; > params->has_announce_step = true; > params->announce_step = s->parameters.announce_step; > + params->has_switchover_hold = true; > + params->switchover_hold = s->parameters.switchover_hold; > > if (s->parameters.has_block_bitmap_mapping) { > params->has_block_bitmap_mapping = true; > @@ -940,6 +944,7 @@ void migrate_params_init(MigrationParameters *params) > params->has_announce_max = true; > params->has_announce_rounds = true; > params->has_announce_step = true; > + params->has_switchover_hold = true; > } > > /* > @@ -1194,6 +1199,9 @@ static void migrate_params_test_apply(MigrateSetParameters *params, > if (params->has_announce_step) { > dest->announce_step = params->announce_step; > } > + if (params->has_switchover_hold) { > + dest->switchover_hold = params->switchover_hold; > + } > > if (params->has_block_bitmap_mapping) { > dest->has_block_bitmap_mapping = true; > @@ -1307,6 +1315,15 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp) > if (params->has_announce_step) { > s->parameters.announce_step = params->announce_step; > } > + if (params->has_switchover_hold) { > + bool old = s->parameters.switchover_hold; > + bool new = params->switchover_hold; > + > + s->parameters.switchover_hold = params->switchover_hold; > + if (old && !new) { > + qemu_sem_post(&s->switchover_hold_sem); > + } > + } This only handles the QMP case, but we forgot to handle the HMP case. I was testing it and got the following assert: (qemu) migrate_set_parameter switchover-hold on qemu-system-x86_64: ../migration/migration-hmp-cmds.c:627: hmp_migrate_set_parameter: Assertion `0' failed. Aborted (core dumped) Thanks. > > if (params->has_block_bitmap_mapping) { > qapi_free_BitmapMigrationNodeAliasList( > -- > 2.41.0 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 1/2] migration: switchover-hold parameter 2023-07-06 8:40 ` Avihai Horon @ 2023-07-06 12:27 ` Peter Xu 0 siblings, 0 replies; 5+ messages in thread From: Peter Xu @ 2023-07-06 12:27 UTC (permalink / raw) To: Avihai Horon Cc: qemu-devel, Eric Blake, Laszlo Ersek, Thomas Huth, Daniel P . Berrangé, Markus Armbruster, Juan Quintela, Leonardo Bras Soares Passos, Laurent Vivier, Paolo Bonzini On Thu, Jul 06, 2023 at 11:40:04AM +0300, Avihai Horon wrote: > This only handles the QMP case, but we forgot to handle the HMP case. > I was testing it and got the following assert: > > (qemu) migrate_set_parameter switchover-hold on > qemu-system-x86_64: ../migration/migration-hmp-cmds.c:627: > hmp_migrate_set_parameter: Assertion `0' failed. > Aborted (core dumped) Ouch.. I'll fix it, thanks. -- Peter Xu ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 2/2] qtest/migration: Use switchover-hold to speedup 2023-07-05 16:31 [PATCH v4 0/2] migration: switchover-hold flag Peter Xu 2023-07-05 16:31 ` [PATCH v4 1/2] migration: switchover-hold parameter Peter Xu @ 2023-07-05 16:31 ` Peter Xu 1 sibling, 0 replies; 5+ messages in thread From: Peter Xu @ 2023-07-05 16:31 UTC (permalink / raw) To: qemu-devel Cc: Eric Blake, Laszlo Ersek, Thomas Huth, Daniel P . Berrangé, Markus Armbruster, Juan Quintela, peterx, Avihai Horon, Leonardo Bras Soares Passos, Laurent Vivier, Paolo Bonzini This solution is heavily based on Daniel's original approach here, but hopefully a cleaner way to impl: https://lore.kernel.org/r/20230601161347.1803440-11-berrange@redhat.com The difference is we use the switchover-hold flag rather than tuning bw+downtime to guide test convergence, comparing to use the magic offset. This can achieve similar goal of previous patch "tests/qtest: massively speed up migration-test" but without magic offset to write or monitoring. With this flag, we can safely always run migration tests with full speed (bw=0). However for postcopy tests, when with above bw=0, it's easy to happen that right after switching to postcopy there're merely no page left, so the postcopy paths are not well tested. To remedy that, don't wait for a full iteration but switch to postcopy in the 1st iteration, adding a precopy bw limit (200MB/s for now, running 100ms) so it should guarantee enough pages left for postcopy. One pity is that normally postcopy switchover happens after 1-2 rounds of precopy, so qtest doesn't follow that anymore (while it was trying to). However it also means previous postcopy tests never tested the case where there're holes in pages (pages that never got migrated during precopy), now we cover that too which is actually also a valid scenario for postcopy. The initial solution can reduce migration-test time from 8min to 1min40s, this patch can further reduce it from 1m40s to <1m per my local test. While at it, add migrate_set_bandwidth_[pre|post]copy() and use them. Signed-off-by: Peter Xu <peterx@redhat.com> --- tests/qtest/migration-test.c | 39 +++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index b9cc194100..d5584d07a9 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -433,16 +433,23 @@ static void migrate_set_parameter_bool(QTestState *who, const char *parameter, static void migrate_ensure_non_converge(QTestState *who) { - /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */ - migrate_set_parameter_int(who, "max-bandwidth", 3 * 1000 * 1000); - migrate_set_parameter_int(who, "downtime-limit", 1); + /* Hold off switchover for precopy only */ + migrate_set_parameter_bool(who, "switchover-hold", true); } static void migrate_ensure_converge(QTestState *who) { - /* Should converge with 30s downtime + 1 gbs bandwidth limit */ - migrate_set_parameter_int(who, "max-bandwidth", 1 * 1000 * 1000 * 1000); - migrate_set_parameter_int(who, "downtime-limit", 30 * 1000); + migrate_set_parameter_bool(who, "switchover-hold", false); +} + +static void migrate_set_bandwidth_precopy(QTestState *who, int bw) +{ + migrate_set_parameter_int(who, "max-bandwidth", bw); +} + +static void migrate_set_bandwidth_postcopy(QTestState *who, int bw) +{ + migrate_set_parameter_int(who, "max-postcopy-bandwidth", bw); } static void migrate_pause(QTestState *who) @@ -736,6 +743,14 @@ static int test_migrate_start(QTestState **from, QTestState **to, unlink(shmem_path); } + /* + * By default, use full speed for precopy in qtests as that will reduce + * the time of testing. The default bandwidth (128MB/s) may be too slow + * in this case. Specific test can overwrite this value after the + * function returns but before starting migration. + */ + migrate_set_bandwidth_precopy(*from, 0); + return 0; } @@ -1168,9 +1183,13 @@ static int migrate_postcopy_prepare(QTestState **from_ptr, /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); + /* + * Limit precopy to 200MB/s for 0.1 sec, so we guarantee to leave + * enough pages (total-20MB) for remote page fault processes later. + */ + migrate_set_bandwidth_precopy(from, 200 * 1024 * 1024); migrate_qmp(from, uri, "{}"); - - wait_for_migration_pass(from); + usleep(100000); *from_ptr = from; *to_ptr = to; @@ -1270,7 +1289,7 @@ static void test_postcopy_recovery_common(MigrateCommon *args) } /* Turn postcopy speed down, 4K/s is slow enough on any machines */ - migrate_set_parameter_int(from, "max-postcopy-bandwidth", 4096); + migrate_set_bandwidth_postcopy(from, 4096); /* Now we start the postcopy */ migrate_postcopy_start(from, to); @@ -1314,7 +1333,7 @@ static void test_postcopy_recovery_common(MigrateCommon *args) migrate_qmp(from, uri, "{'resume': true}"); /* Restore the postcopy bandwidth to unlimited */ - migrate_set_parameter_int(from, "max-postcopy-bandwidth", 0); + migrate_set_bandwidth_postcopy(from, 0); migrate_postcopy_complete(from, to, args); } -- 2.41.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-06 12:28 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-07-05 16:31 [PATCH v4 0/2] migration: switchover-hold flag Peter Xu 2023-07-05 16:31 ` [PATCH v4 1/2] migration: switchover-hold parameter Peter Xu 2023-07-06 8:40 ` Avihai Horon 2023-07-06 12:27 ` Peter Xu 2023-07-05 16:31 ` [PATCH v4 2/2] qtest/migration: Use switchover-hold to speedup Peter Xu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).