QEMU now supports multifd-compression=zstd for migration with enabled multifd. Bring the support to libvirt as well. Signed-off-by: Oleg Vasilev <oleg.vasilev@xxxxxxxxxxxxx> --- include/libvirt/libvirt-domain.h | 10 ++++++++++ src/qemu/qemu_migration.h | 1 + src/qemu/qemu_migration_params.c | 32 ++++++++++++++++++++++++++++++++ src/qemu/qemu_migration_params.h | 2 ++ tools/virsh-completer-domain.c | 2 +- tools/virsh-domain.c | 14 ++++++++++++++ 6 files changed, 60 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 3ebb2c6642..f267ca357b 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1319,6 +1319,16 @@ typedef enum { */ # define VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE "compression.xbzrle.cache" +/** + * VIR_MIGRATE_PARAM_COMPRESSION_ZSTD_LEVEL: + * + * virDomainMigrate* params field: the level of compression for zstd + * compression as VIR_TYPED_PARAM_INT. Accepted values are in range 1-22. + * + * Since: 9.0.0 + */ +# define VIR_MIGRATE_PARAM_COMPRESSION_ZSTD_LEVEL "compression.zstd.level" + /** * VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL: * diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index d21b6f67e8..09d21fd878 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -88,6 +88,7 @@ VIR_MIGRATE_PARAM_PARALLEL_CONNECTIONS, VIR_TYPED_PARAM_INT, \ VIR_MIGRATE_PARAM_TLS_DESTINATION, VIR_TYPED_PARAM_STRING, \ VIR_MIGRATE_PARAM_DISKS_URI, VIR_TYPED_PARAM_STRING, \ + VIR_MIGRATE_PARAM_COMPRESSION_ZSTD_LEVEL, VIR_TYPED_PARAM_INT, \ NULL diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c index a40f791be6..2533353ccf 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -71,6 +71,7 @@ struct _qemuMigrationParams { typedef enum { QEMU_MIGRATION_COMPRESS_XBZRLE = 0, QEMU_MIGRATION_COMPRESS_MT, + QEMU_MIGRATION_COMPRESS_ZSTD, QEMU_MIGRATION_COMPRESS_LAST } qemuMigrationCompressMethod; @@ -79,6 +80,7 @@ VIR_ENUM_IMPL(qemuMigrationCompressMethod, QEMU_MIGRATION_COMPRESS_LAST, "xbzrle", "mt", + "zstd", ); VIR_ENUM_IMPL(qemuMigrationCapability, @@ -114,6 +116,8 @@ VIR_ENUM_IMPL(qemuMigrationParam, "xbzrle-cache-size", "max-postcopy-bandwidth", "multifd-channels", + "multifd-compression", + "multifd-zstd-level", ); typedef struct _qemuMigrationParamsAlwaysOnItem qemuMigrationParamsAlwaysOnItem; @@ -216,6 +220,10 @@ static const qemuMigrationParamsTPMapItem qemuMigrationParamsTPMap[] = { .param = QEMU_MIGRATION_PARAM_XBZRLE_CACHE_SIZE, .party = QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION}, + {.typedParam = VIR_MIGRATE_PARAM_COMPRESSION_ZSTD_LEVEL, + .param = QEMU_MIGRATION_PARAM_MULTIFD_ZSTD_LEVEL, + .party = QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION}, + {.typedParam = VIR_MIGRATE_PARAM_BANDWIDTH_POSTCOPY, .unit = 1024 * 1024, /* MiB/s */ .param = QEMU_MIGRATION_PARAM_MAX_POSTCOPY_BANDWIDTH, @@ -271,6 +279,12 @@ static const qemuMigrationParamInfoItem qemuMigrationParamInfo[] = { [QEMU_MIGRATION_PARAM_MULTIFD_CHANNELS] = { .type = QEMU_MIGRATION_PARAM_TYPE_INT, }, + [QEMU_MIGRATION_PARAM_MULTIFD_COMPRESSION] = { + .type = QEMU_MIGRATION_PARAM_TYPE_STRING, + }, + [QEMU_MIGRATION_PARAM_MULTIFD_ZSTD_LEVEL] = { + .type = QEMU_MIGRATION_PARAM_TYPE_INT, + }, }; G_STATIC_ASSERT(G_N_ELEMENTS(qemuMigrationParamInfo) == QEMU_MIGRATION_PARAM_LAST); @@ -546,6 +560,10 @@ qemuMigrationParamsSetCompression(virTypedParameterPtr params, cap = QEMU_MIGRATION_CAP_COMPRESS; break; + case QEMU_MIGRATION_COMPRESS_ZSTD: + qemuMigrationParamsSetString(migParams, + QEMU_MIGRATION_PARAM_MULTIFD_COMPRESSION, + "zstd"); case QEMU_MIGRATION_COMPRESS_LAST: default: continue; @@ -569,6 +587,13 @@ qemuMigrationParamsSetCompression(virTypedParameterPtr params, return -1; } + if (migParams->params[QEMU_MIGRATION_PARAM_MULTIFD_ZSTD_LEVEL].set && + !(migParams->compMethods & (1ULL << QEMU_MIGRATION_COMPRESS_ZSTD))) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Turn zstd compression on to tune it")); + return -1; + } + if (!migParams->compMethods && (flags & VIR_MIGRATE_COMPRESSED)) { migParams->compMethods = 1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE; ignore_value(virBitmapSetBit(migParams->caps, @@ -669,6 +694,13 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params, return NULL; } + if (migParams->params[QEMU_MIGRATION_PARAM_MULTIFD_ZSTD_LEVEL].set && + !(flags & VIR_MIGRATE_PARALLEL)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Turn parallel migration on to tune zstd level")); + return NULL; + } + if (qemuMigrationParamsSetCompression(params, nparams, flags, migParams) < 0) return NULL; diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h index 458a7a4dfa..383b25ce63 100644 --- a/src/qemu/qemu_migration_params.h +++ b/src/qemu/qemu_migration_params.h @@ -59,6 +59,8 @@ typedef enum { QEMU_MIGRATION_PARAM_XBZRLE_CACHE_SIZE, QEMU_MIGRATION_PARAM_MAX_POSTCOPY_BANDWIDTH, QEMU_MIGRATION_PARAM_MULTIFD_CHANNELS, + QEMU_MIGRATION_PARAM_MULTIFD_COMPRESSION, + QEMU_MIGRATION_PARAM_MULTIFD_ZSTD_LEVEL, QEMU_MIGRATION_PARAM_LAST } qemuMigrationParam; diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index b54baf3577..66748b7b65 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -1012,7 +1012,7 @@ virshDomainMigrateCompMethodsCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags) { - const char *methods[] = {"xbzrle", "mt", NULL}; + const char *methods[] = {"xbzrle", "mt", "zstd", NULL}; const char *method = NULL; virCheckFlags(0, NULL); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 6850843a25..0813bd5de0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11056,6 +11056,10 @@ static const vshCmdOptDef opts_migrate[] = { .type = VSH_OT_INT, .help = N_("page cache size for xbzrle compression") }, + {.name = "comp-zstd-level", + .type = VSH_OT_INT, + .help = N_("zstd level for zstd compression") + }, {.name = "auto-converge-initial", .type = VSH_OT_INT, .help = N_("initial CPU throttling rate for auto-convergence") @@ -11238,6 +11242,16 @@ doMigrate(void *opaque) goto save_error; } + if ((rv = vshCommandOptInt(ctl, cmd, "comp-zstd-level", &intOpt)) < 0) { + goto out; + } else if (rv > 0) { + if (virTypedParamsAddInt(¶ms, &nparams, &maxparams, + VIR_MIGRATE_PARAM_COMPRESSION_ZSTD_LEVEL, + intOpt) < 0) + goto save_error; + } + + if (vshCommandOptStringReq(ctl, cmd, "xml", &opt) < 0) goto out; if (opt) { -- 2.40.0