From nobody Sun Nov 9 11:51:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550680218504888.3773552248072; Wed, 20 Feb 2019 08:30:18 -0800 (PST) Received: from localhost ([127.0.0.1]:42217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUlC-0004jS-AY for importer@patchew.org; Wed, 20 Feb 2019 11:30:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwULS-0007tX-5n for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:03:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwULP-0003zE-He for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:03:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwULP-0003sv-54 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:03:35 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75EDBC007351 for ; Wed, 20 Feb 2019 12:58:42 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-2.ams2.redhat.com [10.36.117.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD31760139; Wed, 20 Feb 2019 12:58:40 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 13:57:53 +0100 Message-Id: <20190220125755.3906-2-quintela@redhat.com> In-Reply-To: <20190220125755.3906-1-quintela@redhat.com> References: <20190220125755.3906-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 20 Feb 2019 12:58:42 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/3] migration: Add multifd-compress parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela --- hmp.c | 17 +++++++++++++++++ hw/core/qdev-properties.c | 11 +++++++++++ include/hw/qdev-properties.h | 1 + migration/migration.c | 25 +++++++++++++++++++++++++ migration/migration.h | 1 + qapi/common.json | 15 +++++++++++++++ qapi/migration.json | 20 ++++++++++++++++---- 7 files changed, 86 insertions(+), 4 deletions(-) diff --git a/hmp.c b/hmp.c index 34edad6ea3..abbd49ec17 100644 --- a/hmp.c +++ b/hmp.c @@ -422,6 +422,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QD= ict *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_COMPRESS), + MultifdCompress_str(params->multifd_compress)); monitor_printf(mon, "%s: %" PRIu64 "\n", MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), params->xbzrle_cache_size); @@ -1690,6 +1693,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) MigrateSetParameters *p =3D g_new0(MigrateSetParameters, 1); uint64_t valuebw =3D 0; uint64_t cache_size; + int compress_type; Error *err =3D NULL; int val, ret; =20 @@ -1769,6 +1773,19 @@ void hmp_migrate_set_parameter(Monitor *mon, const Q= Dict *qdict) p->has_multifd_channels =3D true; visit_type_int(v, param, &p->multifd_channels, &err); break; + case MIGRATION_PARAMETER_MULTIFD_COMPRESS: + p->has_multifd_compress =3D true; + visit_type_enum(v, param, &compress_type, + &MultifdCompress_lookup, &err); + if (err) { + break; + } + if (compress_type < 0 || compress_type > MULTIFD_COMPRESS__MAX) { + error_setg(&err, "Invalid multifd_compress option %s", valuest= r); + break; + } + p->multifd_compress =3D compress_type; + break; case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: p->has_xbzrle_cache_size =3D true; visit_type_size(v, param, &cache_size, &err); diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 5da1439a8b..7c8e71532f 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -645,6 +645,17 @@ const PropertyInfo qdev_prop_fdc_drive_type =3D { .set_default_value =3D set_default_value_enum, }; =20 +/* --- MultifdCompress --- */ + +const PropertyInfo qdev_prop_multifd_compress =3D { + .name =3D "MultifdCompress", + .description =3D "multifd_compress values", + .enum_table =3D &MultifdCompress_lookup, + .get =3D get_enum, + .set =3D set_enum, + .set_default_value =3D set_default_value_enum, +}; + /* --- pci address --- */ =20 /* diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index b6758c852e..ac452d8f2c 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -23,6 +23,7 @@ extern const PropertyInfo qdev_prop_tpm; extern const PropertyInfo qdev_prop_ptr; extern const PropertyInfo qdev_prop_macaddr; extern const PropertyInfo qdev_prop_on_off_auto; +extern const PropertyInfo qdev_prop_multifd_compress; extern const PropertyInfo qdev_prop_losttickpolicy; extern const PropertyInfo qdev_prop_blockdev_on_error; extern const PropertyInfo qdev_prop_bios_chs_trans; diff --git a/migration/migration.c b/migration/migration.c index f246519ec8..568ec8530f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -81,6 +81,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_COMPRESS false =20 /* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit. @@ -748,6 +749,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) params->block_incremental =3D s->parameters.block_incremental; params->has_multifd_channels =3D true; params->multifd_channels =3D s->parameters.multifd_channels; + params->has_multifd_compress =3D true; + params->multifd_compress =3D s->parameters.multifd_compress; params->has_xbzrle_cache_size =3D true; params->xbzrle_cache_size =3D s->parameters.xbzrle_cache_size; params->has_max_postcopy_bandwidth =3D true; @@ -1191,6 +1194,9 @@ static void migrate_params_test_apply(MigrateSetParam= eters *params, if (params->has_multifd_channels) { dest->multifd_channels =3D params->multifd_channels; } + if (params->has_multifd_compress) { + dest->multifd_compress =3D params->multifd_compress; + } if (params->has_xbzrle_cache_size) { dest->xbzrle_cache_size =3D params->xbzrle_cache_size; } @@ -1269,6 +1275,9 @@ static void migrate_params_apply(MigrateSetParameters= *params, Error **errp) if (params->has_multifd_channels) { s->parameters.multifd_channels =3D params->multifd_channels; } + if (params->has_multifd_compress) { + s->parameters.multifd_compress =3D params->multifd_compress; + } if (params->has_xbzrle_cache_size) { s->parameters.xbzrle_cache_size =3D params->xbzrle_cache_size; xbzrle_cache_resize(params->xbzrle_cache_size, errp); @@ -2008,6 +2017,15 @@ bool migrate_use_multifd(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_MULTIFD]; } =20 +bool migrate_use_multifd_zlib(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->parameters.multifd_compress =3D=3D MULTIFD_COMPRESS_ZLIB; +} + bool migrate_pause_before_switchover(void) { MigrationState *s; @@ -3220,6 +3238,9 @@ void migration_global_dump(Monitor *mon) #define DEFINE_PROP_MIG_CAP(name, x) \ DEFINE_PROP_BOOL(name, MigrationState, enabled_capabilities[x], false) =20 +#define DEFINE_PROP_MULTIFD_COMPRESS(_n, _s, _f, _d) \ + DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_multifd_compress, Multifd= Compress) + static Property migration_properties[] =3D { DEFINE_PROP_BOOL("store-global-state", MigrationState, store_global_state, true), @@ -3260,6 +3281,9 @@ static Property migration_properties[] =3D { DEFINE_PROP_UINT8("multifd-channels", MigrationState, parameters.multifd_channels, DEFAULT_MIGRATE_MULTIFD_CHANNELS), + DEFINE_PROP_MULTIFD_COMPRESS("multifd-compress", MigrationState, + parameters.multifd_compress, + DEFAULT_MIGRATE_MULTIFD_COMPRESS), DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState, parameters.xbzrle_cache_size, DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE), @@ -3337,6 +3361,7 @@ static void migration_instance_init(Object *obj) params->has_x_checkpoint_delay =3D true; params->has_block_incremental =3D true; params->has_multifd_channels =3D true; + params->has_multifd_compress =3D true; params->has_xbzrle_cache_size =3D true; params->has_max_postcopy_bandwidth =3D true; params->has_max_cpu_throttle =3D true; diff --git a/migration/migration.h b/migration/migration.h index 7e03643683..646614f71b 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -267,6 +267,7 @@ bool migrate_dirty_bitmaps(void); =20 bool migrate_auto_converge(void); bool migrate_use_multifd(void); +bool migrate_use_multifd_zlib(void); bool migrate_pause_before_switchover(void); int migrate_multifd_channels(void); =20 diff --git a/qapi/common.json b/qapi/common.json index 99d313ef3b..ccdd58d21b 100644 --- a/qapi/common.json +++ b/qapi/common.json @@ -193,3 +193,18 @@ 'ppc64', 'riscv32', 'riscv64', 's390x', 'sh4', 'sh4eb', 'sparc', 'sparc64', 'tricore', 'unicore32', 'x86_64', 'xtensa', 'xtensaeb' ] } + +## +# @MultifdCompress: +# +# An enumeration of multifd compression. +# +# @none: no compression. +# +# @zlib: Compress using zlib. +# +# Since: 3.1 +# +## +{ 'enum': 'MultifdCompress', + 'data': [ 'none', 'zlib' ] } diff --git a/qapi/migration.json b/qapi/migration.json index c202703889..a882fc0823 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -558,6 +558,10 @@ # # @max-cpu-throttle: maximum cpu throttle percentage. # Defaults to 99. (Since 3.1) +# +# @multifd-compress: What compression method to use. +# Defaults to none. (Since 4.0) +# # Since: 2.4 ## { 'enum': 'MigrationParameter', @@ -568,7 +572,7 @@ 'downtime-limit', 'x-checkpoint-delay', 'block-incremental', 'multifd-channels', 'xbzrle-cache-size', 'max-postcopy-bandwidth', - 'max-cpu-throttle' ] } + 'max-cpu-throttle', 'multifd-compress' ] } =20 ## # @MigrateSetParameters: @@ -644,7 +648,10 @@ # (Since 3.0) # # @max-cpu-throttle: maximum cpu throttle percentage. -# The default value is 99. (Since 3.1) +# The default value is 99. (Since 4.0) +# +# @multifd-compress: What compression method to use. +# Defaults to none. (Since 4.0) # # Since: 2.4 ## @@ -666,7 +673,8 @@ '*multifd-channels': 'int', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle': 'int' } } + '*max-cpu-throttle': 'int', + '*multifd-compress': 'MultifdCompress' } } =20 ## # @migrate-set-parameters: @@ -760,6 +768,9 @@ # Defaults to 99. # (Since 3.1) # +# @multifd-compress: What compression method to use. +# Defaults to none. (Since 4.0) +# # Since: 2.4 ## { 'struct': 'MigrationParameters', @@ -778,7 +789,8 @@ '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle':'uint8'} } + '*max-cpu-throttle': 'uint8', + '*multifd-compress': 'MultifdCompress' } } =20 ## # @query-migrate-parameters: --=20 2.20.1 From nobody Sun Nov 9 11:51:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550679933228539.7747037104946; Wed, 20 Feb 2019 08:25:33 -0800 (PST) Received: from localhost ([127.0.0.1]:42053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUgY-0000m5-3t for importer@patchew.org; Wed, 20 Feb 2019 11:25:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU7v-0004CW-WF for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:49:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwU7u-0005Xn-QT for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:49:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwU7s-0005TX-I0 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:49:38 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3805889C40 for ; Wed, 20 Feb 2019 12:58:44 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-2.ams2.redhat.com [10.36.117.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE23660141; Wed, 20 Feb 2019 12:58:42 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 13:57:54 +0100 Message-Id: <20190220125755.3906-3-quintela@redhat.com> In-Reply-To: <20190220125755.3906-1-quintela@redhat.com> References: <20190220125755.3906-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 20 Feb 2019 12:58:44 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/3] multifd: compression support variables X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela --- migration/ram.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index d57db00ce4..7de27e1a35 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -597,6 +597,12 @@ typedef struct { uint64_t num_pages; /* syncs main thread and channels */ QemuSemaphore sem_sync; + /* stream for compression */ + z_stream zs; + /* compressed buffer */ + uint8_t *zbuff; + /* size of compressed buffer */ + uint32_t zbuff_len; } MultiFDSendParams; =20 typedef struct { @@ -632,6 +638,12 @@ typedef struct { uint64_t num_pages; /* syncs main thread and channels */ QemuSemaphore sem_sync; + /* stream for compression */ + z_stream zs; + /* compressed buffer */ + uint8_t *zbuff; + /* size of compressed buffer */ + uint32_t zbuff_len; } MultiFDRecvParams; =20 static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) @@ -969,6 +981,9 @@ void multifd_save_cleanup(void) p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; + deflateEnd(&p->zs); + g_free(p->zbuff); + p->zbuff =3D NULL; } qemu_sem_destroy(&multifd_send_state->channels_ready); qemu_sem_destroy(&multifd_send_state->sem_sync); @@ -1132,6 +1147,7 @@ int multifd_save_setup(void) =20 for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; + z_stream *zs =3D &p->zs; =20 qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); @@ -1145,6 +1161,17 @@ int multifd_save_setup(void) p->packet =3D g_malloc0(p->packet_len); p->name =3D g_strdup_printf("multifdsend_%d", i); socket_send_channel_create(multifd_new_send_channel_async, p); + zs->zalloc =3D Z_NULL; + zs->zfree =3D Z_NULL; + zs->opaque =3D Z_NULL; + if (deflateInit(zs, migrate_compress_level()) !=3D Z_OK) { + printf("deflate init failed\n"); + return -1; + } + /* We will never have more than page_count pages */ + p->zbuff_len =3D page_count * qemu_target_page_size(); + p->zbuff_len *=3D 2; + p->zbuff =3D g_malloc0(p->zbuff_len); } return 0; } @@ -1212,6 +1239,9 @@ int multifd_load_cleanup(Error **errp) p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; + inflateEnd(&p->zs); + g_free(p->zbuff); + p->zbuff =3D NULL; } qemu_sem_destroy(&multifd_recv_state->sem_sync); g_free(multifd_recv_state->params); @@ -1330,6 +1360,7 @@ int multifd_load_setup(void) =20 for (i =3D 0; i < thread_count; i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + z_stream *zs =3D &p->zs; =20 qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem_sync, 0); @@ -1339,6 +1370,21 @@ int multifd_load_setup(void) + sizeof(ram_addr_t) * page_count; p->packet =3D g_malloc0(p->packet_len); p->name =3D g_strdup_printf("multifdrecv_%d", i); + + zs->zalloc =3D Z_NULL; + zs->zfree =3D Z_NULL; + zs->opaque =3D Z_NULL; + zs->avail_in =3D 0; + zs->next_in =3D Z_NULL; + if (inflateInit(zs) !=3D Z_OK) { + printf("inflate init failed\n"); + return -1; + } + /* We will never have more than page_count pages */ + p->zbuff_len =3D page_count * qemu_target_page_size(); + /* We know compression "could" use more space */ + p->zbuff_len *=3D 2; + p->zbuff =3D g_malloc0(p->zbuff_len); } return 0; } --=20 2.20.1 From nobody Sun Nov 9 11:51:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155068105702232.712841613905084; Wed, 20 Feb 2019 08:44:17 -0800 (PST) Received: from localhost ([127.0.0.1]:42575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUyj-00016g-UT for importer@patchew.org; Wed, 20 Feb 2019 11:44:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUSE-0006GQ-E5 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:10:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwUSB-000792-Ln for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:10:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35204) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwUSB-0006ya-7G for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:10:35 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 424C273A91 for ; Wed, 20 Feb 2019 12:58:53 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-2.ams2.redhat.com [10.36.117.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D542600C0; Wed, 20 Feb 2019 12:58:44 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 13:57:55 +0100 Message-Id: <20190220125755.3906-4-quintela@redhat.com> In-Reply-To: <20190220125755.3906-1-quintela@redhat.com> References: <20190220125755.3906-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Feb 2019 12:58:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/3] multifd: Start of zlib compression code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This is still work in progress. It is already faster that normal compression code inside qemu. It don't do any unnecesary copies. And as packages are bigger, we get better compression. Signed-off-by: Juan Quintela --- hmp.c | 6 ++- migration/ram.c | 96 ++++++++++++++++++++++++++++++++++++++++-- migration/trace-events | 2 +- 3 files changed, 97 insertions(+), 7 deletions(-) diff --git a/hmp.c b/hmp.c index abbd49ec17..7c1ad2376d 100644 --- a/hmp.c +++ b/hmp.c @@ -1789,8 +1789,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const Q= Dict *qdict) case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: p->has_xbzrle_cache_size =3D true; visit_type_size(v, param, &cache_size, &err); - if (err || cache_size > INT64_MAX - || (size_t)cache_size !=3D cache_size) { + if (err) { + break; + } + if (cache_size > INT64_MAX || (size_t)cache_size !=3D cache_size) { error_setg(&err, "Invalid size %s", valuestr); break; } diff --git a/migration/ram.c b/migration/ram.c index 7de27e1a35..feb857d395 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -519,6 +519,7 @@ exit: #define MULTIFD_VERSION 1 =20 #define MULTIFD_FLAG_SYNC (1 << 0) +#define MULTIFD_FLAG_ZLIB (1 << 1) =20 /* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024) @@ -1031,6 +1032,7 @@ static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; Error *local_err =3D NULL; + z_stream *zs =3D &p->zs; int ret; =20 trace_multifd_send_thread_start(p->id); @@ -1050,8 +1052,43 @@ static void *multifd_send_thread(void *opaque) uint32_t used =3D p->pages->used; uint64_t packet_num =3D p->packet_num; uint32_t flags =3D p->flags; + struct iovec *iov =3D p->pages->iov; =20 p->next_packet_size =3D used * qemu_target_page_size(); + + if (used && migrate_use_multifd_zlib()) { + uint32_t in_size =3D used * qemu_target_page_size(); + uint32_t out_size =3D 0; + int i; + + for (i =3D 0; i < used; i++ ) { + uint32_t available =3D p->zbuff_len - out_size; + int flush =3D Z_NO_FLUSH; + + if (i =3D=3D used - 1) { + flush =3D Z_SYNC_FLUSH; + } + + zs->avail_in =3D iov[i].iov_len; + zs->next_in =3D iov[i].iov_base; + + zs->avail_out =3D available; + zs->next_out =3D p->zbuff + out_size; + + ret =3D deflate(zs, flush); + if (ret !=3D Z_OK) { + printf("problem with deflate? %d\n", ret); + qemu_mutex_unlock(&p->mutex); + break; + } + out_size +=3D available - zs->avail_out; + } + printf("%d deflate in %d out %d diff %d\n", + p->id, in_size, out_size, in_size - out_size); + + p->next_packet_size =3D out_size; + } + multifd_send_fill_packet(p); p->flags =3D 0; p->num_packets++; @@ -1069,8 +1106,13 @@ static void *multifd_send_thread(void *opaque) } =20 if (used) { - ret =3D qio_channel_writev_all(p->c, p->pages->iov, - used, &local_err); + if (migrate_use_multifd_zlib()) { + ret =3D qio_channel_write_all(p->c, (void *)p->zbuff, + p->next_packet_size, &local= _err); + } else { + ret =3D qio_channel_writev_all(p->c, p->pages->iov, + used, &local_err); + } if (ret !=3D 0) { break; } @@ -1283,6 +1325,7 @@ static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; Error *local_err =3D NULL; + z_stream *zs =3D &p->zs; int ret; =20 trace_multifd_recv_thread_start(p->id); @@ -1317,8 +1360,53 @@ static void *multifd_recv_thread(void *opaque) qemu_mutex_unlock(&p->mutex); =20 if (used) { - ret =3D qio_channel_readv_all(p->c, p->pages->iov, - used, &local_err); + uint32_t in_size =3D p->next_packet_size; + uint32_t out_size =3D 0; + uint32_t expected_size =3D used * qemu_target_page_size(); + int i; + + if (migrate_use_multifd_zlib()) { + ret =3D qio_channel_read_all(p->c, (void *)p->zbuff, + in_size, &local_err); + + if (ret !=3D 0) { + break; + } + + zs->avail_in =3D in_size; + zs->next_in =3D p->zbuff; + + for (i =3D 0; i < used; i++ ) { + struct iovec *iov =3D &p->pages->iov[i]; + int flush =3D Z_NO_FLUSH; + + if (i =3D=3D used - 1) { + flush =3D Z_SYNC_FLUSH; + } + + zs->avail_out =3D iov->iov_len; + zs->next_out =3D iov->iov_base; + + ret =3D inflate(zs, flush); + if (ret !=3D Z_OK) { + printf("%d: problem with inflate? %d\n", p->id, re= t); + qemu_mutex_unlock(&p->mutex); + break; + } + out_size +=3D iov->iov_len; + } + + printf("%d: out_size =3D %d, in_size =3D %d, expected_size= =3D %d avail_in: %d\n", + p->id, out_size, in_size, expected_size, zs->avail_= in); + if (out_size !=3D expected_size) { + printf("out size %d expected size %d\n", + out_size, expected_size); + break; + } + } else { + ret =3D qio_channel_readv_all(p->c, p->pages->iov, + used, &local_err); + } if (ret !=3D 0) { break; } diff --git a/migration/trace-events b/migration/trace-events index a11e66e1d9..8aaae32e67 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -77,7 +77,7 @@ get_queued_page_not_dirty(const char *block_name, uint64_= t tmp_offset, unsigned migration_bitmap_sync_start(void) "" migration_bitmap_sync_end(uint64_t dirty_pages) "dirty_pages %" PRIu64 migration_throttle(void) "" -multifd_recv(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flag= s, uint32_t next_packet_size) "channel %d packet number %" PRIu64 " pages %= d flags 0x%x next packet size %d" +multifd_recv(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flag= s, uint32_t next_packet_size) "channel %d packet_num %" PRIu64 " pages %d f= lags 0x%x next packet size %d" multifd_recv_sync_main(long packet_num) "packet num %ld" multifd_recv_sync_main_signal(uint8_t id) "channel %d" multifd_recv_sync_main_wait(uint8_t id) "channel %d" --=20 2.20.1