From: Hyman Huang(黄勇) <huang...@chinatelecom.cn> Introduce migration dirty-limit capability, which can be turned on before live migration and limit dirty page rate durty live migration.
Introduce migrate_dirty_limit function to help check if dirty-limit capability enabled during live migration. Meanwhile, refactor vcpu_dirty_rate_stat_collect so that period can be configured instead of hardcoded. dirty-limit capability is kind of like auto-converge but using dirty limit instead of traditional cpu-throttle to throttle guest down. To enable this feature, turn on the dirty-limit capability before live migration using migrate-set-capabilities, and set the parameters "x-vcpu-dirty-limit-period", "vcpu-dirty-limit" suitably to speed up convergence. Signed-off-by: Hyman Huang(黄勇) <huang...@chinatelecom.cn> Acked-by: Peter Xu <pet...@redhat.com> --- migration/migration.c | 25 +++++++++++++++++++++++++ migration/migration.h | 1 + qapi/migration.json | 4 +++- softmmu/dirtylimit.c | 11 ++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index e479c86575..f890e5966a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -64,6 +64,7 @@ #include "yank_functions.h" #include "sysemu/qtest.h" #include "ui/qemu-spice.h" +#include "sysemu/kvm.h" #define MAX_THROTTLE (128 << 20) /* Migration transfer speed throttling */ @@ -1444,6 +1445,20 @@ static bool migrate_caps_check(bool *cap_list, } } + if (cap_list[MIGRATION_CAPABILITY_DIRTY_LIMIT]) { + if (cap_list[MIGRATION_CAPABILITY_AUTO_CONVERGE]) { + error_setg(errp, "dirty-limit conflicts with auto-converge" + " either of then available currently"); + return false; + } + + if (!kvm_enabled() || !kvm_dirty_ring_enabled()) { + error_setg(errp, "dirty-limit requires KVM with accelerator" + " property 'dirty-ring-size' set"); + return false; + } + } + return true; } @@ -2635,6 +2650,15 @@ bool migrate_auto_converge(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE]; } +bool migrate_dirty_limit(void) +{ + MigrationState *s; + + s = migrate_get_current(); + + return s->enabled_capabilities[MIGRATION_CAPABILITY_DIRTY_LIMIT]; +} + bool migrate_zero_blocks(void) { MigrationState *s; @@ -4583,6 +4607,7 @@ static Property migration_properties[] = { DEFINE_PROP_MIG_CAP("x-zero-copy-send", MIGRATION_CAPABILITY_ZERO_COPY_SEND), #endif + DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT), DEFINE_PROP_END_OF_LIST(), }; diff --git a/migration/migration.h b/migration/migration.h index 2da2f8a164..cd2e9bfeea 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -418,6 +418,7 @@ bool migrate_ignore_shared(void); bool migrate_validate_uuid(void); bool migrate_auto_converge(void); +bool migrate_dirty_limit(void); bool migrate_use_multifd(void); bool migrate_pause_before_switchover(void); int migrate_multifd_channels(void); diff --git a/qapi/migration.json b/qapi/migration.json index d33cc2d582..b7a92be055 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -477,6 +477,8 @@ # will be handled faster. This is a performance feature and # should not affect the correctness of postcopy migration. # (since 7.1) +# @dirty-limit: Use dirty-limit to throttle down guest if enabled. +# (since 8.0) # # Features: # @unstable: Members @x-colo and @x-ignore-shared are experimental. @@ -492,7 +494,7 @@ 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, 'validate-uuid', 'background-snapshot', - 'zero-copy-send', 'postcopy-preempt'] } + 'zero-copy-send', 'postcopy-preempt', 'dirty-limit'] } ## # @MigrationCapabilityStatus: diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c index dcab9bf2b1..52d1b2c6fa 100644 --- a/softmmu/dirtylimit.c +++ b/softmmu/dirtylimit.c @@ -22,6 +22,8 @@ #include "exec/memory.h" #include "hw/boards.h" #include "sysemu/kvm.h" +#include "migration/misc.h" +#include "migration/migration.h" #include "trace.h" /* @@ -74,11 +76,18 @@ static bool dirtylimit_quit; static void vcpu_dirty_rate_stat_collect(void) { + MigrationState *s = migrate_get_current(); VcpuStat stat; int i = 0; + int64_t period = DIRTYLIMIT_CALC_TIME_MS; + + if (migrate_dirty_limit() && + migration_is_active(s)) { + period = s->parameters.x_vcpu_dirty_limit_period; + } /* calculate vcpu dirtyrate */ - vcpu_calculate_dirtyrate(DIRTYLIMIT_CALC_TIME_MS, + vcpu_calculate_dirtyrate(period, &stat, GLOBAL_DIRTY_LIMIT, false); -- 2.17.1