use qatzip to acclerate the live migration
PATCH 1/1 use qatzip to acclerate the live migration
qatzip https://github.com/intel/QATzip is a project that supply the zlib like api with the Intel QAT hardware. compress and decompress performance with small data block (4kb page) is low with qatzip API. so we compose multiple pages into a multi page address structure which is a buffer list, then we compose these pages together and then call compress and decompress. we also expand the io_buf_size since qat is fast have have stress to the IO_BUFF.
If there is no QAT hardware, qatzip will fall back to the software with proper congfiguration. that mean if host server have the QAT hardware, while destination server don't have QAT, the live migration still work well.
To use the qatzip, one parameter is added in both host and destination side:
(qemu) migrate_set_parameter compress-with-qat 1 if you proper eabled the qatzip, then you can benefit from the QAT accelleration.
Since the compress/decompress offloading to the QAT hardware, no CPU resource neede (only a periodomic polling need some CPU resource).
From the performance, with the same threads scale, with QATzip (HW), the live migration will have 2~4 time of performance.
plan: so far qatzip API support SVM,but no batch APIs and the requirement is raised. once the batch APIs ready, the perf expect to reach close to 10x.
update
--- meson.build | 3 +- migration/migration.c | 22 ++ migration/migration.h | 1 + migration/qemu-file.c | 13 +- migration/qemu-file.h | 3 + migration/ram.c | 771 ++++++++++++++++++++++++++++++++++-------- monitor/hmp-cmds.c | 4 + qapi/migration.json | 8 +- 8 files changed, 687 insertions(+), 138 deletions(-)
meson.build +2 -1
@@ -464,6 +464,7 @@ if have_system or have_tools method: 'pkg-config', kwargs: static_kwargs) endif zlib = dependency('zlib', required: true, kwargs: static_kwargs) +qatzip = dependency('qatzip', required: true, method: 'pkg-config', kwargs: static_kwargs) libaio = not_found if not get_option('linux_aio').auto() or have_block
@@ -3058,7 +3059,7 @@ libmigration = static_library('migration', sources: migration_files + genh, name_suffix: 'fa', build_by_default: false) migration = declare_dependency(link_with: libmigration, - dependencies: [zlib, qom, io]) + dependencies: [qatzip, zlib, qom, io]) softmmu_ss.add(migration) block_ss = block_ss.apply(config_host, strict: false)
migration/migration.c +22 -0
@@ -864,6 +864,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->compress_level = s->parameters.compress_level; params->has_compress_threads = true; params->compress_threads = s->parameters.compress_threads; + params->has_compress_with_qat = true; + params->compress_with_qat = s->parameters.compress_with_qat; params->has_compress_wait_thread = true; params->compress_wait_thread = s->parameters.compress_wait_thread; params->has_decompress_threads = true;
@@ -1500,6 +1502,10 @@ static void migrate_params_test_apply(MigrateSetParameters *params, dest->compress_threads = params->compress_threads; } +if (params->has_compress_with_qat) { + dest->compress_with_qat = params->compress_with_qat; + } +if (params->has_compress_wait_thread) { dest->compress_wait_thread = params->compress_wait_thread; }
@@ -1597,6 +1603,10 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp) s->parameters.compress_threads = params->compress_threads; } +if (params->has_compress_with_qat) { + s->parameters.compress_with_qat = params->compress_with_qat; + } +if (params->has_compress_wait_thread) { s->parameters.compress_wait_thread = params->compress_wait_thread; }
@@ -2421,6 +2431,15 @@ bool migrate_postcopy_blocktime(void)return s->enabled_capabilities[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME ]; } +bool migrate_compress_with_qat (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->parameters.compress_with_qat; +} +bool migrate_use_compression (void ) {MigrationState *s;
@@ -4164,6 +4183,8 @@ static Property migration_properties[] = {DEFINE_PROP_UINT8 ("x-compress-threads" , MigrationState, parameters.compress_threads,DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT ), +DEFINE_PROP_BOOL ("x-compress-with-qat" , MigrationState, + parameters.compress_with_qat, false),DEFINE_PROP_BOOL ("x-compress-wait-thread" , MigrationState, parameters.compress_wait_thread, true), DEFINE_PROP_UINT8("x-decompress-threads", MigrationState,
@@ -4284,6 +4305,7 @@ static void migration_instance_init(Object *obj)/* Set has_* up only for parameter checks */ params->has_compress_level = true; params->has_compress_threads = true; + params->has_compress_with_qat = true; params->has_decompress_threads = true; params->has_throttle_trigger_threshold = true; params->has_cpu_throttle_initial = true;
migration/migration.h +1 -0
@@ -388,6 +388,7 @@ bool migrate_use_return_path(void);uint64_t ram_get_total_transferred_pages (void );bool migrate_use_compression (void ); +bool migrate_compress_with_qat (void );int migrate_compress_level (void );int migrate_compress_threads (void );int migrate_compress_wait_thread (void );
migration/qemu-file.c +11 -2
@@ -22,6 +22,7 @@* THE SOFTWARE. */ #include "qemu/osdep.h" +#include <qatzip.h> #include <zlib.h> #include "qemu/madvise.h" #include "qemu/error-report.h"
@@ -31,7 +32,8 @@#include "trace.h" #include "qapi/error.h" -#define IO_BUF_SIZE 32768 +/* with qat hw, the io buffer size need to expand */ +#define IO_BUF_SIZE 524288#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)struct QEMUFile {
@@ -46,6 +48,7 @@ struct QEMUFile {when reading */ int buf_index;int buf_size;/* 0 when writing */ +uint8_t buf[IO_BUF_SIZE ];DECLARE_BITMAP (may_free,MAX_IOV_SIZE );
@@ -440,7 +443,8 @@ static int add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size,return 0 ; } -static void add_buf_to_iovec (QEMUFile *f,size_t len) +/*public the function and use it in other source code*/ +void add_buf_to_iovec (QEMUFile *f,size_t len) {if (!add_to_iovec (f, f->buf + f->buf_index, len, false)) { f->buf_index += len;
@@ -450,6 +454,11 @@ static void add_buf_to_iovec(QEMUFile *f, size_t len) } } +uint8_t *qemu_get_pos (QEMUFile *f) +{ +return f->buf + f->buf_index; +} +void qemu_put_buffer_async (QEMUFile *f,const uint8_t *buf,size_t size,bool may_free) {
migration/qemu-file.h +3 -0
@@ -25,6 +25,7 @@#ifndef MIGRATION_QEMU_FILE_H #define MIGRATION_QEMU_FILE_H +#include <qatzip.h> #include <zlib.h> #include "exec/cpu-common.h" #include "io/channel.h"
@@ -137,6 +138,8 @@ bool qemu_file_is_writable(QEMUFile *f);#include "migration/qemu-file-types.h" +void add_buf_to_iovec (QEMUFile *f,size_t len); +uint8_t *qemu_get_pos (QEMUFile *f);size_t qemu_peek_buffer (QEMUFile *f,uint8_t **buf,size_t size,size_t offset);size_t qemu_get_buffer_in_place (QEMUFile *f,uint8_t **buf,size_t size); ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream,
migration/ram.c +637 -134
1,148 lines not on this page · raw message
monitor/hmp-cmds.c +4 -0
@@ -1220,6 +1220,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p->has_compress_threads = true;visit_type_uint8 (v, param, &p->compress_threads, &err);break ; +case MIGRATION_PARAMETER_COMPRESS_WITH_QAT : + p->has_compress_with_qat = true; +visit_type_bool (v, param, &p->compress_with_qat, &err); +break ;case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD : p->has_compress_wait_thread = true;visit_type_bool (v, param, &p->compress_wait_thread, &err);
qapi/migration.json +7 -1
@@ -629,6 +629,8 @@ # no compression, 1 means the best compression speed, and 9 means best # compression ratio which will consume more CPU. # +# @compress-with-qat: compress with qat on and off. +# # @compress-threads: Set compression thread count to be used in live migration, # the compression thread count is an integer between 1 and 255. #
@@ -768,7 +770,7 @@ { 'enum': 'MigrationParameter', 'data': ['announce-initial', 'announce-max', 'announce-rounds', 'announce-step', - 'compress-level', 'compress-threads', 'decompress-threads', + 'compress-level', 'compress-with-qat', 'compress-threads', 'decompress-threads', 'compress-wait-thread', 'throttle-trigger-threshold', 'cpu-throttle-initial', 'cpu-throttle-increment', 'cpu-throttle-tailslow',
@@ -799,6 +801,8 @@ # # @compress-level: compression level # +# @compress-with-qat: compression with qat +# # @compress-threads: compression thread count # # @compress-wait-thread: Controls behavior when all compression threads are
@@ -938,6 +942,7 @@ '*announce-rounds': 'size', '*announce-step': 'size', '*compress-level': 'uint8', + '*compress-with-qat': 'bool', '*compress-threads': 'uint8', '*compress-wait-thread': 'bool', '*decompress-threads': 'uint8',
@@ -1136,6 +1141,7 @@ '*announce-rounds': 'size', '*announce-step': 'size', '*compress-level': 'uint8', + '*compress-with-qat': 'bool', '*compress-threads': 'uint8', '*compress-wait-thread': 'bool', '*decompress-threads': 'uint8',
Signature · 1 line
2.39.1
Hi Dennis,
Thank for this patch.
Quoted 11 lines · dennis.wu
qatzip https://github.com/intel/QATzip is a project that supply the zlib like api with the Intel QAT hardware. compress and decompress performance with small data block (4kb page) is low with qatzip API. so we compose multiple pages into a multi page address structure which is a buffer list, then we compose these pages together and then call compress and decompress. we also expand the
io_buf_sizesince qat is fast have have stress to theIO_BUFF.If there is no QAT hardware, qatzip will fall back to the software with proper congfiguration. that mean if host server
Typo "configuration".
Quoted 8 lines
have the QAT hardware, while destination server don't have QAT, the live migration still work well.
To use the qatzip, one parameter is added in both host and destination side:
(qemu)migrate_set_parametercompress-with-qat 1 if you proper eabled the qatzip, then you can benefit from the QAT accelleration.
"acceleration".
Quoted 2 lines
Since the compress/decompress offloading to the QAT hardware, no CPU resource neede (only a periodomic polling need some CPU
"needed", "periodic"
Quoted 5 lines
resource).
From the performance, with the same threads scale, with QATzip
(HW), the live migration will have 2~4 time of performance.
Quoted 7 lines
plan: so far qatzip API support SVM,but no batch APIs and the requirement is raised. once the batch APIs ready, the perf expect to reach close to 10x.
Signed-off-by dennis.wu <[email protected]>update
What do you mean by "update" here?
Please prefix the patch subject with 'migration:'.
Please Cc the maintainers, otherwise your patch won't be reviewed / merged:
$ ./scripts/get_maintainer.pl -f qapi/migration.json Juan Quintela <[email protected]> (maintainer:Migration) "Dr. David Alan Gilbert" <[email protected]> (maintainer:Migration) Eric Blake <[email protected]> (supporter:QAPI Schema) Markus Armbruster <[email protected]> (supporter:QAPI Schema) [email protected] (open list:All patches CC here)
Quoted 16 lines
--- meson.build | 3 +- migration/migration.c | 22 ++ migration/migration.h | 1 + migration/qemu-file.c | 13 +- migration/qemu-file.h | 3 + migration/ram.c | 771 ++++++++++++++++++++++++++++++++++-------- monitor/hmp-cmds.c | 4 + qapi/migration.json | 8 +- 8 files changed, 687 insertions(+), 138 deletions(-)meson.build +0
-0
meson.build if have_system or have_tools · line 467
Quoted 4 lines
meson.build +1
-0@@ -464,6 +464,7 @@ if have_system or have_tools method: 'pkg-config', kwargs: static_kwargs) endif zlib = dependency('zlib', required: true, kwargs: static_kwargs) +qatzip = dependency('qatzip', required: true, method: 'pkg-config', kwargs: static_kwargs)
IIUC when using "required: true", all hosts (and non-Intel ones too) won't be able to build QEMU if libqatzip is not available / installed.
If libqatzip is compatible with pkg-config, you can use "method:
'pkg-config', required: qatzip.found()".
Otherwise better is to provide a generic --enable-qatzip option in meson_options.txt, then you can use "required: get_option('qatzip')" here.
See: https://www.qemu.org/docs/master/devel/build-system.html#stage-2-meson
Quoted 54 lines
meson.build +1
-1libaio = not_found if not get_option('linux_aio').auto() or have_block@@ -3058,7 +3059,7 @@ libmigration = static_library('migration', sources: migration_files + genh, name_suffix: 'fa', build_by_default: false) migration = declare_dependency(link_with: libmigration, - dependencies: [zlib, qom, io]) + dependencies: [qatzip, zlib, qom, io]) softmmu_ss.add(migration) block_ss = block_ss.apply(config_host, strict: false)migration/migration.c +8
-0@@ -2421,6 +2431,15 @@ bool migrate_postcopy_blocktime(void)return s->enabled_capabilities[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME ]; } +bool migrate_compress_with_qat (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->parameters.compress_with_qat; +}migration/migration.h +1
-0@@ -388,6 +388,7 @@ bool migrate_use_return_path(void);uint64_t ram_get_total_transferred_pages (void );bool migrate_use_compression (void ); +bool migrate_compress_with_qat (void );int migrate_compress_level (void );int migrate_compress_threads (void );int migrate_compress_wait_thread (void );migration/qemu-file.c +1
-0@@ -22,6 +22,7 @@* THE SOFTWARE. */ #include "qemu/osdep.h" +#include <qatzip.h> #include <zlib.h> #include "qemu/madvise.h" #include "qemu/error-report.h"
migration/qemu-file.c line 35
Quoted 5 lines
migration/qemu-file.c +1
-1@@ -31,7 +32,8 @@#include "trace.h" #include "qapi/error.h" -#define IO_BUF_SIZE 32768 +/* with qat hw, the io buffer size need to expand */
No need to explain what you do in the commited code.
migration/qemu-file.c line 36
Quoted 1 line
migration/qemu-file.c +1
-0+#define IO_BUF_SIZE 524288
(512 * KiB)
But it might be worth considering moving that buffer to the heap, and allocating 32/512KiB depending on migrate_compress_with_qat().
Quoted 12 lines
migration/qemu-file.c +1
-0#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)struct QEMUFile {@@ -46,6 +48,7 @@ struct QEMUFile {when reading */ int buf_index;int buf_size;/* 0 when writing */ +uint8_t buf[IO_BUF_SIZE ];DECLARE_BITMAP (may_free,MAX_IOV_SIZE );
migration/qemu-file.c static int add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size, · line 446
Quoted 5 lines
migration/qemu-file.c +1
-1@@ -440,7 +443,8 @@ static int add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size,return 0 ; } -static void add_buf_to_iovec (QEMUFile *f,size_t len) +/*public the function and use it in other source code*/
No need to explain what you do in the commited code.
Quoted 21 lines
migration/qemu-file.c +6
-0+void add_buf_to_iovec (QEMUFile *f,size_t len) {if (!add_to_iovec (f, f->buf + f->buf_index, len, false)) { f->buf_index += len;@@ -450,6 +454,11 @@ static void add_buf_to_iovec(QEMUFile *f, size_t len) } } +uint8_t *qemu_get_pos (QEMUFile *f) +{ +return f->buf + f->buf_index; +} +void qemu_put_buffer_async (QEMUFile *f,const uint8_t *buf,size_t size,bool may_free) {migration/qemu-file.h +0
-0
migration/qemu-file.h line 28
Quoted 4 lines
migration/qemu-file.h +1
-0@@ -25,6 +25,7 @@#ifndef MIGRATION_QEMU_FILE_H #define MIGRATION_QEMU_FILE_H +#include <qatzip.h>
Surely this header needs to be guarded with some #ifdef'ry, maybe CONFIG_LIBQATZIP.
Quoted 16 lines
migration/qemu-file.h +2
-0#include <zlib.h> #include "exec/cpu-common.h" #include "io/channel.h" @@ -137,6 +138,8 @@ bool qemu_file_is_writable(QEMUFile *f);#include "migration/qemu-file-types.h" +void add_buf_to_iovec (QEMUFile *f,size_t len); +uint8_t *qemu_get_pos (QEMUFile *f);size_t qemu_peek_buffer (QEMUFile *f,uint8_t **buf,size_t size,size_t offset);size_t qemu_get_buffer_in_place (QEMUFile *f,uint8_t **buf,size_t size); ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream,migration/ram.c +0
-0
[...]
migration/ram.c static void compress_threads_save_cleanup(void) · line 617
Quoted 12 lines
migration/ram.c +6
-2@@ -527,8 +609,16 @@ static void compress_threads_save_cleanup(void)qemu_thread_join (compress_threads + i);qemu_mutex_destroy (&comp_param[i].mutex);qemu_cond_destroy (&comp_param[i].cond); -deflateEnd (&comp_param[i].stream); -g_free (comp_param[i].originbuf); +/* call deflateEnd or qzTeardownSession, qzClose */ +if (migrate_compress_with_qat ()) { +qzTeardownSession (&comp_param[i].qzsess); +qzClose (&comp_param[i].qzsess); +qzFree (comp_param[i].compbuf); +qzFree (comp_param[i].decompbuf);
You need to guard for CONFIG_LIBQATZIP somewhere, otherwise this won't build on hosts / OSes where libqatzip is not available / installed.
[...]
qapi/migration.json line 632
Quoted 7 lines
qapi/migration.json +1
-0@@ -629,6 +629,8 @@ # no compression, 1 means the best compression speed, and 9 means best # compression ratio which will consume more CPU. # +# @compress-with-qat: compress with qat on and off.
Missing "(since 8.1)" tag.
Quoted 13 lines
qapi/migration.json +1
-1# @compress-threads: Set compression thread count to be used in live migration, # the compression thread count is an integer between 1 and 255. #@@ -768,7 +770,7 @@ { 'enum': 'MigrationParameter', 'data': ['announce-initial', 'announce-max', 'announce-rounds', 'announce-step', - 'compress-level', 'compress-threads', 'decompress-threads', + 'compress-level', 'compress-with-qat', 'compress-threads', 'decompress-threads', 'compress-wait-thread', 'throttle-trigger-threshold', 'cpu-throttle-initial', 'cpu-throttle-increment', 'cpu-throttle-tailslow',
qapi/migration.json line 804
Quoted 4 lines
qapi/migration.json +1
-0@@ -799,6 +801,8 @@ # # @compress-level: compression level # +# @compress-with-qat: compression with qat
Missing "(since 8.1)" tag.
qapi/migration.json line 808
Quoted 3 lines
qapi/migration.json +0
-0# @compress-threads: compression thread count # # @compress-wait-thread: Controls behavior when all compression threads are
You can open a free GitLab account to run QEMU CI tests and check your patch works on all supported configurations, see:
https://wiki.qemu.org/Testing/CI/GitLabCI
https://www.qemu.org/docs/master/devel/ci.html
Also, consider adding a test for this qatzip feature. See:
- tests/avocado/migration.py
- tests/qtest/migration-test.c
Regards,
Phil.