Multifd Migration Compression
v5 cover Multifd Migration Compression
Based-on: [email protected]
[v5]
- rebased on top of latest pull request
- check zlib/zstd return codes in loops (denis suggestions)
- check that we do the right thing in error cases (I corrupted the stream, make buffers too small, etc by hand)
[v4]
- create new parameters: multifd-zlib-level & multifd-zstd-level
- use proper "conditionals" for qapi (thanks markus)
- more than half of the patches moved to the migration PULL request that this series are based on
- method type has moved to one int from a set of flags
- fixed all reviews comments
Please review.
[v3]
- rebased on top of upstream + previous multifd cancel series
- split multifd code into its own file (multifd.[ch])
- split zstd/zlib compression methods (multifd-zstd/zlib.c)
- use qemu module feauture to avoid ifdefs
(my understanding is that zlib needs to be present, but we setup zstd only if it is not there or is disabled)
- multifd-method: none|zlib|zstd
As far as I can see, there is no easy way to convince qapi that zstd option could/couldn't be there depending on compliation flags. I ended just checking in migrate_parameters_check() if it is enabled and giving an error message otherwise.
Questions:
- I am "reusing" the compress-level parameter for both zstd and zlib, but it poses a problem:
* zlib values: 1-9 (default: 6?)
* zstd values: 1-19 (default: 3)
So, what should I do:
* create multifd-zstd-level and multifd-zlib-level (easier)
* reuse compress-level, and change its maximum values depending on multifd-method
* any other good option?
Please, review.
[v2] - rebase on top of previous arguments posted to the list - introduces zlib compression - introduces zstd compression
Please help if you know anything about zstd/zlib compression.
This puts compression on top of multifd. Advantages about current compression:
- We copy all pages in a single packet and then compress the whole thing.
- We reuse the compression stream for all the packets sent through the same channel.
- We can select nocomp/zlib/zstd levels of compression.
Please, review.
Juan Quintela (8):
multifd: Add multifd-method parameter
migration: Add support for modules
multifd: Make no compression operations into its own structure
multifd: Add multifd-zlib-level parameter
multifd: Add zlib compression multifd support
configure: Enable test and libs for zstd
multifd: Add multifd-zstd-level parameter
multifd: Add zstd compression multifd support
configure | 30 ++++ hw/core/qdev-properties.c | 13 ++ include/hw/qdev-properties.h | 3 + include/qemu/module.h | 2 + migration/Makefile.objs | 2 + migration/migration.c | 70 ++++++++ migration/migration.h | 3 + migration/multifd-zlib.c | 325 +++++++++++++++++++++++++++++++++ migration/multifd-zstd.c | 337 +++++++++++++++++++++++++++++++++++ migration/multifd.c | 191 +++++++++++++++++++- migration/multifd.h | 29 +++ migration/ram.c | 2 +- monitor/hmp-cmds.c | 21 +++ qapi/migration.json | 80 ++++++++- tests/qtest/migration-test.c | 30 +++- vl.c | 1 + 16 files changed, 1123 insertions(+), 16 deletions(-) create mode 100644 migration/multifd-zlib.c create mode 100644 migration/multifd-zstd.c
Signature · 1 line
2.24.1
PATCH v5 1/8 multifd: Add multifd-method parameter
This will store the compression method to use. We start with none.
--- hw/core/qdev-properties.c | 13 +++++++++++++ include/hw/qdev-properties.h | 3 +++ migration/migration.c | 13 +++++++++++++ monitor/hmp-cmds.c | 13 +++++++++++++ qapi/migration.json | 30 +++++++++++++++++++++++++++--- tests/qtest/migration-test.c | 14 ++++++++++---- 6 files changed, 79 insertions(+), 7 deletions(-)
hw/core/qdev-properties.c +13 -0
@@ -8,6 +8,7 @@#include "qapi/qmp/qerror.h" #include "qemu/ctype.h" #include "qemu/error-report.h" +#include "qapi/qapi-types-migration.h" #include "hw/block/block.h" #include "net/hub.h" #include "qapi/visitor.h"
@@ -639,6 +640,18 @@ const PropertyInfo qdev_prop_fdc_drive_type = { .set_default_value = set_default_value_enum, }; +/* --- MultiFDMethod --- */ + +const PropertyInfo qdev_prop_multifd_method = { + .name ="MultiFDMethod" , + .description ="multifd_method values, " +"none" , + .enum_table = &MultiFDMethod_lookup, + .get = get_enum, + .set = set_enum, + .set_default_value = set_default_value_enum, +}; +/* --- pci address --- */ /*
include/hw/qdev-properties.h +3 -0
@@ -20,6 +20,7 @@ extern const PropertyInfo qdev_prop_chr;extern const PropertyInfo qdev_prop_tpm;extern const PropertyInfo qdev_prop_macaddr;extern const PropertyInfo qdev_prop_on_off_auto; +extern const PropertyInfo qdev_prop_multifd_method;extern const PropertyInfo qdev_prop_losttickpolicy;extern const PropertyInfo qdev_prop_blockdev_on_error;extern const PropertyInfo qdev_prop_bios_chs_trans;
@@ -184,6 +185,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width; DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)#define DEFINE_PROP_ON_OFF_AUTO (_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto) +#define DEFINE_PROP_MULTIFD_METHOD (_n, _s, _f, _d) \ + DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_multifd_method, MultiFDMethod)#define DEFINE_PROP_LOSTTICKPOLICY (_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ LostTickPolicy)
migration/migration.c +13 -0
@@ -88,6 +88,7 @@/* The delay time (in ms) between two COLO checkpoints */ #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY (200 * 100)#define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2 +#define DEFAULT_MIGRATE_MULTIFD_METHOD MULTIFD_METHOD_NONE/* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit.
@@ -798,6 +799,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->block_incremental = s->parameters.block_incremental; params->has_multifd_channels = true; params->multifd_channels = s->parameters.multifd_channels; + params->has_multifd_method = true; + params->multifd_method = s->parameters.multifd_method; params->has_xbzrle_cache_size = true; params->xbzrle_cache_size = s->parameters.xbzrle_cache_size; params->has_max_postcopy_bandwidth = true;
@@ -1315,6 +1318,9 @@ static void migrate_params_test_apply(MigrateSetParameters *params,if (params->has_multifd_channels) { dest->multifd_channels = params->multifd_channels; } +if (params->has_multifd_method) { + dest->multifd_method = params->multifd_method; + }if (params->has_xbzrle_cache_size) { dest->xbzrle_cache_size = params->xbzrle_cache_size; }
@@ -1411,6 +1417,9 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)if (params->has_multifd_channels) { s->parameters.multifd_channels = params->multifd_channels; } +if (params->has_multifd_method) { + s->parameters.multifd_method = params->multifd_method; + }if (params->has_xbzrle_cache_size) { s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;xbzrle_cache_resize (params->xbzrle_cache_size, errp);
@@ -3515,6 +3524,9 @@ static Property migration_properties[] = {DEFINE_PROP_UINT8 ("multifd-channels" , MigrationState, parameters.multifd_channels,DEFAULT_MIGRATE_MULTIFD_CHANNELS ), +DEFINE_PROP_MULTIFD_METHOD ("multifd-method" , MigrationState, + parameters.multifd_method, +DEFAULT_MIGRATE_MULTIFD_METHOD ),DEFINE_PROP_SIZE ("xbzrle-cache-size" , MigrationState, parameters.xbzrle_cache_size, DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),
@@ -3605,6 +3617,7 @@ static void migration_instance_init(Object *obj) params->has_x_checkpoint_delay = true; params->has_block_incremental = true; params->has_multifd_channels = true; + params->has_multifd_method = true; params->has_xbzrle_cache_size = true; params->has_max_postcopy_bandwidth = true; params->has_max_cpu_throttle = true;
monitor/hmp-cmds.c +13 -0
@@ -39,6 +39,7 @@#include "qapi/qapi-commands-tpm.h" #include "qapi/qapi-commands-ui.h" #include "qapi/qapi-visit-net.h" +#include "qapi/qapi-visit-migration.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qapi/string-input-visitor.h"
@@ -447,6 +448,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)monitor_printf (mon,"%s: %u\n" ,MigrationParameter_str (MIGRATION_PARAMETER_MULTIFD_CHANNELS ), params->multifd_channels); +monitor_printf (mon,"%s: %s\n" , +MigrationParameter_str (MIGRATION_PARAMETER_MULTIFD_METHOD ), +MultiFDMethod_str (params->multifd_method));monitor_printf (mon,"%s: %" PRIu64"\n" ,MigrationParameter_str (MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE ), params->xbzrle_cache_size);
@@ -1738,6 +1742,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)MigrateSetParameters *p =g_new0 (MigrateSetParameters,1 );uint64_t valuebw =0 ;uint64_t cache_size; +MultiFDMethod compress_type;Error *err =NULL ;int val, ret;
@@ -1823,6 +1828,14 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p->has_multifd_channels = true;visit_type_int (v, param, &p->multifd_channels, &err);break ; +case MIGRATION_PARAMETER_MULTIFD_METHOD : + p->has_multifd_method = true; +visit_type_MultiFDMethod (v, param, &compress_type, &err); +if (err) { +break ; + } + p->multifd_method = compress_type; +break ;case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE : p->has_xbzrle_cache_size = true;visit_type_size (v, param, &cache_size, &err);
qapi/migration.json +27 -3
@@ -488,6 +488,19 @@ ## { 'command': 'query-migrate-capabilities', 'returns': ['MigrationCapabilityStatus']} +## +# @MultiFDMethod: +# +# An enumeration of multifd compression. +# +# @none: no compression. +# +# Since: 5.0 +# +## +{ 'enum': 'MultiFDMethod', + 'data': [ 'none' ] } + ## # @MigrationParameter: #
@@ -586,6 +599,9 @@ # @max-cpu-throttle: maximum cpu throttle percentage. # Defaults to 99. (Since 3.1) # +# @multifd-method: Which compression method to use. +# Defaults to none. (Since 5.0) +# # Since: 2.4 ## { 'enum': 'MigrationParameter',
@@ -598,7 +614,7 @@ 'downtime-limit', 'x-checkpoint-delay', 'block-incremental', 'multifd-channels', 'xbzrle-cache-size', 'max-postcopy-bandwidth', - 'max-cpu-throttle' ] } + 'max-cpu-throttle', 'multifd-method' ] } ## # @MigrateSetParameters:
@@ -688,6 +704,9 @@ # @max-cpu-throttle: maximum cpu throttle percentage. # The default value is 99. (Since 3.1) # +# @multifd-method: Which compression method to use. +# Defaults to none. (Since 5.0) +# # Since: 2.4 ## # TODO either fuse back into MigrationParameters, or make
@@ -713,7 +732,8 @@ '*multifd-channels': 'int', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle': 'int' } } + '*max-cpu-throttle': 'int', + '*multifd-method': 'MultiFDMethod' } } ## # @migrate-set-parameters:
@@ -823,6 +843,9 @@ # Defaults to 99. # (Since 3.1) # +# @multifd-method: Which compression method to use. +# Defaults to none. (Since 5.0) +# # Since: 2.4 ## { 'struct': 'MigrationParameters',
@@ -846,7 +869,8 @@ '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle':'uint8'} } + '*max-cpu-throttle': 'uint8', + '*multifd-method': 'MultiFDMethod' } } ## # @query-migrate-parameters:
tests/qtest/migration-test.c +10 -4
@@ -378,7 +378,6 @@ static void migrate_check_parameter_str(QTestState *who, const char *parameter,g_free (result); } -__attribute__((unused))static void migrate_set_parameter_str (QTestState *who,const char *parameter,const char *value) {
@@ -1251,7 +1250,7 @@ static void test_migrate_auto_converge(void)test_migrate_end (from, to, true); } -static void test_multifd_tcp (void ) +static void test_multifd_tcp (const char *method) {MigrateStart *args =migrate_start_new ();QTestState *from, *to;
@@ -1275,6 +1274,9 @@ static void test_multifd_tcp(void)migrate_set_parameter_int (from,"multifd-channels" ,16 );migrate_set_parameter_int (to,"multifd-channels" ,16 ); +migrate_set_parameter_str (from,"multifd-method" , method); +migrate_set_parameter_str (to,"multifd-method" , method); +migrate_set_capability (from,"multifd" ,"true" );migrate_set_capability (to,"multifd" ,"true" );
@@ -1306,6 +1308,11 @@ static void test_multifd_tcp(void)g_free (uri); } +static void test_multifd_tcp_none (void ) +{ +test_multifd_tcp ("none" ); +} +/* * This test does: * source target
@@ -1317,7 +1324,6 @@ static void test_multifd_tcp(void)* * And see that it works */ -static void test_multifd_tcp_cancel (void ) {MigrateStart *args =migrate_start_new ();
@@ -1467,7 +1473,7 @@ int main(int argc, char **argv) test_validate_uuid_dst_not_set);qtest_add_func ("/migration/auto_converge" , test_migrate_auto_converge); -qtest_add_func ("/migration/multifd/tcp" , test_multifd_tcp); +qtest_add_func ("/migration/multifd/tcp/none" , test_multifd_tcp_none);qtest_add_func ("/migration/multifd/tcp/cancel" , test_multifd_tcp_cancel); ret =g_test_run ();
Signature · 1 line
2.24.1
Re: [PATCH v5 1/8] multifd: Add multifd-method parameter
Quoted 4 lines · Juan Quintela
This will store the compression method to use. We start with none.
Signed-off-by Juan Quintela <[email protected]>Reviewed-by Markus Armbruster <[email protected]>
I don't remember giving my R-by. I gave my Acked-by for [PATCH v2 06/10] migration: Add multifd-compress parameter
Message-ID: <[email protected]>
https://lists.nongnu.org/archive/html/qemu-devel/2019-12/msg04153.html
If I did give my R-by for a later revision, let me know.
One small suggestion below.
Quoted 1 line
Reviewed-by Dr. David Alan Gilbert <[email protected]>
[...]
qapi/migration.json line 494
Quoted 12 lines
qapi/migration.json +4
-0@@ -488,6 +488,19 @@ ## { 'command': 'query-migrate-capabilities', 'returns': ['MigrationCapabilityStatus']} +## +# @MultiFDMethod: +# +# An enumeration of multifd compression.
Suggest "compression methods."
Quoted 71 lines
qapi/migration.json +23
-3+# +# @none: no compression. +# +# Since: 5.0 +# +## +{ 'enum': 'MultiFDMethod', + 'data': [ 'none' ] } + ## # @MigrationParameter: #@@ -586,6 +599,9 @@ # @max-cpu-throttle: maximum cpu throttle percentage. # Defaults to 99. (Since 3.1) # +# @multifd-method: Which compression method to use. +# Defaults to none. (Since 5.0) +# # Since: 2.4 ## { 'enum': 'MigrationParameter',@@ -598,7 +614,7 @@ 'downtime-limit', 'x-checkpoint-delay', 'block-incremental', 'multifd-channels', 'xbzrle-cache-size', 'max-postcopy-bandwidth', - 'max-cpu-throttle' ] } + 'max-cpu-throttle', 'multifd-method' ] } ## # @MigrateSetParameters:@@ -688,6 +704,9 @@ # @max-cpu-throttle: maximum cpu throttle percentage. # The default value is 99. (Since 3.1) # +# @multifd-method: Which compression method to use. +# Defaults to none. (Since 5.0) +# # Since: 2.4 ## # TODO either fuse back into MigrationParameters, or make@@ -713,7 +732,8 @@ '*multifd-channels': 'int', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle': 'int' } } + '*max-cpu-throttle': 'int', + '*multifd-method': 'MultiFDMethod' } } ## # @migrate-set-parameters:@@ -823,6 +843,9 @@ # Defaults to 99. # (Since 3.1) # +# @multifd-method: Which compression method to use. +# Defaults to none. (Since 5.0) +# # Since: 2.4 ## { 'struct': 'MigrationParameters',@@ -846,7 +869,8 @@ '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle':'uint8'} } + '*max-cpu-throttle': 'uint8', + '*multifd-method': 'MultiFDMethod' } } ## # @query-migrate-parameters:
[...]
Re: [PATCH v5 1/8] multifd: Add multifd-method parameter
Quoted 7 lines · Markus Armbruster
Quoted 4 lines · Juan Quintela
This will store the compression method to use. We start with none.
Signed-off-by Juan Quintela <[email protected]>Reviewed-by Markus Armbruster <[email protected]>
Quoted 6 lines
I don't remember giving my R-by. I gave my Acked-by for [PATCH v2 06/10] migration: Add multifd-compress parameter
Message-ID: <[email protected]>
https://lists.nongnu.org/archive/html/qemu-devel/2019-12/msg04153.htmlIf I did give my R-by for a later revision, let me know.
Hi
Ouch, I *thought* that you got confused. It happens to me all the time. Apologies.
So, how I should I put that Acked-by: in the commit?
Quoted 1 line
One small suggestion below.
Thanks.
Quoted 11 lines
Quoted 1 line
Reviewed-by Dr. David Alan Gilbert <[email protected]>[...]
Quoted 9 lines
qapi/migration.json +0
-0@@ -488,6 +488,19 @@ ## { 'command': 'query-migrate-capabilities', 'returns': ['MigrationCapabilityStatus']}
Quoted 6 lines
qapi/migration.json line 494
Quoted 4 lines
qapi/migration.json +4
-0+## +# @MultiFDMethod: +# +# An enumeration of multifd compression.Suggest "compression methods."
will do.
Sorry again for the missunderstanding.
Later, Juan.
Re: [PATCH v5 1/8] multifd: Add multifd-method parameter
Quoted 13 lines · Juan Quintela
Quoted 11 lines · Markus Armbruster
Quoted 4 lines · Juan Quintela
This will store the compression method to use. We start with none.
Signed-off-by Juan Quintela <[email protected]>Reviewed-by Markus Armbruster <[email protected]>I don't remember giving my R-by. I gave my Acked-by for [PATCH v2 06/10] migration: Add multifd-compress parameter
Message-ID: <[email protected]>
https://lists.nongnu.org/archive/html/qemu-devel/2019-12/msg04153.html
Quoted 7 lines
Quoted 1 line
If I did give my R-by for a later revision, let me know.
Hi
Ouch, I *thought* that you got confused. It happens to me all the time. Apologies.
So, how I should I put that Acked-by: in the commit?
Replace
by
Quoted 22 lines
Quoted 1 line
One small suggestion below.
Thanks.
Quoted 11 lines
Quoted 1 line
Reviewed-by Dr. David Alan Gilbert <[email protected]>[...]
Quoted 9 lines
qapi/migration.json +0
-0@@ -488,6 +488,19 @@ ## { 'command': 'query-migrate-capabilities', 'returns': ['MigrationCapabilityStatus']}Quoted 6 lines
qapi/migration.json line 494
Quoted 4 lines
qapi/migration.json +4
-0+## +# @MultiFDMethod: +# +# An enumeration of multifd compression.Suggest "compression methods."
Quoted 3 lines
will do.
Sorry again for the missunderstanding.
No harm, no foul :)
Re: [PATCH v5 1/8] multifd: Add multifd-method parameter
In reply to Juan QuintelaQuoted 26 lines · Juan Quintela
This will store the compression method to use. We start with none.
Signed-off-by Juan Quintela <[email protected]>Reviewed-by Markus Armbruster <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- hw/core/qdev-properties.c | 13 +++++++++++++ include/hw/qdev-properties.h | 3 +++ migration/migration.c | 13 +++++++++++++ monitor/hmp-cmds.c | 13 +++++++++++++ qapi/migration.json | 30 +++++++++++++++++++++++++++--- tests/qtest/migration-test.c | 14 ++++++++++---- 6 files changed, 79 insertions(+), 7 deletions(-)hw/core/qdev-properties.c +2
-0@@ -8,6 +8,7 @@@@ -488,6 +488,19 @@ ## { 'command': 'query-migrate-capabilities', 'returns': ['MigrationCapabilityStatus']} +## +# @MultiFDMethod:
hw/core/qdev-properties.c line 502
Quoted 10 lines
hw/core/qdev-properties.c +10
-0+# +# An enumeration of multifd compression. +# +# @none: no compression. +# +# Since : 5.0 +# +## +{ 'enum': 'MultiFDMethod', + 'data': [ 'none' ] }
I feel like "MultiFDMethod" is better called "MultiFDCompression"
Quoted 34 lines
hw/core/qdev-properties.c +8
-1+ ## # @MigrationParameter: #@@ -586,6 +599,9 @@ # @max-cpu-throttle: maximum cpu throttle percentage.# Defaults to 99. (Since 3.1) # +# @multifd-method: Which compression method to use. +# Defaults to none. (Since 5.0) +## Since : 2.4 ## { 'enum': 'MigrationParameter',@@ -598,7 +614,7 @@'downtime-limit' ,'x-checkpoint-delay' ,'block-incremental' ,'multifd-channels' ,'xbzrle-cache-size' ,'max-postcopy-bandwidth' , - 'max-cpu-throttle' ] } + 'max-cpu-throttle', 'multifd-method' ] } ## # @MigrateSetParameters:@@ -688,6 +704,9 @@ # @max-cpu-throttle: maximum cpu throttle percentage.# The default value is 99. (Since 3.1) # +# @multifd-method: Which compression method to use. +# Defaults to none. (Since 5.0) +## Since : 2.4 ### TODO either fuse back into MigrationParameters, or make
hw/core/qdev-properties.c line 736
Quoted 6 lines
hw/core/qdev-properties.c +2
-1@@ -713,7 +732,8 @@ '*multifd-channels': 'int', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle': 'int' } } + '*max-cpu-throttle': 'int', + '*multifd-method': 'MultiFDMethod' } }
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v5 1/8] multifd: Add multifd-method parameter
Quoted 25 lines · Daniel P. Berrangé
Quoted 24 lines · Juan Quintela
This will store the compression method to use. We start with none.
Signed-off-by Juan Quintela <[email protected]>Reviewed-by Markus Armbruster <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- hw/core/qdev-properties.c | 13 +++++++++++++ include/hw/qdev-properties.h | 3 +++ migration/migration.c | 13 +++++++++++++ monitor/hmp-cmds.c | 13 +++++++++++++ qapi/migration.json | 30 +++++++++++++++++++++++++++--- tests/qtest/migration-test.c | 14 ++++++++++---- 6 files changed, 79 insertions(+), 7 deletions(-)hw/core/qdev-properties.c +0
-0@@ -8,6 +8,7 @@@@ -488,6 +488,19 @@ ## { 'command': 'query-migrate-capabilities', 'returns': ['MigrationCapabilityStatus']}
Quoted 14 lines
hw/core/qdev-properties.c line 502
Quoted 12 lines
hw/core/qdev-properties.c +12
-0+## +# @MultiFDMethod: +# +# An enumeration of multifd compression. +# +# @none: no compression. +# +# Since : 5.0 +# +## +{ 'enum': 'MultiFDMethod', + 'data': [ 'none' ] }I feel like "MultiFDMethod" is better called "MultiFDCompression"
Changed.
Thanks, Juan.
PATCH v5 2/8 migration: Add support for modules
In reply to Juan QuintelaSo we don't have to compile everything in, or have ifdefs
--- include/qemu/module.h | 2 ++ vl.c | 1 + 2 files changed, 3 insertions(+)
include/qemu/module.h +2 -0
@@ -40,6 +40,7 @@ static void __attribute__((constructor)) do_qemu_init_ ## function(void) \#endif typedef enum { + MODULE_INIT_MIGRATION, MODULE_INIT_BLOCK, MODULE_INIT_OPTS, MODULE_INIT_QOM,
@@ -56,6 +57,7 @@ typedef enum {#define xen_backend_init (function) module_init(function, \ MODULE_INIT_XEN_BACKEND)#define libqos_init (function) module_init(function, MODULE_INIT_LIBQOS) +#define migration_init (function) module_init(function, MODULE_INIT_MIGRATION)#define block_module_load_one (lib) module_load_one("block-", lib)#define ui_module_load_one (lib) module_load_one("ui-", lib)
vl.c +1 -0
@@ -2890,6 +2890,7 @@ int main(int argc, char **argv, char **envp)qemu_init_exec_dir (argv[0 ]);module_call_init (MODULE_INIT_QOM ); +module_call_init (MODULE_INIT_MIGRATION );qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);
Signature · 1 line
2.24.1
Re: [PATCH v5 2/8] migration: Add support for modules
Quoted 3 lines · * Juan Quintela ([email protected]) wrote:
So we don't have to compile everything in, or have ifdefs
Signed-off-by Juan Quintela <[email protected]>
As far as I can tell this matches the way all the rest of the module stuff works, so:
(Although I wish it was documented somewhere).
Dave
Quoted 40 lines
--- include/qemu/module.h | 2 ++ vl.c | 1 + 2 files changed, 3 insertions(+)include/qemu/module.h +2
-0@@ -40,6 +40,7 @@ static void __attribute__((constructor)) do_qemu_init_ ## function(void) \#endif typedef enum { + MODULE_INIT_MIGRATION, MODULE_INIT_BLOCK, MODULE_INIT_OPTS, MODULE_INIT_QOM,@@ -56,6 +57,7 @@ typedef enum {#define xen_backend_init (function) module_init(function, \ MODULE_INIT_XEN_BACKEND)#define libqos_init (function) module_init(function, MODULE_INIT_LIBQOS) +#define migration_init (function) module_init(function, MODULE_INIT_MIGRATION)#define block_module_load_one (lib) module_load_one("block-", lib)#define ui_module_load_one (lib) module_load_one("ui-", lib)vl.c +1
-0@@ -2890,6 +2890,7 @@ int main(int argc, char **argv, char **envp)qemu_init_exec_dir (argv[0 ]);module_call_init (MODULE_INIT_QOM ); +module_call_init (MODULE_INIT_MIGRATION );qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);Signature · 1 line
2.24.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH v5 2/8] migration: Add support for modules
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Juan Quintela ([email protected]) wrote:
So we don't have to compile everything in, or have ifdefs
Signed-off-by Juan Quintela <[email protected]>As far as I can tell this matches the way all the rest of the module stuff works, so:
Reviewed-by Dr. David Alan Gilbert <[email protected]>
Thanks
Quoted 1 line
(Although I wish it was documented somewhere).
I had to learn to use it with grep :-p
PATCH v5 3/8 multifd: Make no compression operations into its own structure
In reply to Juan QuintelaIt will be used later.
--- migration/migration.c | 9 ++ migration/migration.h | 1 + migration/multifd.c | 185 ++++++++++++++++++++++++++++++++++++++++-- migration/multifd.h | 25 ++++++ migration/ram.c | 1 + 5 files changed, 213 insertions(+), 8 deletions(-)
migration/migration.c +9 -0
@@ -2245,6 +2245,15 @@ int migrate_multifd_channels(void)return s->parameters.multifd_channels; } +MultiFDMethod migrate_multifd_method (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->parameters.multifd_method; +} +int migrate_use_xbzrle (void ) {MigrationState *s;
migration/migration.h +1 -0
@@ -300,6 +300,7 @@ bool migrate_auto_converge(void);bool migrate_use_multifd (void );bool migrate_pause_before_switchover (void );int migrate_multifd_channels (void ); +MultiFDMethod migrate_multifd_method (void );int migrate_use_xbzrle (void );int64_t migrate_xbzrle_cache_size (void );
migration/multifd.c +177 -8
284 lines not on this page · raw message
migration/multifd.h +25 -0
@@ -25,6 +25,10 @@ int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);#define MULTIFD_FLAG_SYNC (1 << 0) +/* We reserve 3 bits for METHODS */ +#define MULTIFD_FLAG_METHOD_MASK (7 << 1) +#define MULTIFD_FLAG_NOCOMP (1 << 1) +/* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024)
@@ -96,6 +100,8 @@ typedef struct {uint64_t num_pages;/* syncs main thread and channels */ QemuSemaphore sem_sync; +/* used for compression methods */ +void *data; } MultiFDSendParams; typedef struct {
@@ -133,7 +139,26 @@ typedef struct {uint64_t num_pages;/* syncs main thread and channels */ QemuSemaphore sem_sync; +/* used for de-compression methods */ +void *data; } MultiFDRecvParams; +typedef struct { +/* Setup for sending side */ +int (*send_setup)(MultiFDSendParams *p,Error **errp); +/* Cleanup for sending side */ +void (*send_cleanup)(MultiFDSendParams *p,Error **errp); +/* Prepare the send packet */ +int (*send_prepare)(MultiFDSendParams *p,uint32_t used,Error **errp); +/* Write the send packet */ +int (*send_write)(MultiFDSendParams *p,uint32_t used,Error **errp); +/* Setup for receiving side */ +int (*recv_setup)(MultiFDRecvParams *p,Error **errp); +/* Cleanup for receiving side */ +void (*recv_cleanup)(MultiFDRecvParams *p); +/* Read all pages */ +int (*recv_pages)(MultiFDRecvParams *p,uint32_t used,Error **errp); +}MultiFDMethods ; +#endif
migration/ram.c +1 -0
@@ -43,6 +43,7 @@#include "page_cache.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "qapi/qapi-types-migration.h" #include "qapi/qapi-events-migration.h" #include "qapi/qmp/qerror.h" #include "trace.h"
Signature · 1 line
2.24.1
Re: [PATCH v5 3/8] multifd: Make no compression operations into its own structure
Quoted 9 lines · * Juan Quintela ([email protected]) wrote:
It will be used later.
Signed-off-by Juan Quintela <[email protected]>migration/multifd.h +0
-0
migration/multifd.h int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset); · line 31
Quoted 7 lines
migration/multifd.h +4
-0@@ -25,6 +25,10 @@ int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);#define MULTIFD_FLAG_SYNC (1 << 0) +/* We reserve 3 bits for METHODS */ +#define MULTIFD_FLAG_METHOD_MASK (7 << 1) +#define MULTIFD_FLAG_NOCOMP (1 << 1) +
Doesn't the 'NOCOMP' value have to be 0 for it to not break compatibility with existing multifd?
Dave
Quoted 54 lines
migration/multifd.h +21
-0/* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024)@@ -96,6 +100,8 @@ typedef struct {uint64_t num_pages;/* syncs main thread and channels */ QemuSemaphore sem_sync; +/* used for compression methods */ +void *data; } MultiFDSendParams; typedef struct {@@ -133,7 +139,26 @@ typedef struct {uint64_t num_pages;/* syncs main thread and channels */ QemuSemaphore sem_sync; +/* used for de-compression methods */ +void *data; } MultiFDRecvParams; +typedef struct { +/* Setup for sending side */ +int (*send_setup)(MultiFDSendParams *p,Error **errp); +/* Cleanup for sending side */ +void (*send_cleanup)(MultiFDSendParams *p,Error **errp); +/* Prepare the send packet */ +int (*send_prepare)(MultiFDSendParams *p,uint32_t used,Error **errp); +/* Write the send packet */ +int (*send_write)(MultiFDSendParams *p,uint32_t used,Error **errp); +/* Setup for receiving side */ +int (*recv_setup)(MultiFDRecvParams *p,Error **errp); +/* Cleanup for receiving side */ +void (*recv_cleanup)(MultiFDRecvParams *p); +/* Read all pages */ +int (*recv_pages)(MultiFDRecvParams *p,uint32_t used,Error **errp); +}MultiFDMethods ; +#endif migration/ram.c +1
-0@@ -43,6 +43,7 @@#include "page_cache.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "qapi/qapi-types-migration.h" #include "qapi/qapi-events-migration.h" #include "qapi/qmp/qerror.h" #include "trace.h" Signature · 1 line
2.24.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH v5 3/8] multifd: Make no compression operations into its own structure
Quoted 13 lines · Dr. David Alan Gilbert
Quoted 12 lines · * Juan Quintela ([email protected]) wrote:
It will be used later.
Signed-off-by Juan Quintela <[email protected]>migration/multifd.h +0
-0@@ -25,6 +25,10 @@ int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);#define MULTIFD_FLAG_SYNC (1 << 0)
Quoted 7 lines
migration/multifd.h int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset); · line 31
Quoted 4 lines
migration/multifd.h +4
-0+/* We reserve 3 bits for METHODS */ +#define MULTIFD_FLAG_METHOD_MASK (7 << 1) +#define MULTIFD_FLAG_NOCOMP (1 << 1) +Doesn't the 'NOCOMP' value have to be 0 for it to not break compatibility with existing multifd?
You are right. fixing on next resend.
Thanks.
PATCH v5 4/8 multifd: Add multifd-zlib-level parameter
In reply to Juan QuintelaIt will indicate which level use for compression.
--- migration/migration.c | 15 +++++++++++++++ monitor/hmp-cmds.c | 4 ++++ qapi/migration.json | 30 +++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 3 deletions(-)
migration/migration.c +15 -0
@@ -89,6 +89,8 @@#define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY (200 * 100)#define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2#define DEFAULT_MIGRATE_MULTIFD_METHOD MULTIFD_METHOD_NONE +/*0: means nocompress, 1: best speed, ... 9: best compress ratio */ +#define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1/* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit.
@@ -801,6 +803,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->multifd_channels = s->parameters.multifd_channels; params->has_multifd_method = true; params->multifd_method = s->parameters.multifd_method; + params->has_multifd_zlib_level = true; + params->multifd_zlib_level = s->parameters.multifd_zlib_level; params->has_xbzrle_cache_size = true; params->xbzrle_cache_size = s->parameters.xbzrle_cache_size; params->has_max_postcopy_bandwidth = true;
@@ -1208,6 +1212,13 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)return false; } +if (params->has_multifd_zlib_level && + (params->multifd_zlib_level >9 )) { +error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"multifd_zlib_level" , +"is invalid, it should be in the range of 0 to 9" ); +return false; + } +if (params->has_xbzrle_cache_size && (params->xbzrle_cache_size <qemu_target_page_size () || !is_power_of_2 (params->xbzrle_cache_size))) {
@@ -3536,6 +3547,9 @@ static Property migration_properties[] = {DEFINE_PROP_MULTIFD_METHOD ("multifd-method" , MigrationState, parameters.multifd_method,DEFAULT_MIGRATE_MULTIFD_METHOD ), +DEFINE_PROP_UINT8 ("multifd-zlib-level" , MigrationState, + parameters.multifd_zlib_level, +DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL ),DEFINE_PROP_SIZE ("xbzrle-cache-size" , MigrationState, parameters.xbzrle_cache_size, DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),
@@ -3627,6 +3641,7 @@ static void migration_instance_init(Object *obj) params->has_block_incremental = true; params->has_multifd_channels = true; params->has_multifd_method = true; + params->has_multifd_zlib_level = true; params->has_xbzrle_cache_size = true; params->has_max_postcopy_bandwidth = true; params->has_max_cpu_throttle = true;
monitor/hmp-cmds.c +4 -0
@@ -1836,6 +1836,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) } p->multifd_method = compress_type;break ; +case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL : + p->has_multifd_zlib_level = true; +visit_type_int (v, param, &p->multifd_zlib_level, &err); +break ;case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE : p->has_xbzrle_cache_size = true;visit_type_size (v, param, &cache_size, &err);
qapi/migration.json +27 -3
@@ -602,6 +602,13 @@ # @multifd-method: Which compression method to use. # Defaults to none. (Since 5.0) # +# @multifd-zlib-level: Set the compression level to be used in live +# migration, the compression level is an integer between 0 +# and 9, where 0 means no compression, 1 means the best +# compression speed, and 9 means best compression ratio which +# will consume more CPU. +# Defaults to 1. (Since 5.0) +# # Since: 2.4 ## { 'enum': 'MigrationParameter',
@@ -614,7 +621,8 @@ 'downtime-limit', 'x-checkpoint-delay', 'block-incremental', 'multifd-channels', 'xbzrle-cache-size', 'max-postcopy-bandwidth', - 'max-cpu-throttle', 'multifd-method' ] } + 'max-cpu-throttle', 'multifd-method', + 'multifd-zlib-level' ] } ## # @MigrateSetParameters:
@@ -707,6 +715,13 @@ # @multifd-method: Which compression method to use. # Defaults to none. (Since 5.0) # +# @multifd-zlib-level: Set the compression level to be used in live +# migration, the compression level is an integer between 0 +# and 9, where 0 means no compression, 1 means the best +# compression speed, and 9 means best compression ratio which +# will consume more CPU. +# Defaults to 1. (Since 5.0) +# # Since: 2.4 ## # TODO either fuse back into MigrationParameters, or make
@@ -733,7 +748,8 @@ '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', '*max-cpu-throttle': 'int', - '*multifd-method': 'MultiFDMethod' } } + '*multifd-method': 'MultiFDMethod', + '*multifd-zlib-level': 'int' } } ## # @migrate-set-parameters:
@@ -846,6 +862,13 @@ # @multifd-method: Which compression method to use. # Defaults to none. (Since 5.0) # +# @multifd-zlib-level: Set the compression level to be used in live +# migration, the compression level is an integer between 0 +# and 9, where 0 means no compression, 1 means the best +# compression speed, and 9 means best compression ratio which +# will consume more CPU. +# Defaults to 1. (Since 5.0) +# # Since: 2.4 ## { 'struct': 'MigrationParameters',
@@ -870,7 +893,8 @@ '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', '*max-cpu-throttle': 'uint8', - '*multifd-method': 'MultiFDMethod' } } + '*multifd-method': 'MultiFDMethod', + '*multifd-zlib-level': 'uint8' } } ## # @query-migrate-parameters:
Signature · 1 line
2.24.1
Re: [PATCH v5 4/8] multifd: Add multifd-zlib-level parameter
Quoted 3 lines · Juan Quintela
It will indicate which level use for compression.
Signed-off-by Juan Quintela <[email protected]>
This is slightly confusing (there is no zlib compression), unless you peek at the next patch (which adds zlib compression).
Three ways to make it less confusing:
* Squash the two commits
* Swap them: first add zlib compression with level hardcoded to 1, then make the level configurable.
* Have the first commit explain itself better. Something like
multifd: Add multifd-zlib-level parameter
This parameter specifies zlib compression level. The next patch will put it to use.
For QAPI:
Re: [PATCH v5 4/8] multifd: Add multifd-zlib-level parameter
Quoted 4 lines · Markus Armbruster
Quoted 2 lines · Juan Quintela
It will indicate which level use for compression.
Quoted 8 lines
Quoted 1 line
Signed-off-by Juan Quintela <[email protected]>This is slightly confusing (there is no zlib compression), unless you peek at the next patch (which adds zlib compression).
Three ways to make it less confusing:
* Squash the two commits
As a QAPI begginer, I feel it easier to put it in a different patch. It makes it also easier to add other parameters, just copy whatewer is here.
Quoted 2 lines
* Swap them: first add zlib compression with level hardcoded to 1, then make the level configurable.
That could work.
Quoted 6 lines
* Have the first commit explain itself better. Something like
multifd: Add multifd-zlib-level parameter
This parameter specifies zlib compression level. The next patch will put it to use.
Will take this approach.
The reason that I put the qapi bits first is that I *know* how to do them. Once that I got approval for how to add one parameter, I add the rest exactly the same.
For the rest of the patch, it needs to be developed, and normally needs more iterations.
Quoted 3 lines
For QAPI:
Thanks very much.
Later, Juan.
Re: [PATCH v5 4/8] multifd: Add multifd-zlib-level parameter
In reply to Markus ArmbrusterQuoted 16 lines · Markus Armbruster
Quoted 3 lines · Juan Quintela
It will indicate which level use for compression.
Signed-off-by Juan Quintela <[email protected]>This is slightly confusing (there is no zlib compression), unless you peek at the next patch (which adds zlib compression).
Three ways to make it less confusing:
* Squash the two commits
* Swap them: first add zlib compression with level hardcoded to 1, then make the level configurable.
Quoted 6 lines
* Have the first commit explain itself better. Something like
multifd: Add multifd-zlib-level parameter
This parameter specifies zlib compression level. The next patch will put it to use.
Wouldn't the "normal" best practice for QAPI design be to use a enum and discriminated union. eg
{ 'enum': 'MigrationCompression',
'data': ['none', 'zlib'] }
{ 'struct': 'MigrationCompressionParamsZLib',
'data': { 'compression-level' } } { 'union': 'MigrationCompressionParams',
'base': { 'mode': 'MigrationCompression' },
'discriminator': 'mode',
'data': {
'zlib': 'MigrationCompressionParamsZLib',
}Of course this is quite different from how migration parameters are done today. Maybe it makes sense to stick with the flat list of migration parameters for consistency & ignore normal QAPI design practice ?
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v5 4/8] multifd: Add multifd-zlib-level parameter
Quoted 31 lines · Daniel P. Berrangé
Quoted 16 lines · Markus Armbruster
Quoted 3 lines · Juan Quintela
It will indicate which level use for compression.
Signed-off-by Juan Quintela <[email protected]>This is slightly confusing (there is no zlib compression), unless you peek at the next patch (which adds zlib compression).
Three ways to make it less confusing:
* Squash the two commits
* Swap them: first add zlib compression with level hardcoded to 1, then make the level configurable.
Quoted 6 lines
* Have the first commit explain itself better. Something like
multifd: Add multifd-zlib-level parameter
This parameter specifies zlib compression level. The next patch will put it to use.
Wouldn't the "normal" best practice for QAPI design be to use a enum and discriminated union. eg
{ 'enum': 'MigrationCompression',
'data': ['none', 'zlib'] }{ 'struct': 'MigrationCompressionParamsZLib',
Quoted 8 lines
'data': { 'compression-level' } }{ 'union': 'MigrationCompressionParams', 'base': { 'mode': 'MigrationCompression' }, 'discriminator': 'mode', 'data': { 'zlib': 'MigrationCompressionParamsZLib', }
This expresses the connection between compression mode and level. In general, we prefer that to a bunch of optional members where the comments say things like "member A can be present only when member B has value V", or worse "member A is silently ignored unless member B has value V". However:
Quoted 4 lines
Of course this is quite different from how migration parameters are done today. Maybe it makes sense to stick with the flat list of migration parameters for consistency & ignore normal QAPI design practice ?
Unsure. It's certainly ugly now. Each parameter is defined in three
places: enum MigrationParameter (for HMP), struct MigrateSetParameters (for QMP migrate-set-parameters), and struct MigrationParameters (for QMP query-migrate-parameters).
I don't know how to make this better other than by starting over. I don't know whether starting over would result in enough of an improvement to make it worthwhile.
Re: [PATCH v5 4/8] multifd: Add multifd-zlib-level parameter
In reply to Daniel P. BerrangéQuoted 31 lines · Daniel P. Berrangé
Quoted 16 lines · Markus Armbruster
Quoted 3 lines · Juan Quintela
It will indicate which level use for compression.
Signed-off-by Juan Quintela <[email protected]>This is slightly confusing (there is no zlib compression), unless you peek at the next patch (which adds zlib compression).
Three ways to make it less confusing:
* Squash the two commits
* Swap them: first add zlib compression with level hardcoded to 1, then make the level configurable.
Quoted 6 lines
* Have the first commit explain itself better. Something like
multifd: Add multifd-zlib-level parameter
This parameter specifies zlib compression level. The next patch will put it to use.
Wouldn't the "normal" best practice for QAPI design be to use a enum and discriminated union. eg
{ 'enum': 'MigrationCompression',
'data': ['none', 'zlib'] }{ 'struct': 'MigrationCompressionParamsZLib',
Quoted 8 lines
'data': { 'compression-level' } }{ 'union': 'MigrationCompressionParams', 'base': { 'mode': 'MigrationCompression' }, 'discriminator': 'mode', 'data': { 'zlib': 'MigrationCompressionParamsZLib', }
How is this translate into HMP?
Markus says to start over, so lets see the dependencies:
Announce: Allawys there
announce-initial
announce-max
announce-rounds
announce-step
Osd compression (deprecated)
compress-level
compress-threads
compress-wait-thread
decompress-threads
cpu-throttles-initial
cpu-throottle-incroment
max-cpu-throotle
tls-creds
tls-hostname
tls-auth
Real params
max-bandwidth
downtime-limit
colo
x-checkpoint-delay
block-incremental
multifd-channels
xbzrle-cache-size
max-postcopy-bandwidth
New things:
- multifd method
- multifd-zlib-level
- multifd-zstd-level
What is a good way to define them?
Why do I ask, because the current method is as bad as it can be. To add a new parameter:
- for qapi, add it in three places (as Markus said)
- go to hmp-cmds.c and do things by hand
- qemu_migrate_set_parameters
- migrate_params_check
- migrate_params_apply
(last three functions are almost identical in structure, not in content).
So, if you can give me something that is _easier_ of maintaining, I am all ears.
Later, Juan.
Quoted 9 lines
Of course this is quite different from how migration parameters are done today. Maybe it makes sense to stick with the flat list of migration parameters for consistency & ignore normal QAPI design practice ?
Regards,
Daniel
PATCH v5 5/8 multifd: Add zlib compression multifd support
In reply to Juan Quintela--- hw/core/qdev-properties.c | 2 +- migration/Makefile.objs | 1 + migration/migration.c | 9 + migration/migration.h | 1 + migration/multifd-zlib.c | 325 +++++++++++++++++++++++++++++++++++ migration/multifd.c | 6 + migration/multifd.h | 4 + qapi/migration.json | 3 +- tests/qtest/migration-test.c | 6 + 9 files changed, 355 insertions(+), 2 deletions(-) create mode 100644 migration/multifd-zlib.c
hw/core/qdev-properties.c +1 -1
@@ -645,7 +645,7 @@ const PropertyInfo qdev_prop_fdc_drive_type = {const PropertyInfo qdev_prop_multifd_method = { .name ="MultiFDMethod" , .description ="multifd_method values, " -"none" , +"none/zlib" , .enum_table = &MultiFDMethod_lookup, .get = get_enum, .set = set_enum,
migration/Makefile.objs +1 -0
@@ -8,6 +8,7 @@ common-obj-y += xbzrle.o postcopy-ram.o common-obj-y += qjson.o common-obj-y += block-dirty-bitmap.o common-obj-y += multifd.o +common-obj-y += multifd-zlib.o common-obj-$(CONFIG_RDMA) += rdma.o
migration/migration.c +9 -0
@@ -2265,6 +2265,15 @@ MultiFDMethod migrate_multifd_method(void)return s->parameters.multifd_method; } +int migrate_multifd_zlib_level (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->parameters.multifd_zlib_level; +} +int migrate_use_xbzrle (void ) {MigrationState *s;
migration/migration.h +1 -0
@@ -301,6 +301,7 @@ bool migrate_use_multifd(void);bool migrate_pause_before_switchover (void );int migrate_multifd_channels (void );MultiFDMethod migrate_multifd_method (void ); +int migrate_multifd_zlib_level (void );int migrate_use_xbzrle (void );int64_t migrate_xbzrle_cache_size (void );
migration/multifd-zlib.c new file +325 -0
325 lines not on this page · raw message
migration/multifd.c +6 -0
@@ -166,6 +166,12 @@ static MultiFDMethods *multifd_ops[MULTIFD_METHOD__MAX] = { [MULTIFD_METHOD_NONE] = &multifd_nocomp_ops, }; +void multifd_register_ops (int method,MultiFDMethods *ops) +{ +assert (0 < method && method <MULTIFD_METHOD__MAX ); + multifd_ops[method] = ops; +} +static int multifd_send_initial_packet (MultiFDSendParams *p,Error **errp) {MultiFDInit_t msg = {};
migration/multifd.h +4 -0
@@ -23,11 +23,13 @@ void multifd_recv_sync_main(void);void multifd_send_sync_main (QEMUFile *f);int multifd_queue_page (QEMUFile *f,RAMBlock *block,ram_addr_t offset); +/* Multifd Compression flags */ #define MULTIFD_FLAG_SYNC (1 << 0)/* We reserve 3 bits for METHODS */ #define MULTIFD_FLAG_METHOD_MASK (7 << 1)#define MULTIFD_FLAG_NOCOMP (1 << 1) +#define MULTIFD_FLAG_ZLIB (2 << 1)/* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024)
@@ -160,5 +162,7 @@ typedef struct { int (*recv_pages)(MultiFDRecvParams *p, uint32_t used, Error **errp); } MultiFDMethods; +void multifd_register_ops (int method,MultiFDMethods *ops); +#endif
qapi/migration.json +2 -1
@@ -494,12 +494,13 @@ # An enumeration of multifd compression. # # @none: no compression. +# @zlib: use zlib compression method. # # Since: 5.0 # ## { 'enum': 'MultiFDMethod', - 'data': [ 'none' ] } + 'data': [ 'none', 'zlib' ] } ## # @MigrationParameter:
tests/qtest/migration-test.c +6 -0
@@ -1313,6 +1313,11 @@ static void test_multifd_tcp_none(void)test_multifd_tcp ("none" ); } +static void test_multifd_tcp_zlib (void ) +{ +test_multifd_tcp ("zlib" ); +} +/* * This test does: * source target
@@ -1475,6 +1480,7 @@ int main(int argc, char **argv)qtest_add_func ("/migration/auto_converge" , test_migrate_auto_converge);qtest_add_func ("/migration/multifd/tcp/none" , test_multifd_tcp_none);qtest_add_func ("/migration/multifd/tcp/cancel" , test_multifd_tcp_cancel); +qtest_add_func ("/migration/multifd/tcp/zlib" , test_multifd_tcp_zlib); ret =g_test_run ();
Signature · 1 line
2.24.1
Re: [PATCH v5 5/8] multifd: Add zlib compression multifd support
Quoted 1 line · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>
For QAPI:
Re: [PATCH v5 5/8] multifd: Add zlib compression multifd support
In reply to Juan QuintelaQuoted 13 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- hw/core/qdev-properties.c | 2 +- migration/Makefile.objs | 1 + migration/migration.c | 9 + migration/migration.h | 1 + migration/multifd-zlib.c | 325 +++++++++++++++++++++++++++++++++++ migration/multifd.c | 6 + migration/multifd.h | 4 + qapi/migration.json | 3 +- tests/qtest/migration-test.c | 6 + 9 files changed, 355 insertions(+), 2 deletions(-) create mode 100644 migration/multifd-zlib.c
Coupld of really minor points below to fix up, but other than those:
Quoted 32 lines
hw/core/qdev-properties.c +1
-1@@ -645,7 +645,7 @@ const PropertyInfo qdev_prop_fdc_drive_type = {const PropertyInfo qdev_prop_multifd_method = { .name ="MultiFDMethod" , .description ="multifd_method values, " -"none" , +"none/zlib" , .enum_table = &MultiFDMethod_lookup, .get = get_enum, .set = set_enum,migration/Makefile.objs +1
-0@@ -8,6 +8,7 @@ common-obj-y += xbzrle.o postcopy-ram.o common-obj-y += qjson.o common-obj-y += block-dirty-bitmap.o common-obj-y += multifd.o +common-obj-y += multifd-zlib.o common-obj-$(CONFIG_RDMA) += rdma.omigration/migration.c +0
-0@@ -2265,6 +2265,15 @@ MultiFDMethod migrate_multifd_method(void)return s->parameters.multifd_method; }
migration/migration.c MultiFDMethod migrate_multifd_method(void) · line 2276
Quoted 10 lines
migration/migration.c +9
-0+int migrate_multifd_zlib_level (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->parameters.multifd_zlib_level; +} +
Does this belong in the previous patch?
Quoted 282 lines
migration/migration.c +0
-0int migrate_use_xbzrle (void ) {MigrationState *s;migration/migration.h +1
-0@@ -301,6 +301,7 @@ bool migrate_use_multifd(void);bool migrate_pause_before_switchover (void );int migrate_multifd_channels (void );MultiFDMethod migrate_multifd_method (void ); +int migrate_multifd_zlib_level (void );int migrate_use_xbzrle (void );int64_t migrate_xbzrle_cache_size (void );migration/multifd-zlib.c new file +261
-0@@ -0,0 +1,325 @@ +/* +* Multifd zlib compression implementation +* +* Copyright (c) 2020 Red Hat Inc +* +* Authors: +* Juan Quintela <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include <zlib.h> +#include "qemu/rcu.h" +#include "exec/target_page.h" +#include "qapi/error.h" +#include "migration.h" +#include "trace.h" +#include "multifd.h" + +struct zlib_data { +/* stream for compression */ +z_stream zs; +/* compressed buffer */ +uint8_t *zbuff; +/* size of compressed buffer */ +uint32_t zbuff_len; +}; + +/* Multifd zlib compression */ + +/** +* zlib_send_setup: setup send side +* +* Setup each channel with zlib compression. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @errp: pointer to an error +*/ +static int zlib_send_setup (MultiFDSendParams *p,Error **errp) +{ +uint32_t page_count =MULTIFD_PACKET_SIZE /qemu_target_page_size (); +struct zlib_data *z =g_malloc0 (sizeof (struct zlib_data )); +z_stream *zs = &z->zs; + + zs->zalloc =Z_NULL ; + zs->zfree =Z_NULL ; + zs->opaque =Z_NULL ; +if (deflateInit (zs,migrate_multifd_zlib_level ()) !=Z_OK ) { +g_free (z); +error_setg (errp,"multifd %d: deflate init failed" , p->id); +return -1 ; + } +/* We will never have more than page_count pages */ + z->zbuff_len = page_count *qemu_target_page_size (); + z->zbuff_len *=2 ; + z->zbuff =g_try_malloc (z->zbuff_len); +if (!z->zbuff) { +deflateEnd (&z->zs); +g_free (z); +error_setg (errp,"multifd %d: out of memory for zbuff" , p->id); +return -1 ; + } + p->data = z; +return 0 ; +} + +/** +* zlib_send_cleanup: cleanup send side +* +* Close the channel and return memory. +* +* @p: Params for the channel that we are using +*/ +static void zlib_send_cleanup (MultiFDSendParams *p,Error **errp) +{ +struct zlib_data *z = p->data; + +deflateEnd (&z->zs); +g_free (z->zbuff); + z->zbuff =NULL ; +g_free (p->data); + p->data =NULL ; +} + +/** +* zlib_send_prepare: prepare date to be able to send +* +* Create a compressed buffer with all the pages that we are going to +* send. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @used: number of pages used +*/ +static int zlib_send_prepare (MultiFDSendParams *p,uint32_t used,Error **errp) +{ +struct iovec *iov = p->pages->iov; +struct zlib_data *z = p->data; +z_stream *zs = &z->zs; +uint32_t out_size =0 ; +int ret; +uint32_t i; + +for (i =0 ; i < used; i++) { +uint32_t available = z->zbuff_len - out_size; +int flush =Z_NO_FLUSH ; + +if (i == used -1 ) { + flush =Z_SYNC_FLUSH ; + } + + zs->avail_in = iov[i].iov_len; + zs->next_in = iov[i].iov_base; + + zs->avail_out = available; + zs->next_out = z->zbuff + out_size; + +/* +* Welcome to deflate semantics +* +* We need to loop while: +* - return is Z_OK +* - there are stuff to be compressed +* - there are output space free +*/ +do { + ret =deflate (zs, flush); + }while (ret ==Z_OK && zs->avail_in && zs->avail_out); +if (ret ==Z_OK && zs->avail_in) { +error_setg (errp,"multifd %d: deflate failed to compress all input" , + p->id); +return -1 ; + } +if (ret !=Z_OK ) { +error_setg (errp,"multifd %d: deflate returned %d instead of Z_OK" , + p->id, ret); +return -1 ; + } + out_size += available - zs->avail_out; + } + p->next_packet_size = out_size; + p->flags |=MULTIFD_FLAG_ZLIB ; + +return 0 ; +} + +/** +* zlib_send_write: do the actual write of the data +* +* Do the actual write of the comprresed buffer. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @used: number of pages used +* @errp: pointer to an error +*/ +static int zlib_send_write (MultiFDSendParams *p,uint32_t used,Error **errp) +{ +struct zlib_data *z = p->data; + +return qio_channel_write_all (p->c, (void *)z->zbuff, p->next_packet_size, + errp); +} + +/** +* zlib_recv_setup: setup receive side +* +* Create the compressed channel and buffer. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @errp: pointer to an error +*/ +static int zlib_recv_setup (MultiFDRecvParams *p,Error **errp) +{ +uint32_t page_count =MULTIFD_PACKET_SIZE /qemu_target_page_size (); +struct zlib_data *z =g_malloc0 (sizeof (struct zlib_data )); +z_stream *zs = &z->zs; + + p->data = z; + zs->zalloc =Z_NULL ; + zs->zfree =Z_NULL ; + zs->opaque =Z_NULL ; + zs->avail_in =0 ; + zs->next_in =Z_NULL ; +if (inflateInit (zs) !=Z_OK ) { +error_setg (errp,"multifd %d: inflate init failed" , p->id); +return -1 ; + } +/* We will never have more than page_count pages */ + z->zbuff_len = page_count *qemu_target_page_size (); +/* We know compression "could" use more space */ + z->zbuff_len *=2 ; + z->zbuff =g_try_malloc (z->zbuff_len); +if (!z->zbuff) { +inflateEnd (zs); +error_setg (errp,"multifd %d: out of memory for zbuff" , p->id); +return -1 ; + } +return 0 ; +} + +/** +* zlib_recv_cleanup: setup receive side +* +* For no compression this function does nothing. +* +* @p: Params for the channel that we are using +*/ +static void zlib_recv_cleanup (MultiFDRecvParams *p) +{ +struct zlib_data *z = p->data; + +inflateEnd (&z->zs); +g_free (z->zbuff); + z->zbuff =NULL ; +g_free (p->data); + p->data =NULL ; +} + +/** +* zlib_recv_pages: read the data from the channel into actual pages +* +* Read the compressed buffer, and uncompress it into the actual +* pages. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @used: number of pages used +* @errp: pointer to an error +*/ +static int zlib_recv_pages (MultiFDRecvParams *p,uint32_t used,Error **errp) +{ +struct zlib_data *z = p->data; +z_stream *zs = &z->zs; +uint32_t in_size = p->next_packet_size; +/* we measure the change of total_out */ +uint32_t out_size = zs->total_out; +uint32_t expected_size = used *qemu_target_page_size (); +uint32_t flags = p->flags &MULTIFD_FLAG_METHOD_MASK ; +int ret; +int i; + +if (flags !=MULTIFD_FLAG_ZLIB ) { +error_setg (errp,"multifd %d: flags received %x flags expected %x" , + p->id, flags,MULTIFD_FLAG_ZLIB ); +return -1 ; + } + ret =qio_channel_read_all (p->c, (void *)z->zbuff, in_size, errp); + +if (ret !=0 ) { +return ret; + }
migration/multifd-zlib.c line 271
Quoted 10 lines
migration/multifd-zlib.c new file +10
-0+ + zs->avail_in = in_size; + zs->next_in = z->zbuff; + +for (i =0 ; i < used; i++) { +struct iovec *iov = &p->pages->iov[i]; +int flush =Z_NO_FLUSH ; +unsigned long start = zs->total_out; + +if (i == used -1 ) {
Note an extra space there.
Quoted 143 lines
migration/multifd-zlib.c new file +54
-0+ flush =Z_SYNC_FLUSH ; + } + + zs->avail_out = iov->iov_len; + zs->next_out = iov->iov_base; + +/* +* Welcome to inflate semantics +* +* We need to loop while: +* - return is Z_OK +* - there are input available +* - we haven't completed a full page +*/ +do { + ret =inflate (zs, flush); + }while (ret ==Z_OK && zs->avail_in + && (zs->total_out - start) < iov->iov_len); +if (ret ==Z_OK && (zs->total_out - start) < iov->iov_len) { +error_setg (errp,"multifd %d: inflate generated too few output" , + p->id); +return -1 ; + } +if (ret !=Z_OK ) { +error_setg (errp,"multifd %d: inflate returned %d instead of Z_OK" , + p->id, ret); +return -1 ; + } + } + out_size = zs->total_out - out_size; +if (out_size != expected_size) { +error_setg (errp,"multifd %d: packet size received %d size expected %d" , + p->id, out_size, expected_size); +return -1 ; + } +return 0 ; +} + +static MultiFDMethods multifd_zlib_ops = { + .send_setup = zlib_send_setup, + .send_cleanup = zlib_send_cleanup, + .send_prepare = zlib_send_prepare, + .send_write = zlib_send_write, + .recv_setup = zlib_recv_setup, + .recv_cleanup = zlib_recv_cleanup, + .recv_pages = zlib_recv_pages +}; + +static void multifd_zlib_register (void ) +{ +multifd_register_ops (MULTIFD_METHOD_ZLIB , &multifd_zlib_ops); +} + +migration_init (multifd_zlib_register);migration/multifd.c +6
-0@@ -166,6 +166,12 @@ static MultiFDMethods *multifd_ops[MULTIFD_METHOD__MAX] = { [MULTIFD_METHOD_NONE] = &multifd_nocomp_ops, }; +void multifd_register_ops (int method,MultiFDMethods *ops) +{ +assert (0 < method && method <MULTIFD_METHOD__MAX ); + multifd_ops[method] = ops; +} +static int multifd_send_initial_packet (MultiFDSendParams *p,Error **errp) {MultiFDInit_t msg = {};migration/multifd.h +4
-0@@ -23,11 +23,13 @@ void multifd_recv_sync_main(void);void multifd_send_sync_main (QEMUFile *f);int multifd_queue_page (QEMUFile *f,RAMBlock *block,ram_addr_t offset); +/* Multifd Compression flags */ #define MULTIFD_FLAG_SYNC (1 << 0)/* We reserve 3 bits for METHODS */ #define MULTIFD_FLAG_METHOD_MASK (7 << 1)#define MULTIFD_FLAG_NOCOMP (1 << 1) +#define MULTIFD_FLAG_ZLIB (2 << 1)/* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024)@@ -160,5 +162,7 @@ typedef struct { int (*recv_pages)(MultiFDRecvParams *p, uint32_t used, Error **errp); } MultiFDMethods; +void multifd_register_ops (int method,MultiFDMethods *ops); +#endif qapi/migration.json +2
-1@@ -494,12 +494,13 @@ # An enumeration of multifd compression. # # @none: no compression. +# @zlib: use zlib compression method. # # Since: 5.0 # ## { 'enum': 'MultiFDMethod', - 'data': [ 'none' ] } + 'data': [ 'none', 'zlib' ] } ## # @MigrationParameter:tests/qtest/migration-test.c +6
-0@@ -1313,6 +1313,11 @@ static void test_multifd_tcp_none(void)test_multifd_tcp ("none" ); } +static void test_multifd_tcp_zlib (void ) +{ +test_multifd_tcp ("zlib" ); +} +/* * This test does: * source target @@ -1475,6 +1480,7 @@ int main(int argc, char **argv)qtest_add_func ("/migration/auto_converge" , test_migrate_auto_converge);qtest_add_func ("/migration/multifd/tcp/none" , test_multifd_tcp_none);qtest_add_func ("/migration/multifd/tcp/cancel" , test_multifd_tcp_cancel); +qtest_add_func ("/migration/multifd/tcp/zlib" , test_multifd_tcp_zlib); ret =g_test_run ();Signature · 1 line
2.24.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH v5 5/8] multifd: Add zlib compression multifd support
Quoted 22 lines · Dr. David Alan Gilbert
Quoted 13 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- hw/core/qdev-properties.c | 2 +- migration/Makefile.objs | 1 + migration/migration.c | 9 + migration/migration.h | 1 + migration/multifd-zlib.c | 325 +++++++++++++++++++++++++++++++++++ migration/multifd.c | 6 + migration/multifd.h | 4 + qapi/migration.json | 3 +- tests/qtest/migration-test.c | 6 + 9 files changed, 355 insertions(+), 2 deletions(-) create mode 100644 migration/multifd-zlib.cCoupld of really minor points below to fix up, but other than those:
Reviewed-by Dr. David Alan Gilbert <[email protected]>Quoted 2 lines
}
Quoted 11 lines
migration/migration.c MultiFDMethod migrate_multifd_method(void) · line 2276
Quoted 9 lines
migration/migration.c +9
-0+int migrate_multifd_zlib_level (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->parameters.multifd_zlib_level; +} +Does this belong in the previous patch?
It is used only here. Should not make any difference.
Anyways, changing it.
Quoted 11 lines
Quoted 11 lines
int
migrate_use_xbzrle(void){ MigrationState *s;migration/migration.h +0
-0@@ -301,6 +301,7 @@ bool migrate_use_multifd(void);bool migrate_pause_before_switchover (void );int migrate_multifd_channels (void );
Quoted 9 lines
migration/migration.h bool migrate_use_multifd(void);
Quoted 6 lines
migration/migration.h +5
-0MultiFDMethod migrate_multifd_method (void ); +int migrate_multifd_zlib_level (void ); +int flush =Z_NO_FLUSH ; +unsigned long start = zs->total_out; + +if (i == used -1 ) {Note an extra space there.
Fixed, thanks.
PATCH v5 6/8 configure: Enable test and libs for zstd
In reply to Juan Quintela--- configure | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
configure +30 -0
@@ -448,6 +448,7 @@ lzo="" snappy="" bzip2="" lzfse="" +zstd="" guest_agent="" guest_agent_with_vss="no" guest_agent_ntddscsi="no"
@@ -1343,6 +1344,10 @@ for opt do ;; --disable-lzfse) lzfse="no" ;; + --disable-zstd) zstd="no" + ;; + --enable-zstd) zstd="yes" + ;; --enable-guest-agent) guest_agent="yes" ;; --disable-guest-agent) guest_agent="no"
@@ -1795,6 +1800,8 @@ disabled with --disable-FEATURE, default is enabled if available: (for reading bzip2-compressed dmg images) lzfse support of lzfse compression library (for reading lzfse-compressed dmg images) + zstd support for zstd compression library + (for migration compression) seccomp seccomp support coroutine-pool coroutine freelist (better performance) glusterfs GlusterFS backend
@@ -2409,6 +2416,24 @@ EOF fi fi +########################################## +# zstd check + +if test "$zstd" != "no" ; then + if $pkg_config --exist libzstd ; then + zstd_cflags="$($pkg_config --cflags libzstd)" + zstd_libs="$($pkg_config --libs libzstd)" + LIBS="$zstd_libs $LIBS" + QEMU_CFLAGS="$QEMU_CFLAGS $zstd_cflags" + zstd="yes" + else + if test "$zstd" = "yes" ; then + feature_not_found "libzstd" "Install libzstd devel" + fi + zstd="no" + fi +fi + ########################################## # libseccomp check
@@ -6578,6 +6603,7 @@ echo "lzo support $lzo" echo "snappy support $snappy" echo "bzip2 support $bzip2" echo "lzfse support $lzfse" +echo "zstd support $zstd" echo "NUMA host support $numa" echo "libxml2 $libxml2" echo "tcmalloc support $tcmalloc"
@@ -7143,6 +7169,10 @@ if test "$lzfse" = "yes" ; then echo "LZFSE_LIBS=-llzfse" >> $config_host_mak fi +if test "$zstd" = "yes" ; then + echo "CONFIG_ZSTD=y" >> $config_host_mak +fi + if test "$libiscsi" = "yes" ; then echo "CONFIG_LIBISCSI=m" >> $config_host_mak echo "LIBISCSI_CFLAGS=$libiscsi_cflags" >> $config_host_mak
Signature · 1 line
2.24.1
Re: [PATCH v5 6/8] configure: Enable test and libs for zstd
Quoted 5 lines · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- configure | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
This is adding a new 3rd party library to QEMU that we've not previously built and so isn't included in any of our CI platforms.
This commit should be updating at least some of our CI platforms to request the libzstd library installation to get CI coverage for the latest patches in this series. Probably the docker files, the VM installs for FreeBSD at least, travis and gitlab CI.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v5 6/8] configure: Enable test and libs for zstd
Quoted 9 lines · Daniel P. Berrangé
Quoted 5 lines · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- configure | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)This is adding a new 3rd party library to QEMU that we've not previously built and so isn't included in any of our CI platforms.
Ok.
Learning how one does that.
Quoted 5 lines
This commit should be updating at least some of our CI platforms to request the libzstd library installation to get CI coverage for the latest patches in this series.
Probably the docker files,
I added it in all debian/centos/fedora files that zlib-dev or xen-dev
Quoted 1 line
the VM installs for FreeBSD at least,
A fast google finds that library is called "zstd" and that it includes the includes (put intended)
tests/vm/freebsd
Once there, include it in fedora
Quoted 1 line
travis and
I added it to .travis.yml
Quoted 1 line
gitlab CI.
gitlab-ci.yml (just when we compile x86_64-softmmu)
I have something like this, but net real clue how to test that I haven't broken anything:
commit 59d8694dfcfc3d5ef36bc72a5c02bedaa3a6a6ec
Author: Juan Quintela <[email protected]> Date: Thu Feb 13 22:06:16 2020 +0100
Use zstd packages
.gitlab-ci.yml +1 -0
@@ -21,6 +21,7 @@ build-system2: script: - apt-get install -y -qq libsdl2-dev libgcrypt-dev libbrlapi-dev libaio-dev libfdt-dev liblzo2-dev librdmacm-dev libibverbs-dev libibumad-dev + libzstd-dev - mkdir build - cd build - ../configure --enable-werror --target-list="tricore-softmmu unicore32-softmmu
.travis.yml +1 -0
@@ -48,6 +48,7 @@ addons: - libusb-1.0-0-dev - libvdeplug-dev - libvte-2.91-dev + - libzstd-dev - sparse - uuid-dev - gcovr
tests/docker/dockerfiles/centos7.docker +2 -1
@@ -33,6 +33,7 @@ ENV PACKAGES \ tar \ vte-devel \ xen-devel \ - zlib-devel + zlib-devel \ + libzstd-devel RUN yum install -y $PACKAGES RUN rpm -q $PACKAGES | sort > /packages.txt
tests/docker/dockerfiles/fedora-i386-cross.docker +2 -1
@@ -7,7 +7,8 @@ ENV PACKAGES \ gnutls-devel.i686 \ nettle-devel.i686 \ pixman-devel.i686 \ - zlib-devel.i686 + zlib-devel.i686 \ + libzstd-devel.i686 RUN dnf install -y $PACKAGES RUN rpm -q $PACKAGES | sort > /packages.txt
tests/docker/dockerfiles/fedora.docker +2 -1
@@ -92,7 +92,8 @@ ENV PACKAGES \ vte291-devel \ which \ xen-devel \ - zlib-devel + zlib-devel \ + libzstd-devel ENV QEMU_CONFIGURE_OPTS --python=/usr/bin/python3 RUN dnf install -y $PACKAGES
tests/docker/dockerfiles/ubuntu.docker +1 -0
@@ -58,6 +58,7 @@ ENV PACKAGES flex bison \ libvdeplug-dev \ libvte-2.91-dev \ libxen-dev \ + libzstd-dev \ make \ python3-yaml \ python3-sphinx \
tests/docker/dockerfiles/ubuntu1804.docker +1 -0
@@ -44,6 +44,7 @@ ENV PACKAGES flex bison \ libvdeplug-dev \ libvte-2.91-dev \ libxen-dev \ + libzstd-dev \ make \ python3-yaml \ python3-sphinx \
tests/vm/fedora +4 -1
@@ -53,7 +53,10 @@ class FedoraVM(basevm.BaseVM): # libs: audio '"pkgconfig(libpulse)"', '"pkgconfig(alsa)"', - ] + + # libs: migration + '"pkgconfig(libzstd)"', +] BUILD_SCRIPT = """ set -e;
tests/vm/freebsd +3 -0
@@ -55,6 +55,9 @@ class FreeBSDVM(basevm.BaseVM): # libs: opengl "libepoxy", "mesa-libs", + + # libs: migration + "zstd", ] BUILD_SCRIPT = """
tests/vm/netbsd +3 -0
@@ -49,6 +49,9 @@ class NetBSDVM(basevm.BaseVM): "SDL2", "gtk3+", "libxkbcommon", + + # libs: migration + "zstd", ] BUILD_SCRIPT = """
tests/vm/openbsd +3 -0
@@ -51,6 +51,9 @@ class OpenBSDVM(basevm.BaseVM): "sdl2", "gtk+3", "libxkbcommon", + + # libs: migration + "zstd", ] BUILD_SCRIPT = """
Re: [PATCH v5 6/8] configure: Enable test and libs for zstd
Quoted 189 lines · Juan Quintela
Quoted 9 lines · Daniel P. Berrangé
Quoted 5 lines · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- configure | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)This is adding a new 3rd party library to QEMU that we've not previously built and so isn't included in any of our CI platforms.
Ok.
Learning how one does that.
Quoted 5 lines
This commit should be updating at least some of our CI platforms to request the libzstd library installation to get CI coverage for the latest patches in this series.
Probably the docker files,
I added it in all debian/centos/fedora files that zlib-dev or xen-dev
Quoted 1 line
the VM installs for FreeBSD at least,
A fast google finds that library is called "zstd" and that it includes the includes (put intended)
tests/vm/freebsd
Once there, include it in fedora
Quoted 1 line
travis and
I added it to .travis.yml
Quoted 1 line
gitlab CI.
gitlab-ci.yml (just when we compile x86_64-softmmu)
I have something like this, but net real clue how to test that I haven't broken anything:
commit
59d8694dfcfc3d5ef36bc72a5c02bedaa3a6a6ecAuthor: Juan Quintela <[email protected]> Date: Thu Feb 13 22:06:16 2020 +0100Use zstd packages
Signed-off-by Juan Quintela <[email protected]>.gitlab-ci.yml +1
-0@@ -21,6 +21,7 @@ build-system2: script: - apt-get install -y -qq libsdl2-dev libgcrypt-dev libbrlapi-dev libaio-dev libfdt-dev liblzo2-dev librdmacm-dev libibverbs-dev libibumad-dev + libzstd-dev - mkdir build - cd build - ../configure --enable-werror --target-list="tricore-softmmu unicore32-softmmu.travis.yml +1
-0@@ -48,6 +48,7 @@ addons: - libusb-1.0-0-dev - libvdeplug-dev - libvte-2.91-dev + - libzstd-dev - sparse - uuid-dev - gcovrtests/docker/dockerfiles/centos7.docker +2
-1@@ -33,6 +33,7 @@ ENV PACKAGES \ tar \ vte-devel \ xen-devel \ - zlib-devel + zlib-devel \ + libzstd-devel RUN yum install -y $PACKAGES RUN rpm -q $PACKAGES | sort > /packages.txttests/docker/dockerfiles/fedora-i386-cross.docker +2
-1@@ -7,7 +7,8 @@ ENV PACKAGES \ gnutls-devel.i686 \ nettle-devel.i686 \ pixman-devel.i686 \ - zlib-devel.i686 + zlib-devel.i686 \ + libzstd-devel.i686 RUN dnf install -y $PACKAGES RUN rpm -q $PACKAGES | sort > /packages.txttests/docker/dockerfiles/fedora.docker +2
-1@@ -92,7 +92,8 @@ ENV PACKAGES \ vte291-devel \ which \ xen-devel \ - zlib-devel + zlib-devel \ + libzstd-devel ENV QEMU_CONFIGURE_OPTS --python=/usr/bin/python3 RUN dnf install -y $PACKAGEStests/docker/dockerfiles/ubuntu.docker +1
-0@@ -58,6 +58,7 @@ ENV PACKAGES flex bison \ libvdeplug-dev \ libvte-2.91-dev \ libxen-dev \ + libzstd-dev \ make \ python3-yaml \ python3-sphinx \tests/docker/dockerfiles/ubuntu1804.docker +1
-0@@ -44,6 +44,7 @@ ENV PACKAGES flex bison \ libvdeplug-dev \ libvte-2.91-dev \ libxen-dev \ + libzstd-dev \ make \ python3-yaml \ python3-sphinx \tests/vm/fedora +4
-1@@ -53,7 +53,10 @@ class FedoraVM(basevm.BaseVM): # libs: audio '"pkgconfig(libpulse)"', '"pkgconfig(alsa)"', - ] + + # libs: migration + '"pkgconfig(libzstd)"', +] BUILD_SCRIPT = """ set -e;tests/vm/freebsd +3
-0@@ -55,6 +55,9 @@ class FreeBSDVM(basevm.BaseVM): # libs: opengl "libepoxy", "mesa-libs", + + # libs: migration + "zstd", ] BUILD_SCRIPT = """tests/vm/netbsd +3
-0@@ -49,6 +49,9 @@ class NetBSDVM(basevm.BaseVM): "SDL2", "gtk3+", "libxkbcommon", + + # libs: migration + "zstd", ] BUILD_SCRIPT = """tests/vm/openbsd +0
-0
tests/vm/openbsd class OpenBSDVM(basevm.BaseVM): · line 59
Quoted 9 lines
tests/vm/openbsd +3
-0@@ -51,6 +51,9 @@ class OpenBSDVM(basevm.BaseVM): "sdl2", "gtk+3", "libxkbcommon", + + # libs: migration + "zstd", ] BUILD_SCRIPT = """
This looks good to me, thanks.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 7/8 multifd: Add multifd-zstd-level parameter
In reply to Juan Quintela--- migration/migration.c | 15 +++++++++++++++ monitor/hmp-cmds.c | 4 ++++ qapi/migration.json | 29 ++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-)
migration/migration.c +15 -0
@@ -91,6 +91,8 @@#define DEFAULT_MIGRATE_MULTIFD_METHOD MULTIFD_METHOD_NONE/*0: means nocompress, 1: best speed, ... 9: best compress ratio */ #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1 +/* 0: means nocompress, 1: best speed, ... 20: best compress ratio */ +#define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1/* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit.
@@ -805,6 +807,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->multifd_method = s->parameters.multifd_method; params->has_multifd_zlib_level = true; params->multifd_zlib_level = s->parameters.multifd_zlib_level; + params->has_multifd_zstd_level = true; + params->multifd_zstd_level = s->parameters.multifd_zstd_level; params->has_xbzrle_cache_size = true; params->xbzrle_cache_size = s->parameters.xbzrle_cache_size; params->has_max_postcopy_bandwidth = true;
@@ -1219,6 +1223,13 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)return false; } +if (params->has_multifd_zstd_level && + (params->multifd_zstd_level >20 )) { +error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"multifd_zstd_level" , +"is invalid, it should be in the range of 0 to 20" ); +return false; + } +if (params->has_xbzrle_cache_size && (params->xbzrle_cache_size <qemu_target_page_size () || !is_power_of_2 (params->xbzrle_cache_size))) {
@@ -3559,6 +3570,9 @@ static Property migration_properties[] = {DEFINE_PROP_UINT8 ("multifd-zlib-level" , MigrationState, parameters.multifd_zlib_level,DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL ), +DEFINE_PROP_UINT8 ("multifd-zstd-level" , MigrationState, + parameters.multifd_zstd_level, +DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL ),DEFINE_PROP_SIZE ("xbzrle-cache-size" , MigrationState, parameters.xbzrle_cache_size, DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),
@@ -3651,6 +3665,7 @@ static void migration_instance_init(Object *obj) params->has_multifd_channels = true; params->has_multifd_method = true; params->has_multifd_zlib_level = true; + params->has_multifd_zstd_level = true; params->has_xbzrle_cache_size = true; params->has_max_postcopy_bandwidth = true; params->has_max_cpu_throttle = true;
monitor/hmp-cmds.c +4 -0
@@ -1840,6 +1840,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p->has_multifd_zlib_level = true;visit_type_int (v, param, &p->multifd_zlib_level, &err);break ; +case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL : + p->has_multifd_zstd_level = true; +visit_type_int (v, param, &p->multifd_zstd_level, &err); +break ;case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE : p->has_xbzrle_cache_size = true;visit_type_size (v, param, &cache_size, &err);
qapi/migration.json +26 -3
@@ -610,6 +610,13 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # +# @multifd-zstd-level: Set the compression level to be used in live +# migration, the compression level is an integer between 0 +# and 20, where 0 means no compression, 1 means the best +# compression speed, and 20 means best compression ratio which +# will consume more CPU. +# Defaults to 1. (Since 5.0) +# # Since: 2.4 ## { 'enum': 'MigrationParameter',
@@ -623,7 +630,7 @@ 'multifd-channels', 'xbzrle-cache-size', 'max-postcopy-bandwidth', 'max-cpu-throttle', 'multifd-method', - 'multifd-zlib-level' ] } + 'multifd-zlib-level' ,'multifd-zstd-level' ] } ## # @MigrateSetParameters:
@@ -723,6 +730,13 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # +# @multifd-zstd-level: Set the compression level to be used in live +# migration, the compression level is an integer between 0 +# and 20, where 0 means no compression, 1 means the best +# compression speed, and 20 means best compression ratio which +# will consume more CPU. +# Defaults to 1. (Since 5.0) +# # Since: 2.4 ## # TODO either fuse back into MigrationParameters, or make
@@ -750,7 +764,8 @@ '*max-postcopy-bandwidth': 'size', '*max-cpu-throttle': 'int', '*multifd-method': 'MultiFDMethod', - '*multifd-zlib-level': 'int' } } + '*multifd-zlib-level': 'int', + '*multifd-zstd-level': 'int' } } ## # @migrate-set-parameters:
@@ -870,6 +885,13 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # +# @multifd-zstd-level: Set the compression level to be used in live +# migration, the compression level is an integer between 0 +# and 20, where 0 means no compression, 1 means the best +# compression speed, and 20 means best compression ratio which +# will consume more CPU. +# Defaults to 1. (Since 5.0) +# # Since: 2.4 ## { 'struct': 'MigrationParameters',
@@ -895,7 +917,8 @@ '*max-postcopy-bandwidth': 'size', '*max-cpu-throttle': 'uint8', '*multifd-method': 'MultiFDMethod', - '*multifd-zlib-level': 'uint8' } } + '*multifd-zlib-level': 'uint8', + '*multifd-zstd-level': 'uint8' } } ## # @query-migrate-parameters:
Signature · 1 line
2.24.1
Re: [PATCH v5 7/8] multifd: Add multifd-zstd-level parameter
Quoted 1 line · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>
Same confusion as in PATCH 4; my proposal there applies here, too.
For QAPI:
Re: [PATCH v5 7/8] multifd: Add multifd-zstd-level parameter
In reply to Juan QuintelaQuoted 21 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 15 +++++++++++++++ monitor/hmp-cmds.c | 4 ++++ qapi/migration.json | 29 ++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-)migration/migration.c +2
-0@@ -91,6 +91,8 @@#define DEFAULT_MIGRATE_MULTIFD_METHOD MULTIFD_METHOD_NONE/*0: means nocompress, 1: best speed, ... 9: best compress ratio */ #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1 +/* 0: means nocompress, 1: best speed, ... 20: best compress ratio */ +#define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1/* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit.
migration/migration.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 811
Quoted 5 lines
migration/migration.c +2
-0@@ -805,6 +807,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->multifd_method = s->parameters.multifd_method; params->has_multifd_zlib_level = true; params->multifd_zlib_level = s->parameters.multifd_zlib_level; + params->has_multifd_zstd_level = true; + params->multifd_zstd_level = s->parameters.multifd_zstd_level;
Do we really want different 'multifd_...._level's or just one 'multifd_compress_level' - or even just reuse the existing 'compress-level' parameter.
The only tricky thing about combining them is how to handle the difference in allowed ranges; When would the right time be to check it?
Markus/Eric: Any idea?
Dave
Quoted 128 lines
migration/migration.c +11
-0params->has_xbzrle_cache_size = true; params->xbzrle_cache_size = s->parameters.xbzrle_cache_size; params->has_max_postcopy_bandwidth = true;@@ -1219,6 +1223,13 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)return false; } +if (params->has_multifd_zstd_level && + (params->multifd_zstd_level >20 )) { +error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"multifd_zstd_level" , +"is invalid, it should be in the range of 0 to 20" ); +return false; + } +if (params->has_xbzrle_cache_size && (params->xbzrle_cache_size <qemu_target_page_size () || !is_power_of_2 (params->xbzrle_cache_size))) {@@ -3559,6 +3570,9 @@ static Property migration_properties[] = {DEFINE_PROP_UINT8 ("multifd-zlib-level" , MigrationState, parameters.multifd_zlib_level,DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL ), +DEFINE_PROP_UINT8 ("multifd-zstd-level" , MigrationState, + parameters.multifd_zstd_level, +DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL ),DEFINE_PROP_SIZE ("xbzrle-cache-size" , MigrationState, parameters.xbzrle_cache_size, DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),@@ -3651,6 +3665,7 @@ static void migration_instance_init(Object *obj) params->has_multifd_channels = true; params->has_multifd_method = true; params->has_multifd_zlib_level = true; + params->has_multifd_zstd_level = true; params->has_xbzrle_cache_size = true; params->has_max_postcopy_bandwidth = true; params->has_max_cpu_throttle = true;monitor/hmp-cmds.c +4
-0@@ -1840,6 +1840,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p->has_multifd_zlib_level = true;visit_type_int (v, param, &p->multifd_zlib_level, &err);break ; +case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL : + p->has_multifd_zstd_level = true; +visit_type_int (v, param, &p->multifd_zstd_level, &err); +break ;case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE : p->has_xbzrle_cache_size = true;visit_type_size (v, param, &cache_size, &err);qapi/migration.json +26
-3@@ -610,6 +610,13 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # +# @multifd-zstd-level: Set the compression level to be used in live +# migration, the compression level is an integer between 0 +# and 20, where 0 means no compression, 1 means the best +# compression speed, and 20 means best compression ratio which +# will consume more CPU. +# Defaults to 1. (Since 5.0) +# # Since: 2.4 ## { 'enum': 'MigrationParameter',@@ -623,7 +630,7 @@ 'multifd-channels', 'xbzrle-cache-size', 'max-postcopy-bandwidth', 'max-cpu-throttle', 'multifd-method', - 'multifd-zlib-level' ] } + 'multifd-zlib-level' ,'multifd-zstd-level' ] } ## # @MigrateSetParameters:@@ -723,6 +730,13 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # +# @multifd-zstd-level: Set the compression level to be used in live +# migration, the compression level is an integer between 0 +# and 20, where 0 means no compression, 1 means the best +# compression speed, and 20 means best compression ratio which +# will consume more CPU. +# Defaults to 1. (Since 5.0) +# # Since: 2.4 ## # TODO either fuse back into MigrationParameters, or make@@ -750,7 +764,8 @@ '*max-postcopy-bandwidth': 'size', '*max-cpu-throttle': 'int', '*multifd-method': 'MultiFDMethod', - '*multifd-zlib-level': 'int' } } + '*multifd-zlib-level': 'int', + '*multifd-zstd-level': 'int' } } ## # @migrate-set-parameters:@@ -870,6 +885,13 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # +# @multifd-zstd-level: Set the compression level to be used in live +# migration, the compression level is an integer between 0 +# and 20, where 0 means no compression, 1 means the best +# compression speed, and 20 means best compression ratio which +# will consume more CPU. +# Defaults to 1. (Since 5.0) +# # Since: 2.4 ## { 'struct': 'MigrationParameters',@@ -895,7 +917,8 @@ '*max-postcopy-bandwidth': 'size', '*max-cpu-throttle': 'uint8', '*multifd-method': 'MultiFDMethod', - '*multifd-zlib-level': 'uint8' } } + '*multifd-zlib-level': 'uint8', + '*multifd-zstd-level': 'uint8' } } ## # @query-migrate-parameters:Signature · 1 line
2.24.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH v5 7/8] multifd: Add multifd-zstd-level parameter
Quoted 19 lines · Dr. David Alan Gilbert
Quoted 18 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 15 +++++++++++++++ monitor/hmp-cmds.c | 4 ++++ qapi/migration.json | 29 ++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-)migration/migration.c +2
-0@@ -91,6 +91,8 @@#define DEFAULT_MIGRATE_MULTIFD_METHOD MULTIFD_METHOD_NONE/*0: means nocompress, 1: best speed, ... 9: best compress ratio */ #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1 +/* 0: means nocompress, 1: best speed, ... 20: best compress ratio */ +#define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1
Quoted 12 lines
migration/migration.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 811
Quoted 8 lines
migration/migration.c +2
-0/* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit. @@ -805,6 +807,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->multifd_method = s->parameters.multifd_method; params->has_multifd_zlib_level = true; params->multifd_zlib_level = s->parameters.multifd_zlib_level; + params->has_multifd_zstd_level = true; + params->multifd_zstd_level = s->parameters.multifd_zstd_level;Do we really want different 'multifd_...._level's or just one '
multifd_compress_level' - or even just reuse the existing 'compress-level' parameter.
compress-level, multifd-zlib-level, and multifd-zstd-level apply "normal" live migration compression, multifd zlib live migration compression, and multifd zstd live migration compression, respectively.
Any live migration can only use one of the three compressions.
Correct?
Quoted 5 lines
The only tricky thing about combining them is how to handle the difference in allowed ranges; When would the right time be to check it?
Markus/Eric: Any idea?
To have an informed opinion, I'd have to dig through the migration code.
Documentation of admissible range will become a bit awkward, too.
Too many migration parameters...
Re: [PATCH v5 7/8] multifd: Add multifd-zstd-level parameter
Quoted 34 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 19 lines · Dr. David Alan Gilbert
Quoted 18 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 15 +++++++++++++++ monitor/hmp-cmds.c | 4 ++++ qapi/migration.json | 29 ++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-)migration/migration.c +2
-0@@ -91,6 +91,8 @@#define DEFAULT_MIGRATE_MULTIFD_METHOD MULTIFD_METHOD_NONE/*0: means nocompress, 1: best speed, ... 9: best compress ratio */ #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1 +/* 0: means nocompress, 1: best speed, ... 20: best compress ratio */ +#define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1Quoted 12 lines
migration/migration.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 811
Quoted 8 lines
migration/migration.c +2
-0/* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit. @@ -805,6 +807,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->multifd_method = s->parameters.multifd_method; params->has_multifd_zlib_level = true; params->multifd_zlib_level = s->parameters.multifd_zlib_level; + params->has_multifd_zstd_level = true; + params->multifd_zstd_level = s->parameters.multifd_zstd_level;Do we really want different 'multifd_...._level's or just one '
multifd_compress_level' - or even just reuse the existing 'compress-level' parameter.
Quoted 7 lines
compress-level, multifd-zlib-level, and multifd-zstd-level apply "normal" live migration compression, multifd zlib live migration compression, and multifd zstd live migration compression, respectively.
Any live migration can only use one of the three compressions.
Correct?
Right.
Quoted 8 lines
Quoted 5 lines
The only tricky thing about combining them is how to handle the difference in allowed ranges; When would the right time be to check it?
Markus/Eric: Any idea?
To have an informed opinion, I'd have to dig through the migration code.
The tricky part I see is validating settings/parameters; when someone tries to set a parameter migrate_params_check gets called and has checks like:
if (params->has_compress_level &&
(params->compress_level > 9)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level",
"is invalid, it should be in the range of 0 to 9");
return false;
}now that's nice because you error when you set the parameter rather than later when you try and start a migration; the downside now though is you get more complex interaction between parameters and capabilities - so for example if you set the multifd-compression type parameter to 'zstd' and *then* set the single compression level it'll be fine taking '20' as a compresison level, but if you were to set the compression level to 20 and then set the type to 'zstd' it might error because with zlib you can't have 20.
Quoted 3 lines
Documentation of admissible range will become a bit awkward, too.
Too many migration parameters...
Nod; which why I was trying to make it 1.
Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH v5 7/8] multifd: Add multifd-zstd-level parameter
In reply to Markus ArmbrusterQuoted 34 lines · Markus Armbruster
Quoted 19 lines · Dr. David Alan Gilbert
Quoted 18 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 15 +++++++++++++++ monitor/hmp-cmds.c | 4 ++++ qapi/migration.json | 29 ++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-)migration/migration.c +2
-0@@ -91,6 +91,8 @@#define DEFAULT_MIGRATE_MULTIFD_METHOD MULTIFD_METHOD_NONE/*0: means nocompress, 1: best speed, ... 9: best compress ratio */ #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1 +/* 0: means nocompress, 1: best speed, ... 20: best compress ratio */ +#define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1Quoted 12 lines
migration/migration.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 811
Quoted 8 lines
migration/migration.c +2
-0/* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit. @@ -805,6 +807,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->multifd_method = s->parameters.multifd_method; params->has_multifd_zlib_level = true; params->multifd_zlib_level = s->parameters.multifd_zlib_level; + params->has_multifd_zstd_level = true; + params->multifd_zstd_level = s->parameters.multifd_zstd_level;Do we really want different 'multifd_...._level's or just one '
multifd_compress_level' - or even just reuse the existing 'compress-level' parameter.
Quoted 1 line
compress-level,
possible values: 1 to 9 deprecated
Quoted 1 line
multifd-zlib-level
possible values: 1 to 9, default 1
(zlib default is -1, let the lib decide)
, and multifd-zstd-level apply
possible values: 1 to 19, default 1
(zstd default is 3)
Quoted 6 lines
"normal" live migration compression, multifd zlib live migration compression, and multifd zstd live migration compression, respectively.
Any live migration can only use one of the three compressions.
Correct?
Yeap.
Quoted 8 lines
Quoted 5 lines
The only tricky thing about combining them is how to handle the difference in allowed ranges; When would the right time be to check it?
Markus/Eric: Any idea?
To have an informed opinion, I'd have to dig through the migration code.
Problem is _how_ to setup them. if we setup zstd compression method, put the value at 19, and then setup zlib compression method, what should we do?
Truncate to 9?
Give one error?
Don't allow the zlib setup?
Too complicated.
Quoted 3 lines
Documentation of admissible range will become a bit awkward, too.
Too many migration parameters...
Sure, but the other option is taking a value and live with it. I am all for leaving the library default and call it a day.
Later, Juan.
Re: [PATCH v5 7/8] multifd: Add multifd-zstd-level parameter
Quoted 71 lines · Juan Quintela
Quoted 34 lines · Markus Armbruster
Quoted 19 lines · Dr. David Alan Gilbert
Quoted 18 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 15 +++++++++++++++ monitor/hmp-cmds.c | 4 ++++ qapi/migration.json | 29 ++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-)migration/migration.c +2
-0@@ -91,6 +91,8 @@#define DEFAULT_MIGRATE_MULTIFD_METHOD MULTIFD_METHOD_NONE/*0: means nocompress, 1: best speed, ... 9: best compress ratio */ #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1 +/* 0: means nocompress, 1: best speed, ... 20: best compress ratio */ +#define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1Quoted 12 lines
migration/migration.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 811
Quoted 8 lines
migration/migration.c +2
-0/* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit. @@ -805,6 +807,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->multifd_method = s->parameters.multifd_method; params->has_multifd_zlib_level = true; params->multifd_zlib_level = s->parameters.multifd_zlib_level; + params->has_multifd_zstd_level = true; + params->multifd_zstd_level = s->parameters.multifd_zstd_level;Do we really want different 'multifd_...._level's or just one '
multifd_compress_level' - or even just reuse the existing 'compress-level' parameter.Quoted 1 line
compress-level,
possible values: 1 to 9 deprecated
Quoted 1 line
multifd-zlib-level
possible values: 1 to 9, default 1
(zlib default is -1, let the lib decide), and multifd-zstd-level apply
possible values: 1 to 19, default 1
(zstd default is 3)Quoted 6 lines
"normal" live migration compression, multifd zlib live migration compression, and multifd zstd live migration compression, respectively.
Any live migration can only use one of the three compressions.
Correct?
Yeap.
Quoted 8 lines
Quoted 5 lines
The only tricky thing about combining them is how to handle the difference in allowed ranges; When would the right time be to check it?
Markus/Eric: Any idea?
To have an informed opinion, I'd have to dig through the migration code.
Problem is _how_ to setup them. if we setup zstd compression method, put the value at 19, and then setup zlib compression method, what should we do?
Quoted 5 lines
Truncate to 9?
Give one error?
Don't allow the zlib setup?Too complicated.
The interface pretends the parameters are all independent: you get to set them one by one.
They are in fact not independent, and this now leads to difficulties.
To avoid them, the interface should let you specify a desired configuration all at once, and its implementation should then do what it takes to get from here to there.
Example: current state is multifd compression method "zstd", compression level is 19. User wants to switch to method "zlib" level 9 the obvious way
With old interface:
step 1: set method to "zlib"
step 2: set level to 9
Problem: after step 1, we have method "zlib" with invalid level 19.
Workaround: swap the steps.
Note that the workaround only works because the set of levels both methods support is non-empty. We might still come up with more complicated parameter combinations where that is not the case.
With new interface:
set compression to "zlib" level 9
The new interface require us to specify a QAPI type capable of holding the complete migration configuration.
The stupid way is to throw all migration parameters into a struct, and make the ones optional that apply only when others have certain values. Thus, the "applies only when" bits are semantical, documented in comments, and enforced by C code.
With a bit more care, we can make "applies only when" syntactical instead. Examples:
@max-bandwidth and @downtime-limit always apply. They go straight into the struct.
@tls-creds, @tls-hostname, @tls-authz apply only when TLS is enabled by setting @tls-creds. Have an optional member @tls, which is a struct with mandatory member @creds, optional members @hostname, @authz.
@multifd-zlib-level applies when @multifd-method is "zlib", and @multifd-zstd-level applies when it's "zstd". Have a union @multifd-compression, cases "none", "zlib" and "zstd", where each case's members are the parameters applying in that case.
Please note the purpose of these examples is to show how things can be done in the schema. I'm not trying to tell you how these specific things *should* be done.
The resulting type is perfectly suited as return value of a query command. It's awkward as argument of a "specify desired configuration" command, because it requires the user to specify *complete* configuration. If we want to support omitting the parts of it we don't want to change, we have to make more members optional. Imprecise for the query, where we now have to specify "always present" in comments. Usually less bad than duplicating a complex type.
Quoted 8 lines
Quoted 3 lines
Documentation of admissible range will become a bit awkward, too.
Too many migration parameters...
Sure, but the other option is taking a value and live with it. I am all for leaving the library default and call it a day.
Later, Juan.
Hope this helps some.
Re: [PATCH v5 7/8] multifd: Add multifd-zstd-level parameter
Quoted 105 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 71 lines · Juan Quintela
Quoted 34 lines · Markus Armbruster
Quoted 19 lines · Dr. David Alan Gilbert
Quoted 18 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 15 +++++++++++++++ monitor/hmp-cmds.c | 4 ++++ qapi/migration.json | 29 ++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-)migration/migration.c +2
-0@@ -91,6 +91,8 @@#define DEFAULT_MIGRATE_MULTIFD_METHOD MULTIFD_METHOD_NONE/*0: means nocompress, 1: best speed, ... 9: best compress ratio */ #define DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL 1 +/* 0: means nocompress, 1: best speed, ... 20: best compress ratio */ +#define DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL 1Quoted 12 lines
migration/migration.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 811
Quoted 8 lines
migration/migration.c +2
-0/* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit. @@ -805,6 +807,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->multifd_method = s->parameters.multifd_method; params->has_multifd_zlib_level = true; params->multifd_zlib_level = s->parameters.multifd_zlib_level; + params->has_multifd_zstd_level = true; + params->multifd_zstd_level = s->parameters.multifd_zstd_level;Do we really want different 'multifd_...._level's or just one '
multifd_compress_level' - or even just reuse the existing 'compress-level' parameter.Quoted 1 line
compress-level,
possible values: 1 to 9 deprecated
Quoted 1 line
multifd-zlib-level
possible values: 1 to 9, default 1
(zlib default is -1, let the lib decide), and multifd-zstd-level apply
possible values: 1 to 19, default 1
(zstd default is 3)Quoted 6 lines
"normal" live migration compression, multifd zlib live migration compression, and multifd zstd live migration compression, respectively.
Any live migration can only use one of the three compressions.
Correct?
Yeap.
Quoted 8 lines
Quoted 5 lines
The only tricky thing about combining them is how to handle the difference in allowed ranges; When would the right time be to check it?
Markus/Eric: Any idea?
To have an informed opinion, I'd have to dig through the migration code.
Problem is _how_ to setup them. if we setup zstd compression method, put the value at 19, and then setup zlib compression method, what should we do?
Quoted 5 lines
Truncate to 9?
Give one error?
Don't allow the zlib setup?Too complicated.
The interface pretends the parameters are all independent: you get to set them one by one.
They are in fact not independent, and this now leads to difficulties.
To avoid them, the interface should let you specify a desired configuration all at once, and its implementation should then do what it takes to get from here to there.
Example: current state is multifd compression method "zstd", compression level is 19. User wants to switch to method "zlib" level 9 the obvious way
With old interface:
step 1: set method to "zlib"
step 2: set level to 9
Problem: after step 1, we have method "zlib" with invalid level 19.
Workaround: swap the steps.Note that the workaround only works because the set of levels both methods support is non-empty. We might still come up with more complicated parameter combinations where that is not the case.
With new interface:
set compression to "zlib" level 9
Quoted 7 lines
The new interface require us to specify a QAPI type capable of holding the complete migration configuration.
The stupid way is to throw all migration parameters into a struct, and make the ones optional that apply only when others have certain values. Thus, the "applies only when" bits are semantical, documented in comments, and enforced by C code.
I realised we already have that stupid struct! It's just MigrationParameters - it has all the parameters as optional values, and QMP's MigrateSetParameters already takes that - so you can already provide both the type and the level at the same time; although there's no semantic correlation between them.
Dave
Quoted 30 lines
With a bit more care, we can make "applies only when" syntactical instead. Examples:
@max-bandwidth and @downtime-limit always apply. They go straight into the struct.
@tls-creds, @tls-hostname, @tls-authz apply only when TLS is enabled by setting @tls-creds. Have an optional member @tls, which is a struct with mandatory member @creds, optional members @hostname, @authz.
@multifd-zlib-level applies when @multifd-method is "zlib", and @multifd-zstd-level applies when it's "zstd". Have a union @multifd-compression, cases "none", "zlib" and "zstd", where each case's members are the parameters applying in that case.
Please note the purpose of these examples is to show how things can be done in the schema. I'm not trying to tell you how these specific things *should* be done.
The resulting type is perfectly suited as return value of a query command. It's awkward as argument of a "specify desired configuration" command, because it requires the user to specify *complete* configuration. If we want to support omitting the parts of it we don't want to change, we have to make more members optional. Imprecise for the query, where we now have to specify "always present" in comments. Usually less bad than duplicating a complex type.
Quoted 2 lines
Quoted 2 lines
Documentation of admissible range will become a bit awkward, too.
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Too many migration parameters...
Sure, but the other option is taking a value and live with it. I am all for leaving the library default and call it a day.
Later, Juan.
Hope this helps some.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH v5 8/8 multifd: Add zstd compression multifd support
In reply to Juan Quintela--- hw/core/qdev-properties.c | 2 +- migration/Makefile.objs | 1 + migration/migration.c | 9 + migration/migration.h | 1 + migration/multifd-zstd.c | 337 +++++++++++++++++++++++++++++++++++ migration/multifd.h | 2 +- migration/ram.c | 1 - qapi/migration.json | 4 +- tests/qtest/migration-test.c | 10 ++ 9 files changed, 363 insertions(+), 4 deletions(-) create mode 100644 migration/multifd-zstd.c
hw/core/qdev-properties.c +1 -1
@@ -645,7 +645,7 @@ const PropertyInfo qdev_prop_fdc_drive_type = {const PropertyInfo qdev_prop_multifd_method = { .name ="MultiFDMethod" , .description ="multifd_method values, " -"none/zlib" , +"none/zlib/zstd" , .enum_table = &MultiFDMethod_lookup, .get = get_enum, .set = set_enum,
migration/Makefile.objs +1 -0
@@ -9,6 +9,7 @@ common-obj-y += qjson.o common-obj-y += block-dirty-bitmap.o common-obj-y += multifd.o common-obj-y += multifd-zlib.o +common-obj-$(CONFIG_ZSTD) += multifd-zstd.o common-obj-$(CONFIG_RDMA) += rdma.o
migration/migration.c +9 -0
@@ -2285,6 +2285,15 @@ int migrate_multifd_zlib_level(void)return s->parameters.multifd_zlib_level; } +int migrate_multifd_zstd_level (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->parameters.multifd_zstd_level; +} +int migrate_use_xbzrle (void ) {MigrationState *s;
migration/migration.h +1 -0
@@ -302,6 +302,7 @@ bool migrate_pause_before_switchover(void);int migrate_multifd_channels (void );MultiFDMethod migrate_multifd_method (void );int migrate_multifd_zlib_level (void ); +int migrate_multifd_zstd_level (void );int migrate_use_xbzrle (void );int64_t migrate_xbzrle_cache_size (void );
migration/multifd-zstd.c new file +337 -0
337 lines not on this page · raw message
migration/multifd.h +1 -1
@@ -30,6 +30,7 @@ int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);#define MULTIFD_FLAG_METHOD_MASK (7 << 1)#define MULTIFD_FLAG_NOCOMP (1 << 1)#define MULTIFD_FLAG_ZLIB (2 << 1) +#define MULTIFD_FLAG_ZSTD (3 << 1)/* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024)
@@ -163,6 +164,5 @@ typedef struct { } MultiFDMethods;void multifd_register_ops (int method,MultiFDMethods *ops); -#endif
migration/ram.c +0 -1
@@ -28,7 +28,6 @@#include "qemu/osdep.h" #include "cpu.h" -#include <zlib.h> #include "qemu/cutils.h" #include "qemu/bitops.h" #include "qemu/bitmap.h"
qapi/migration.json +3 -1
@@ -495,12 +495,14 @@ # # @none: no compression. # @zlib: use zlib compression method. +# @zstd: use zstd compression method. # # Since: 5.0 # ## { 'enum': 'MultiFDMethod', - 'data': [ 'none', 'zlib' ] } + 'data': [ 'none', 'zlib', + { 'name': 'zstd', 'if': 'defined(CONFIG_ZSTD)' } ] } ## # @MigrationParameter:
tests/qtest/migration-test.c +10 -0
@@ -1318,6 +1318,13 @@ static void test_multifd_tcp_zlib(void)test_multifd_tcp ("zlib" ); } +#ifdef CONFIG_ZSTD +static void test_multifd_tcp_zstd (void ) +{ +test_multifd_tcp ("zstd" ); +} +#endif +/* * This test does: * source target
@@ -1481,6 +1488,9 @@ int main(int argc, char **argv)qtest_add_func ("/migration/multifd/tcp/none" , test_multifd_tcp_none);qtest_add_func ("/migration/multifd/tcp/cancel" , test_multifd_tcp_cancel);qtest_add_func ("/migration/multifd/tcp/zlib" , test_multifd_tcp_zlib); +#ifdef CONFIG_ZSTD +qtest_add_func ("/migration/multifd/tcp/zstd" , test_multifd_tcp_zstd); +#endif ret =g_test_run ();
Signature · 1 line
2.24.1
Re: [PATCH v5 8/8] multifd: Add zstd compression multifd support
Quoted 1 line · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>
For QAPI:
Re: [PATCH v5 8/8] multifd: Add zstd compression multifd support
In reply to Juan QuintelaQuoted 133 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- hw/core/qdev-properties.c | 2 +- migration/Makefile.objs | 1 + migration/migration.c | 9 + migration/migration.h | 1 + migration/multifd-zstd.c | 337 +++++++++++++++++++++++++++++++++++ migration/multifd.h | 2 +- migration/ram.c | 1 - qapi/migration.json | 4 +- tests/qtest/migration-test.c | 10 ++ 9 files changed, 363 insertions(+), 4 deletions(-) create mode 100644 migration/multifd-zstd.chw/core/qdev-properties.c +1
-1@@ -645,7 +645,7 @@ const PropertyInfo qdev_prop_fdc_drive_type = {const PropertyInfo qdev_prop_multifd_method = { .name ="MultiFDMethod" , .description ="multifd_method values, " -"none/zlib" , +"none/zlib/zstd" , .enum_table = &MultiFDMethod_lookup, .get = get_enum, .set = set_enum,migration/Makefile.objs +1
-0@@ -9,6 +9,7 @@ common-obj-y += qjson.o common-obj-y += block-dirty-bitmap.o common-obj-y += multifd.o common-obj-y += multifd-zlib.o +common-obj-$(CONFIG_ZSTD) += multifd-zstd.o common-obj-$(CONFIG_RDMA) += rdma.omigration/migration.c +9
-0@@ -2285,6 +2285,15 @@ int migrate_multifd_zlib_level(void)return s->parameters.multifd_zlib_level; } +int migrate_multifd_zstd_level (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->parameters.multifd_zstd_level; +} +int migrate_use_xbzrle (void ) {MigrationState *s;migration/migration.h +1
-0@@ -302,6 +302,7 @@ bool migrate_pause_before_switchover(void);int migrate_multifd_channels (void );MultiFDMethod migrate_multifd_method (void );int migrate_multifd_zlib_level (void ); +int migrate_multifd_zstd_level (void );int migrate_use_xbzrle (void );int64_t migrate_xbzrle_cache_size (void );migration/multifd-zstd.c new file +56
-0@@ -0,0 +1,337 @@ +/* +* Multifd zlib compression implementation +* +* Copyright (c) 2020 Red Hat Inc +* +* Authors: +* Juan Quintela <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include <zstd.h> +#include "qemu/rcu.h" +#include "exec/target_page.h" +#include "qapi/error.h" +#include "migration.h" +#include "trace.h" +#include "multifd.h" + +struct zstd_data { +/* stream for compression */ +ZSTD_CStream *zcs; +/* stream for decompression */ +ZSTD_DStream *zds; +/* buffers */ +ZSTD_inBuffer in; +ZSTD_outBuffer out; +/* compressed buffer */ +uint8_t *zbuff; +/* size of compressed buffer */ +uint32_t zbuff_len; +}; + +/* Multifd zstd compression */ + +/** +* zstd_send_setup: setup send side +* +* Setup each channel with zstd compression. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @errp: pointer to an error +*/ +static int zstd_send_setup (MultiFDSendParams *p,Error **errp) +{ +uint32_t page_count =MULTIFD_PACKET_SIZE /qemu_target_page_size (); + struct zstd_data *z = g_new0(struct zstd_data, 1); +int res; + + p->data = z; + z->zcs =ZSTD_createCStream (); +if (!z->zcs) {
migration/multifd-zstd.c line 66
Quoted 10 lines
migration/multifd-zstd.c new file +10
-0+g_free (z); +error_setg (errp,"multifd %d: zstd createCStream failed" , p->id); +return -1 ; + } + + res =ZSTD_initCStream (z->zcs,migrate_multifd_zstd_level ()); +if (ZSTD_isError (res)) { +ZSTD_freeCStream (z->zcs); +g_free (z); +error_setg (errp,"multifd %d: initCStream failed" , p->id);
It might be useful to print 'res' here - you seem to decode it on the receive side.
Quoted 284 lines
migration/multifd-zstd.c new file +271
-0+return -1 ; + } +/* We will never have more than page_count pages */ + z->zbuff_len = page_count *qemu_target_page_size (); + z->zbuff_len *=2 ; + z->zbuff =g_try_malloc (z->zbuff_len); +if (!z->zbuff) { +ZSTD_freeCStream (z->zcs); +g_free (z); +error_setg (errp,"multifd %d: out of memory for zbuff" , p->id); +return -1 ; + } +return 0 ; +} + +/** +* zstd_send_cleanup: cleanup send side +* +* Close the channel and return memory. +* +* @p: Params for the channel that we are using +*/ +static void zstd_send_cleanup (MultiFDSendParams *p,Error **errp) +{ +struct zstd_data *z = p->data; + +ZSTD_freeCStream (z->zcs); + z->zcs =NULL ; +g_free (z->zbuff); + z->zbuff =NULL ; +g_free (p->data); + p->data =NULL ; +} + +/** +* zstd_send_prepare: prepare date to be able to send +* +* Create a compressed buffer with all the pages that we are going to +* send. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @used: number of pages used +*/ +static int zstd_send_prepare (MultiFDSendParams *p,uint32_t used,Error **errp) +{ +struct iovec *iov = p->pages->iov; +struct zstd_data *z = p->data; +int ret; +uint32_t i; + + z->out.dst = z->zbuff; + z->out.size = z->zbuff_len; + z->out.pos =0 ; + +for (i =0 ; i < used; i++) { +ZSTD_EndDirective flush = ZSTD_e_continue; + +if (i == used -1 ) { + flush = ZSTD_e_flush; + } + z->in.src = iov[i].iov_base; + z->in.size = iov[i].iov_len; + z->in.pos =0 ; + +/* +* Welcome to compressStream2 semantics +* +* We need to loop while: +* - return is > 0 +* - there is input available +* - there is output space free +*/ +do { + ret =ZSTD_compressStream2 (z->zcs, &z->out, &z->in, flush); + }while (ret >0 && (z->in.size - z->in.pos >0 ) + && (z->out.size - z->out.pos >0 )); +if (ret >0 && (z->in.size - z->in.pos >0 )) { +error_setg (errp,"multifd %d: compressStream buffer too small" , + p->id); +return -1 ; + } +if (ZSTD_isError (ret)) { +error_setg (errp,"multifd %d: compressStream error %s" , + p->id,ZSTD_getErrorName (ret)); +return -1 ; + } + } + p->next_packet_size = z->out.pos; + p->flags |=MULTIFD_FLAG_ZSTD ; + +return 0 ; +} + +/** +* zstd_send_write: do the actual write of the data +* +* Do the actual write of the comprresed buffer. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @used: number of pages used +* @errp: pointer to an error +*/ +static int zstd_send_write (MultiFDSendParams *p,uint32_t used,Error **errp) +{ +struct zstd_data *z = p->data; + +return qio_channel_write_all (p->c, (void *)z->zbuff, p->next_packet_size, + errp); +} + +/** +* zstd_recv_setup: setup receive side +* +* Create the compressed channel and buffer. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @errp: pointer to an error +*/ +static int zstd_recv_setup (MultiFDRecvParams *p,Error **errp) +{ +uint32_t page_count =MULTIFD_PACKET_SIZE /qemu_target_page_size (); + struct zstd_data *z = g_new0(struct zstd_data, 1); +int res; + + p->data = z; + z->zds =ZSTD_createDStream (); +if (!z->zds) { +g_free (z); +error_setg (errp,"multifd %d: zstd createDStream failed" , p->id); +return -1 ; + } + + res =ZSTD_initDStream (z->zds); +if (ZSTD_isError (res)) { +ZSTD_freeDStream (z->zds); +g_free (z); +error_setg (errp,"multifd %d: initDStream failed" , p->id); +return -1 ; + } + +/* We will never have more than page_count pages */ + z->zbuff_len = page_count *qemu_target_page_size (); +/* We know compression "could" use more space */ + z->zbuff_len *=2 ; + z->zbuff =g_try_malloc (z->zbuff_len); +if (!z->zbuff) { +ZSTD_freeDStream (z->zds); +g_free (z); +error_setg (errp,"multifd %d: out of memory for zbuff" , p->id); +return -1 ; + } +return 0 ; +} + +/** +* zstd_recv_cleanup: setup receive side +* +* For no compression this function does nothing. +* +* @p: Params for the channel that we are using +*/ +static void zstd_recv_cleanup (MultiFDRecvParams *p) +{ +struct zstd_data *z = p->data; + +ZSTD_freeDStream (z->zds); + z->zds =NULL ; +g_free (z->zbuff); + z->zbuff =NULL ; +g_free (p->data); + p->data =NULL ; +} + +/** +* zstd_recv_pages: read the data from the channel into actual pages +* +* Read the compressed buffer, and uncompress it into the actual +* pages. +* +* Returns 0 for success or -1 for error +* +* @p: Params for the channel that we are using +* @used: number of pages used +* @errp: pointer to an error +*/ +static int zstd_recv_pages (MultiFDRecvParams *p,uint32_t used,Error **errp) +{ +uint32_t in_size = p->next_packet_size; +uint32_t out_size =0 ; +uint32_t expected_size = used *qemu_target_page_size (); +uint32_t flags = p->flags &MULTIFD_FLAG_METHOD_MASK ; +struct zstd_data *z = p->data; +int ret; +int i; + +if (flags !=MULTIFD_FLAG_ZSTD ) { +error_setg (errp,"multifd %d: flags received %x flags expected %x" , + p->id, flags,MULTIFD_FLAG_ZSTD ); +return -1 ; + } + ret =qio_channel_read_all (p->c, (void *)z->zbuff, in_size, errp); + +if (ret !=0 ) { +return ret; + } + + z->in.src = z->zbuff; + z->in.size = in_size; + z->in.pos =0 ; + +for (i =0 ; i < used; i++) { +struct iovec *iov = &p->pages->iov[i]; + + z->out.dst = iov->iov_base; + z->out.size = iov->iov_len; + z->out.pos =0 ; + +/* +* Welcome to decompressStream semantics +* +* We need to loop while: +* - return is > 0 +* - there is input available +* - we haven't put out a full page +*/ +do { + ret =ZSTD_decompressStream (z->zds, &z->out, &z->in); + }while (ret >0 && (z->in.size - z->in.pos >0 ) + && (z->out.pos < iov->iov_len)); +if (ret >0 && (z->out.pos < iov->iov_len)) { +error_setg (errp,"multifd %d: decompressStream buffer too small" , + p->id); +return -1 ; + } +if (ZSTD_isError (ret)) { +error_setg (errp,"multifd %d: decompressStream returned %s" , + p->id,ZSTD_getErrorName (ret)); +return ret; + } + out_size += z->out.pos; + } +if (out_size != expected_size) { +error_setg (errp,"multifd %d: packet size received %d size expected %d" , + p->id, out_size, expected_size); +return -1 ; + } +return 0 ; +} + +static MultiFDMethods multifd_zstd_ops = { + .send_setup = zstd_send_setup, + .send_cleanup = zstd_send_cleanup, + .send_prepare = zstd_send_prepare, + .send_write = zstd_send_write, + .recv_setup = zstd_recv_setup, + .recv_cleanup = zstd_recv_cleanup, + .recv_pages = zstd_recv_pages +}; + +static void multifd_zstd_register (void ) +{ +multifd_register_ops (MULTIFD_METHOD_ZSTD , &multifd_zstd_ops); +} + +migration_init (multifd_zstd_register);migration/multifd.h +1
-0@@ -30,6 +30,7 @@ int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);#define MULTIFD_FLAG_METHOD_MASK (7 << 1)#define MULTIFD_FLAG_NOCOMP (1 << 1)#define MULTIFD_FLAG_ZLIB (2 << 1) +#define MULTIFD_FLAG_ZSTD (3 << 1)/* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024)
migration/multifd.h typedef struct { · line 166
Quoted 4 lines
migration/multifd.h +0
-1@@ -163,6 +164,5 @@ typedef struct { } MultiFDMethods;void multifd_register_ops (int method,MultiFDMethods *ops); -
Oddment.
Quoted 65 lines
migration/multifd.h +0
-0#endif migration/ram.c +0
-1@@ -28,7 +28,6 @@#include "qemu/osdep.h" #include "cpu.h" -#include <zlib.h> #include "qemu/cutils.h" #include "qemu/bitops.h" #include "qemu/bitmap.h" qapi/migration.json +3
-1@@ -495,12 +495,14 @@ # # @none: no compression. # @zlib: use zlib compression method. +# @zstd: use zstd compression method. # # Since: 5.0 # ## { 'enum': 'MultiFDMethod', - 'data': [ 'none', 'zlib' ] } + 'data': [ 'none', 'zlib', + { 'name': 'zstd', 'if': 'defined(CONFIG_ZSTD)' } ] } ## # @MigrationParameter:tests/qtest/migration-test.c +10
-0@@ -1318,6 +1318,13 @@ static void test_multifd_tcp_zlib(void)test_multifd_tcp ("zlib" ); } +#ifdef CONFIG_ZSTD +static void test_multifd_tcp_zstd (void ) +{ +test_multifd_tcp ("zstd" ); +} +#endif +/* * This test does: * source target @@ -1481,6 +1488,9 @@ int main(int argc, char **argv)qtest_add_func ("/migration/multifd/tcp/none" , test_multifd_tcp_none);qtest_add_func ("/migration/multifd/tcp/cancel" , test_multifd_tcp_cancel);qtest_add_func ("/migration/multifd/tcp/zlib" , test_multifd_tcp_zlib); +#ifdef CONFIG_ZSTD +qtest_add_func ("/migration/multifd/tcp/zstd" , test_multifd_tcp_zstd); +#endif ret =g_test_run ();Signature · 1 line
2.24.1
Minor comments above; but other than those it looks OK to me, but I've not used zstd before:
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH v5 8/8] multifd: Add zstd compression multifd support
Quoted 15 lines · Dr. David Alan Gilbert
Quoted 13 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- hw/core/qdev-properties.c | 2 +- migration/Makefile.objs | 1 + migration/migration.c | 9 + migration/migration.h | 1 + migration/multifd-zstd.c | 337 +++++++++++++++++++++++++++++++++++ migration/multifd.h | 2 +- migration/ram.c | 1 - qapi/migration.json | 4 +- tests/qtest/migration-test.c | 10 ++ 9 files changed, 363 insertions(+), 4 deletions(-) create mode 100644 migration/multifd-zstd.c
Quoted 8 lines
migration/multifd-zstd.c line 66
Quoted 5 lines
migration/multifd-zstd.c new file +5
-0+ res =ZSTD_initCStream (z->zcs,migrate_multifd_zstd_level ()); +if (ZSTD_isError (res)) { +ZSTD_freeCStream (z->zcs); +g_free (z); +error_setg (errp,"multifd %d: initCStream failed" , p->id);It might be useful to print 'res' here - you seem to decode it on the receive side.
Fixed all callers.
Quoted 7 lines
migration/multifd.h typedef struct { · line 166
Quoted 5 lines
migration/multifd.h +0
-1@@ -163,6 +164,5 @@ typedef struct { } MultiFDMethods;void multifd_register_ops (int method,MultiFDMethods *ops); -Oddment.
oops. Removed the chunk.
Quoted 3 lines
Reviewed-by Dr. David Alan Gilbert <[email protected]>
Thanks.