From nobody Fri May 3 17:52:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604913307; cv=none; d=zohomail.com; s=zohoarc; b=cLTpMRnSZ76Q5QhKKqD46/ThPJfsSVAr+sqSI8lzcgMatjtT61dCqcANGPekbgBArNjgb7EHC+7l//9p3dBDCrlHIjWUaJSKr0cJC79sFiGXwE7dBq0gogH3visTwXTdU3tB+gHpDIQo7sIZklRXXWIW6vrBHQrH5WsDVSCqvbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604913307; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=u3uRdPwyKcHd+INumF3hLRKQlZup9yjT6UJsBUR9lpg=; b=EC93CVoex1LzJHoWLs3D6VWSjah3jYoA4A4hDWCBbZUwhieyeBSvJMR6O/eT0xIBDdTMCX4sMK6VldCkPe5OGZFDuceRxqdZd85VSTpBFqb+0FHTElD+9WZ+fMgmwqNxsSpo8Edmg8Tl13JohtwmfQKCcg2A2nHojulUxbeHEWg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604913307010300.89568001538225; Mon, 9 Nov 2020 01:15:07 -0800 (PST) Received: from localhost ([::1]:59462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kc3GT-0002bL-Qn for importer@patchew.org; Mon, 09 Nov 2020 04:15:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Ay-0004RO-M2 for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:24 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2132) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Av-0006xn-Pv for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:24 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CV4tQ08HHz74SM; Mon, 9 Nov 2020 17:09:02 +0800 (CST) Received: from localhost (10.174.186.67) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 17:09:02 +0800 From: Zeyu Jin To: , Subject: [RFC PATCH 1/6] migration: Add multi-thread compress method Date: Mon, 9 Nov 2020 17:08:45 +0800 Message-ID: <20201109090850.2424-2-jinzeyu@huawei.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201109090850.2424-1-jinzeyu@huawei.com> References: <20201109090850.2424-1-jinzeyu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.186.67] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=45.249.212.35; envelope-from=jinzeyu@huawei.com; helo=szxga07-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 04:09:09 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ying Fang , qemu-devel@nongnu.org, Zeyu Jin , zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" A multi-thread compress method parameter is added to hold the method we are going to use. By default the 'zlib' method is used to maintain the compatibility as before. Signed-off-by: Zeyu Jin Signed-off-by: Ying Fang --- hw/core/qdev-properties-system.c | 11 +++++++++++ include/hw/qdev-properties.h | 4 ++++ migration/migration.c | 15 +++++++++++++++ monitor/hmp-cmds.c | 12 ++++++++++++ qapi/migration.json | 26 +++++++++++++++++++++++++- 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index b81a4e8d14..d757b2cd70 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -663,6 +663,17 @@ const PropertyInfo qdev_prop_multifd_compression =3D { .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 +/* --- CompressMethod --- */ +const PropertyInfo qdev_prop_compress_method =3D { + .name =3D "CompressMethod", + .description =3D "multi-thread compression method, " + "zlib", + .enum_table =3D &CompressMethod_lookup, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + /* --- Reserved Region --- */ =20 /* diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 4437450065..4a943f7e80 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -23,6 +23,7 @@ extern const PropertyInfo qdev_prop_macaddr; extern const PropertyInfo qdev_prop_reserved_region; extern const PropertyInfo qdev_prop_on_off_auto; extern const PropertyInfo qdev_prop_multifd_compression; +extern const PropertyInfo qdev_prop_compress_method; extern const PropertyInfo qdev_prop_losttickpolicy; extern const PropertyInfo qdev_prop_blockdev_on_error; extern const PropertyInfo qdev_prop_bios_chs_trans; @@ -193,6 +194,9 @@ extern const PropertyInfo qdev_prop_pcie_link_width; #define DEFINE_PROP_MULTIFD_COMPRESSION(_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_multifd_compression, \ MultiFDCompression) +#define DEFINE_PROP_COMPRESS_METHOD(_n, _s, _f, _d) \ + DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_compress_method, \ + CompressMethod) #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ LostTickPolicy) diff --git a/migration/migration.c b/migration/migration.c index 3263aa55a9..d0da95fc0d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -83,6 +83,7 @@ #define DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT 2 /*0: means nocompress, 1: best speed, ... 9: best compress ratio */ #define DEFAULT_MIGRATE_COMPRESS_LEVEL 1 +#define DEFAULT_MIGRATE_COMPRESS_METHOD COMPRESS_METHOD_ZLIB /* Define default autoconverge cpu throttle migration parameters */ #define DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD 50 #define DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL 20 @@ -843,6 +844,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) params->compress_wait_thread =3D s->parameters.compress_wait_thread; params->has_decompress_threads =3D true; params->decompress_threads =3D s->parameters.decompress_threads; + params->has_compress_method =3D true; + params->compress_method =3D s->parameters.compress_method; params->has_throttle_trigger_threshold =3D true; params->throttle_trigger_threshold =3D s->parameters.throttle_trigger_= threshold; params->has_cpu_throttle_initial =3D true; @@ -1407,6 +1410,10 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, dest->decompress_threads =3D params->decompress_threads; } =20 + if (params->has_compress_method) { + dest->compress_method =3D params->compress_method; + } + if (params->has_throttle_trigger_threshold) { dest->throttle_trigger_threshold =3D params->throttle_trigger_thre= shold; } @@ -1504,6 +1511,10 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) s->parameters.decompress_threads =3D params->decompress_threads; } =20 + if (params->has_compress_method) { + s->parameters.compress_method =3D params->compress_method; + } + if (params->has_throttle_trigger_threshold) { s->parameters.throttle_trigger_threshold =3D params->throttle_trig= ger_threshold; } @@ -3715,6 +3726,9 @@ static Property migration_properties[] =3D { DEFINE_PROP_UINT8("x-decompress-threads", MigrationState, parameters.decompress_threads, DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT), + DEFINE_PROP_COMPRESS_METHOD("compress-method", MigrationState, + parameters.compress_method, + DEFAULT_MIGRATE_COMPRESS_METHOD), DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState, parameters.throttle_trigger_threshold, DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD), @@ -3829,6 +3843,7 @@ static void migration_instance_init(Object *obj) params->has_compress_level =3D true; params->has_compress_threads =3D true; params->has_decompress_threads =3D true; + params->has_compress_method =3D true; params->has_throttle_trigger_threshold =3D true; params->has_cpu_throttle_initial =3D true; params->has_cpu_throttle_increment =3D true; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 56e9bad33d..e771c36e1b 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -419,6 +419,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QD= ict *qdict) MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), params->decompress_threads); assert(params->has_throttle_trigger_threshold); + monitor_printf(mon, "%s: %s\n", + MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_METHOD), + CompressMethod_str(params->compress_method)); monitor_printf(mon, "%s: %u\n", MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_TH= RESHOLD), params->throttle_trigger_threshold); @@ -1281,6 +1284,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; + CompressMethod compress_method; Error *err =3D NULL; int val, ret; =20 @@ -1306,6 +1310,14 @@ void hmp_migrate_set_parameter(Monitor *mon, const Q= Dict *qdict) p->has_decompress_threads =3D true; visit_type_int(v, param, &p->decompress_threads, &err); break; + case MIGRATION_PARAMETER_COMPRESS_METHOD: + p->has_compress_method =3D true; + visit_type_CompressMethod(v, param, &compress_method, &err); + if (err) { + break; + } + p->compress_method =3D compress_method; + break; case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD: p->has_throttle_trigger_threshold =3D true; visit_type_int(v, param, &p->throttle_trigger_threshold, &err); diff --git a/qapi/migration.json b/qapi/migration.json index 3c75820527..d262683a38 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -525,6 +525,19 @@ 'data': [ 'none', 'zlib', { 'name': 'zstd', 'if': 'defined(CONFIG_ZSTD)' } ] } =20 +## +# @CompressMethod: +# +# An enumeration of multi-thread compression methods. +# +# @zlib: use zlib compression method. +# +# Since: 5.0 +# +## +{ 'enum': 'CompressMethod', + 'data': [ 'zlib' ] } + ## # @BitmapMigrationBitmapAlias: # @@ -599,6 +612,9 @@ # compression, so set the decompress-threads to the n= umber about 1/4 # of compress-threads is adequate. # +# @compress-method: Set compression method to use in multi-thread compress= ion. +# Defaults to none. (Since 5.0) +# # @throttle-trigger-threshold: The ratio of bytes_dirty_period and bytes_x= fer_period # to trigger throttling. It is expressed as p= ercentage. # The default value is 50. (Since 5.0) @@ -722,7 +738,7 @@ 'data': ['announce-initial', 'announce-max', 'announce-rounds', 'announce-step', 'compress-level', 'compress-threads', 'decompress-threads', - 'compress-wait-thread', 'throttle-trigger-threshold', + 'compress-wait-thread', 'compress-method', 'throttle-trigger-th= reshold', 'cpu-throttle-initial', 'cpu-throttle-increment', 'cpu-throttle-tailslow', 'tls-creds', 'tls-hostname', 'tls-authz', 'max-bandwidth', @@ -759,6 +775,9 @@ # # @decompress-threads: decompression thread count # +# @compress-method: Which multi-thread compression method to use. +# Defaults to none. (Since 5.0) +# # @throttle-trigger-threshold: The ratio of bytes_dirty_period and bytes_x= fer_period # to trigger throttling. It is expressed as p= ercentage. # The default value is 50. (Since 5.0) @@ -889,6 +908,7 @@ '*compress-threads': 'int', '*compress-wait-thread': 'bool', '*decompress-threads': 'int', + '*compress-method': 'CompressMethod', '*throttle-trigger-threshold': 'int', '*cpu-throttle-initial': 'int', '*cpu-throttle-increment': 'int', @@ -953,6 +973,9 @@ # # @decompress-threads: decompression thread count # +# @compress-method: Which multi-thread compression method to use. +# Defaults to none. (Since 5.0) +# # @throttle-trigger-threshold: The ratio of bytes_dirty_period and bytes_x= fer_period # to trigger throttling. It is expressed as p= ercentage. # The default value is 50. (Since 5.0) @@ -1083,6 +1106,7 @@ '*compress-threads': 'uint8', '*compress-wait-thread': 'bool', '*decompress-threads': 'uint8', + '*compress-method': 'CompressMethod', '*throttle-trigger-threshold': 'uint8', '*cpu-throttle-initial': 'uint8', '*cpu-throttle-increment': 'uint8', --=20 2.23.0 From nobody Fri May 3 17:52:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604913197; cv=none; d=zohomail.com; s=zohoarc; b=hOYNF6ryoHXHuoIuQ66J2lG2TtRiPWs3cIUTA6YF5qJ7YUcuMxo2Rxpc84+3grMvCesaX+xtEVyaTWM+Yx44CMUmmdKemHcIdjbKdUCNG0jmQezwB8t+ODuDAL9tXpzcD8lIhOu8IuE+QbDjCg9jBucRITljV4g3iuCm3n9EVGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604913197; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cZMyeTkSwr9QJ9kxn3bhi0nwvQTqVfBhuuhkAcTjyhk=; b=SxHILzVXz8I4aWCeAngd3LDQ6xZK+ZbxIjJ1WA0p/H0QD0BRgmUJlmtC8Bemv6M+Xuf6XvR7k7EwzL4nm+z0nl3PY9T36e3OvCy4CVvDzoaBQzbjwrBePlD5LueHt2OMAWvqdazyaisuZJ+mknJJrXQT/rsZ5+w6T1tqVUBRwz0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604913197596707.5128771148437; Mon, 9 Nov 2020 01:13:17 -0800 (PST) Received: from localhost ([::1]:52964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kc3Ei-0008Li-Es for importer@patchew.org; Mon, 09 Nov 2020 04:13:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3B0-0004Ut-HH for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:26 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2084) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Aw-0006yv-U9 for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:26 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CV4tX5ZBWzhjCR; Mon, 9 Nov 2020 17:09:08 +0800 (CST) Received: from localhost (10.174.186.67) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 17:09:02 +0800 From: Zeyu Jin To: , Subject: [RFC PATCH 2/6] migration: Refactoring multi-thread compress migration Date: Mon, 9 Nov 2020 17:08:46 +0800 Message-ID: <20201109090850.2424-3-jinzeyu@huawei.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201109090850.2424-1-jinzeyu@huawei.com> References: <20201109090850.2424-1-jinzeyu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.186.67] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=45.249.212.32; envelope-from=jinzeyu@huawei.com; helo=szxga06-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 04:09:11 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ying Fang , qemu-devel@nongnu.org, Zeyu Jin , zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Code refactor for the compression procedure which includes: 1. Move qemu_compress_data and qemu_put_compression_data from qemu-file.c to ram.c, for the reason that most part of the code logical has nothing to do with qemu-file. Besides, the decompression code is located at ram.c only. 2. Simplify the function input arguments for compression and decompression. Wrap the input into the param structure which already exists. This change a= lso makes the function much more flexible for other compression methods. Signed-off-by: Zeyu Jin Signed-off-by: Ying Fang --- migration/qemu-file.c | 62 ++++++------------------------- migration/qemu-file.h | 4 +- migration/ram.c | 86 ++++++++++++++++++++++++++++++------------- 3 files changed, 75 insertions(+), 77 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index be21518c57..1efb667aa1 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -737,56 +737,6 @@ uint64_t qemu_get_be64(QEMUFile *f) return v; } =20 -/* return the size after compression, or negative value on error */ -static int qemu_compress_data(z_stream *stream, uint8_t *dest, size_t dest= _len, - const uint8_t *source, size_t source_len) -{ - int err; - - err =3D deflateReset(stream); - if (err !=3D Z_OK) { - return -1; - } - - stream->avail_in =3D source_len; - stream->next_in =3D (uint8_t *)source; - stream->avail_out =3D dest_len; - stream->next_out =3D dest; - - err =3D deflate(stream, Z_FINISH); - if (err !=3D Z_STREAM_END) { - return -1; - } - - return stream->next_out - dest; -} - -/* Compress size bytes of data start at p and store the compressed - * data to the buffer of f. - * - * Since the file is dummy file with empty_ops, return -1 if f has no spac= e to - * save the compressed data. - */ -ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream, - const uint8_t *p, size_t size) -{ - ssize_t blen =3D IO_BUF_SIZE - f->buf_index - sizeof(int32_t); - - if (blen < compressBound(size)) { - return -1; - } - - blen =3D qemu_compress_data(stream, f->buf + f->buf_index + sizeof(int= 32_t), - blen, p, size); - if (blen < 0) { - return -1; - } - - qemu_put_be32(f, blen); - add_buf_to_iovec(f, blen); - return blen + sizeof(int32_t); -} - /* Put the data in the buffer of f_src to the buffer of f_des, and * then reset the buf_index of f_src to 0. */ @@ -846,3 +796,15 @@ void qemu_file_set_blocking(QEMUFile *f, bool block) f->ops->set_blocking(f->opaque, block, NULL); } } + +ssize_t qemu_put_compress_start(QEMUFile *f, uint8_t **dest_ptr) +{ + *dest_ptr =3D f->buf + f->buf_index + sizeof(int32_t); + return IO_BUF_SIZE - f->buf_index - sizeof(int32_t); +} + +void qemu_put_compress_end(QEMUFile *f, unsigned int v) +{ + qemu_put_be32(f, v); + add_buf_to_iovec(f, v); +} diff --git a/migration/qemu-file.h b/migration/qemu-file.h index a9b6d6ccb7..1ac1566460 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -138,8 +138,6 @@ bool qemu_file_is_writable(QEMUFile *f); =20 size_t qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t of= fset); 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, - const uint8_t *p, size_t size); int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src); =20 /* @@ -166,6 +164,8 @@ void ram_control_before_iterate(QEMUFile *f, uint64_t f= lags); void ram_control_after_iterate(QEMUFile *f, uint64_t flags); void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data); =20 +ssize_t qemu_put_compress_start(QEMUFile *f, uint8_t **dest_ptr); +void qemu_put_compress_end(QEMUFile *f, unsigned int v); /* Whenever this is found in the data stream, the flags * will be passed to ram_control_load_hook in the incoming-migration * side. This lets before_ram_iterate/after_ram_iterate add diff --git a/migration/ram.c b/migration/ram.c index 2da2b622ab..75504540c9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -453,27 +453,22 @@ static QemuThread *decompress_threads; static QemuMutex decomp_done_lock; static QemuCond decomp_done_cond; =20 -static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *= block, - ram_addr_t offset, uint8_t *source_buf); +static bool do_compress_ram_page(CompressParam *param, RAMBlock *block); =20 static void *do_data_compress(void *opaque) { CompressParam *param =3D opaque; RAMBlock *block; - ram_addr_t offset; bool zero_page; =20 qemu_mutex_lock(¶m->mutex); while (!param->quit) { if (param->block) { block =3D param->block; - offset =3D param->offset; param->block =3D NULL; qemu_mutex_unlock(¶m->mutex); =20 - zero_page =3D do_compress_ram_page(param->file, ¶m->stream, - block, offset, param->originb= uf); - + zero_page =3D do_compress_ram_page(param, block); qemu_mutex_lock(&comp_done_lock); param->done =3D true; param->zero_page =3D zero_page; @@ -1214,28 +1209,73 @@ static int ram_save_multifd_page(RAMState *rs, RAMB= lock *block, return 1; } =20 -static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *= block, - ram_addr_t offset, uint8_t *source_buf) +/* + * Compress size bytes of data start at p and store the compressed + * data to the buffer of f. + * + * Since the file is dummy file with empty_ops, return -1 if f has no spac= e to + * save the compressed data. + */ +static ssize_t qemu_put_compression_data(CompressParam *param, size_t size) +{ + int err; + uint8_t *dest =3D NULL; + z_stream *stream =3D ¶m->stream; + uint8_t *p =3D param->originbuf; + QEMUFile *f =3D f =3D param->file; + ssize_t blen =3D qemu_put_compress_start(f, &dest); + + if (blen < compressBound(size)) { + return -1; + } + + err =3D deflateReset(stream); + if (err !=3D Z_OK) { + return -1; + } + + stream->avail_in =3D size; + stream->next_in =3D p; + stream->avail_out =3D blen; + stream->next_out =3D dest; + + err =3D deflate(stream, Z_FINISH); + if (err !=3D Z_STREAM_END) { + return -1; + } + + blen =3D stream->next_out - dest; + if (blen < 0) { + return -1; + } + + qemu_put_compress_end(f, blen); + return blen + sizeof(int32_t); +} + +static bool do_compress_ram_page(CompressParam *param, RAMBlock *block) { RAMState *rs =3D ram_state; + ram_addr_t offset =3D param->offset; uint8_t *p =3D block->host + (offset & TARGET_PAGE_MASK); bool zero_page =3D false; int ret; =20 - if (save_zero_page_to_file(rs, f, block, offset)) { + if (save_zero_page_to_file(rs, param->file, block, offset)) { zero_page =3D true; goto exit; } =20 - save_page_header(rs, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); + save_page_header(rs, param->file, block, + offset | RAM_SAVE_FLAG_COMPRESS_PAGE); =20 /* * copy it to a internal buffer to avoid it being modified by VM * so that we can catch up the error during compression and * decompression */ - memcpy(source_buf, p, TARGET_PAGE_SIZE); - ret =3D qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_S= IZE); + memcpy(param->originbuf, p, TARGET_PAGE_SIZE); + ret =3D qemu_put_compression_data(param, TARGET_PAGE_SIZE); if (ret < 0) { qemu_file_set_error(migrate_get_current()->to_dst_file, ret); error_report("compressed data failed!"); @@ -2826,19 +2866,20 @@ void ram_handle_compressed(void *host, uint8_t ch, = uint64_t size) =20 /* return the size after decompression, or negative value on error */ static int -qemu_uncompress_data(z_stream *stream, uint8_t *dest, size_t dest_len, - const uint8_t *source, size_t source_len) +qemu_uncompress_data(DecompressParam *param, uint8_t *dest, size_t pagesiz= e) { int err; =20 + z_stream *stream =3D ¶m->stream; + err =3D inflateReset(stream); if (err !=3D Z_OK) { return -1; } =20 - stream->avail_in =3D source_len; - stream->next_in =3D (uint8_t *)source; - stream->avail_out =3D dest_len; + stream->avail_in =3D param->len; + stream->next_in =3D param->compbuf; + stream->avail_out =3D pagesize; stream->next_out =3D dest; =20 err =3D inflate(stream, Z_NO_FLUSH); @@ -2852,22 +2893,17 @@ qemu_uncompress_data(z_stream *stream, uint8_t *des= t, size_t dest_len, static void *do_data_decompress(void *opaque) { DecompressParam *param =3D opaque; - unsigned long pagesize; uint8_t *des; - int len, ret; + int ret; =20 qemu_mutex_lock(¶m->mutex); while (!param->quit) { if (param->des) { des =3D param->des; - len =3D param->len; param->des =3D 0; qemu_mutex_unlock(¶m->mutex); =20 - pagesize =3D TARGET_PAGE_SIZE; - - ret =3D qemu_uncompress_data(¶m->stream, des, pagesize, - param->compbuf, len); + ret =3D qemu_uncompress_data(param, des, TARGET_PAGE_SIZE); if (ret < 0 && migrate_get_current()->decompress_error_check) { error_report("decompress data failed"); qemu_file_set_error(decomp_file, ret); --=20 2.23.0 From nobody Fri May 3 17:52:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604913306; cv=none; d=zohomail.com; s=zohoarc; b=T//aSLN8oG69t5xx1KvRwBfatkFPX+nq9NXP08YhGzJQJvUDokd2yFUbv92jrZoQAna/hpsP2eZdzE5gkIn4zs7crF7KVwLmvZL1fO7F7Fs3Wq3A1i8JZQsMaAmfXsrHTTJoj1cA8x2Qx9cAubSmYTfaC8VxMioo/W7xb2YQWi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604913306; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XaFn7cQ8+U3I/oTBWag0Q82gjt6hxiwXFwyKsma6zdU=; b=UYvCC+f0i0/3PT5tOVB2c48JM4un5uMJ4t+INTtHHnwc22u8X5rR1G5bJS8Q4ovKK5+7t+ujlOZZ9I34fTExK9f+5zaUPCllPn2J09arq5tcG++qWd2iLb+Nhn06f5lNHNV0fVZGiq3i4NToXSiPZ93KgU8xFqWMWxQgFioIYlc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604913306907497.431597984698; Mon, 9 Nov 2020 01:15:06 -0800 (PST) Received: from localhost ([::1]:59482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kc3GT-0002bm-Me for importer@patchew.org; Mon, 09 Nov 2020 04:15:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3B0-0004Vu-Ux for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:26 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Ax-0006yw-7b for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:26 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CV4tX5NtMzhhwr; Mon, 9 Nov 2020 17:09:08 +0800 (CST) Received: from localhost (10.174.186.67) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 17:09:03 +0800 From: Zeyu Jin To: , Subject: [RFC PATCH 3/6] migration: Add multi-thread compress ops Date: Mon, 9 Nov 2020 17:08:47 +0800 Message-ID: <20201109090850.2424-4-jinzeyu@huawei.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201109090850.2424-1-jinzeyu@huawei.com> References: <20201109090850.2424-1-jinzeyu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.186.67] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=45.249.212.32; envelope-from=jinzeyu@huawei.com; helo=szxga06-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 04:09:11 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Zeyu Jin , zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add the MigrationCompressOps and MigrationDecompressOps structures to make the compression method configurable for multi-thread compression migration. Signed-off-by: Zeyu Jin Signed-off-by: Ying Fang parameters.decompress_threads; } =20 +CompressMethod migrate_compress_method(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->parameters.compress_method; +} + bool migrate_dirty_bitmaps(void) { MigrationState *s; diff --git a/migration/migration.h b/migration/migration.h index d096b77f74..e22b2ef840 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -339,6 +339,7 @@ int migrate_compress_level(void); int migrate_compress_threads(void); int migrate_compress_wait_thread(void); int migrate_decompress_threads(void); +CompressMethod migrate_compress_method(void); bool migrate_use_events(void); bool migrate_postcopy_blocktime(void); =20 diff --git a/migration/ram.c b/migration/ram.c index 75504540c9..94a7422204 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -419,8 +419,11 @@ struct CompressParam { ram_addr_t offset; =20 /* internally used fields */ - z_stream stream; uint8_t *originbuf; + + /* for zlib compression */ + z_stream stream; + }; typedef struct CompressParam CompressParam; =20 @@ -432,12 +435,29 @@ struct DecompressParam { void *des; uint8_t *compbuf; int len; + + /* for zlib compression */ z_stream stream; }; typedef struct DecompressParam DecompressParam; =20 +typedef struct { + int (*save_setup)(CompressParam *param); + void (*save_cleanup)(CompressParam *param); + ssize_t (*compress_data)(CompressParam *param, size_t size); +} MigrationCompressOps; + +typedef struct { + int (*load_setup)(DecompressParam *param); + void (*load_cleanup)(DecompressParam *param); + int (*decompress_data)(DecompressParam *param, uint8_t *dest, size_t s= ize); + int (*check_len)(int len); +} MigrationDecompressOps; + static CompressParam *comp_param; static QemuThread *compress_threads; +static MigrationCompressOps *compress_ops; +static MigrationDecompressOps *decompress_ops; /* comp_done_cond is used to wake up the migration thread when * one of the compression threads has finished the compression. * comp_done_lock is used to co-work with comp_done_cond. @@ -455,6 +475,157 @@ static QemuCond decomp_done_cond; =20 static bool do_compress_ram_page(CompressParam *param, RAMBlock *block); =20 +static int zlib_save_setup(CompressParam *param) +{ + if (deflateInit(¶m->stream, + migrate_compress_level()) !=3D Z_OK) { + return -1; + } + + return 0; +} + +static ssize_t zlib_compress_data(CompressParam *param, size_t size) +{ + int err; + uint8_t *dest =3D NULL; + z_stream *stream =3D ¶m->stream; + uint8_t *p =3D param->originbuf; + QEMUFile *f =3D f =3D param->file; + ssize_t blen =3D qemu_put_compress_start(f, &dest); + + if (blen < compressBound(size)) { + return -1; + } + + err =3D deflateReset(stream); + if (err !=3D Z_OK) { + return -1; + } + + stream->avail_in =3D size; + stream->next_in =3D p; + stream->avail_out =3D blen; + stream->next_out =3D dest; + + err =3D deflate(stream, Z_FINISH); + if (err !=3D Z_STREAM_END) { + return -1; + } + + blen =3D stream->next_out - dest; + if (blen < 0) { + return -1; + } + + qemu_put_compress_end(f, blen); + return blen + sizeof(int32_t); +} + +static void zlib_save_cleanup(CompressParam *param) +{ + deflateEnd(¶m->stream); +} + +static int zlib_load_setup(DecompressParam *param) +{ + if (inflateInit(¶m->stream) !=3D Z_OK) { + return -1; + } + + return 0; +} + +static int +zlib_decompress_data(DecompressParam *param, uint8_t *dest, size_t size) +{ + int err; + + z_stream *stream =3D ¶m->stream; + + err =3D inflateReset(stream); + if (err !=3D Z_OK) { + return -1; + } + + stream->avail_in =3D param->len; + stream->next_in =3D param->compbuf; + stream->avail_out =3D size; + stream->next_out =3D dest; + + err =3D inflate(stream, Z_NO_FLUSH); + if (err !=3D Z_STREAM_END) { + return -1; + } + + return stream->total_out; +} + +static void zlib_load_cleanup(DecompressParam *param) +{ + inflateEnd(¶m->stream); +} + +static int zlib_check_len(int len) +{ + return len < 0 || len > compressBound(TARGET_PAGE_SIZE); +} + +static int set_compress_ops(void) +{ + compress_ops =3D g_new0(MigrationCompressOps, 1); + + switch (migrate_compress_method()) { + case COMPRESS_METHOD_ZLIB: + compress_ops->save_setup =3D zlib_save_setup; + compress_ops->save_cleanup =3D zlib_save_cleanup; + compress_ops->compress_data =3D zlib_compress_data; + break; + default: + return -1; + } + + return 0; +} + +static int set_decompress_ops(void) +{ + decompress_ops =3D g_new0(MigrationDecompressOps, 1); + + switch (migrate_compress_method()) { + case COMPRESS_METHOD_ZLIB: + decompress_ops->load_setup =3D zlib_load_setup; + decompress_ops->load_cleanup =3D zlib_load_cleanup; + decompress_ops->decompress_data =3D zlib_decompress_data; + decompress_ops->check_len =3D zlib_check_len; + break; + default: + return -1; + } + + return 0; +} + +static void clean_compress_ops(void) +{ + compress_ops->save_setup =3D NULL; + compress_ops->save_cleanup =3D NULL; + compress_ops->compress_data =3D NULL; + + g_free(compress_ops); + compress_ops =3D NULL; +} + +static void clean_decompress_ops(void) +{ + decompress_ops->load_setup =3D NULL; + decompress_ops->load_cleanup =3D NULL; + decompress_ops->decompress_data =3D NULL; + + g_free(decompress_ops); + decompress_ops =3D NULL; +} + static void *do_data_compress(void *opaque) { CompressParam *param =3D opaque; @@ -511,7 +682,7 @@ 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); + compress_ops->save_cleanup(&comp_param[i]); g_free(comp_param[i].originbuf); qemu_fclose(comp_param[i].file); comp_param[i].file =3D NULL; @@ -522,6 +693,7 @@ static void compress_threads_save_cleanup(void) g_free(comp_param); compress_threads =3D NULL; comp_param =3D NULL; + clean_compress_ops(); } =20 static int compress_threads_save_setup(void) @@ -531,6 +703,12 @@ static int compress_threads_save_setup(void) if (!migrate_use_compression()) { return 0; } + + if (set_compress_ops() < 0) { + clean_compress_ops(); + return -1; + } + thread_count =3D migrate_compress_threads(); compress_threads =3D g_new0(QemuThread, thread_count); comp_param =3D g_new0(CompressParam, thread_count); @@ -542,8 +720,7 @@ static int compress_threads_save_setup(void) goto exit; } =20 - if (deflateInit(&comp_param[i].stream, - migrate_compress_level()) !=3D Z_OK) { + if (compress_ops->save_setup(&comp_param[i]) < 0) { g_free(comp_param[i].originbuf); goto exit; } @@ -1209,50 +1386,6 @@ static int ram_save_multifd_page(RAMState *rs, RAMBl= ock *block, return 1; } =20 -/* - * Compress size bytes of data start at p and store the compressed - * data to the buffer of f. - * - * Since the file is dummy file with empty_ops, return -1 if f has no spac= e to - * save the compressed data. - */ -static ssize_t qemu_put_compression_data(CompressParam *param, size_t size) -{ - int err; - uint8_t *dest =3D NULL; - z_stream *stream =3D ¶m->stream; - uint8_t *p =3D param->originbuf; - QEMUFile *f =3D f =3D param->file; - ssize_t blen =3D qemu_put_compress_start(f, &dest); - - if (blen < compressBound(size)) { - return -1; - } - - err =3D deflateReset(stream); - if (err !=3D Z_OK) { - return -1; - } - - stream->avail_in =3D size; - stream->next_in =3D p; - stream->avail_out =3D blen; - stream->next_out =3D dest; - - err =3D deflate(stream, Z_FINISH); - if (err !=3D Z_STREAM_END) { - return -1; - } - - blen =3D stream->next_out - dest; - if (blen < 0) { - return -1; - } - - qemu_put_compress_end(f, blen); - return blen + sizeof(int32_t); -} - static bool do_compress_ram_page(CompressParam *param, RAMBlock *block) { RAMState *rs =3D ram_state; @@ -1275,7 +1408,7 @@ static bool do_compress_ram_page(CompressParam *param= , RAMBlock *block) * decompression */ memcpy(param->originbuf, p, TARGET_PAGE_SIZE); - ret =3D qemu_put_compression_data(param, TARGET_PAGE_SIZE); + ret =3D compress_ops->compress_data(param, TARGET_PAGE_SIZE); if (ret < 0) { qemu_file_set_error(migrate_get_current()->to_dst_file, ret); error_report("compressed data failed!"); @@ -2864,32 +2997,6 @@ void ram_handle_compressed(void *host, uint8_t ch, u= int64_t size) } } =20 -/* return the size after decompression, or negative value on error */ -static int -qemu_uncompress_data(DecompressParam *param, uint8_t *dest, size_t pagesiz= e) -{ - int err; - - z_stream *stream =3D ¶m->stream; - - err =3D inflateReset(stream); - if (err !=3D Z_OK) { - return -1; - } - - stream->avail_in =3D param->len; - stream->next_in =3D param->compbuf; - stream->avail_out =3D pagesize; - stream->next_out =3D dest; - - err =3D inflate(stream, Z_NO_FLUSH); - if (err !=3D Z_STREAM_END) { - return -1; - } - - return stream->total_out; -} - static void *do_data_decompress(void *opaque) { DecompressParam *param =3D opaque; @@ -2903,7 +3010,7 @@ static void *do_data_decompress(void *opaque) param->des =3D 0; qemu_mutex_unlock(¶m->mutex); =20 - ret =3D qemu_uncompress_data(param, des, TARGET_PAGE_SIZE); + ret =3D decompress_ops->decompress_data(param, des, TARGET_PAG= E_SIZE); if (ret < 0 && migrate_get_current()->decompress_error_check) { error_report("decompress data failed"); qemu_file_set_error(decomp_file, ret); @@ -2973,7 +3080,7 @@ static void compress_threads_load_cleanup(void) qemu_thread_join(decompress_threads + i); qemu_mutex_destroy(&decomp_param[i].mutex); qemu_cond_destroy(&decomp_param[i].cond); - inflateEnd(&decomp_param[i].stream); + decompress_ops->load_cleanup(&decomp_param[i]); g_free(decomp_param[i].compbuf); decomp_param[i].compbuf =3D NULL; } @@ -2982,6 +3089,7 @@ static void compress_threads_load_cleanup(void) decompress_threads =3D NULL; decomp_param =3D NULL; decomp_file =3D NULL; + clean_decompress_ops(); } =20 static int compress_threads_load_setup(QEMUFile *f) @@ -2992,6 +3100,11 @@ static int compress_threads_load_setup(QEMUFile *f) return 0; } =20 + if (set_decompress_ops() < 0) { + clean_decompress_ops(); + return -1; + } + thread_count =3D migrate_decompress_threads(); decompress_threads =3D g_new0(QemuThread, thread_count); decomp_param =3D g_new0(DecompressParam, thread_count); @@ -2999,7 +3112,7 @@ static int compress_threads_load_setup(QEMUFile *f) qemu_cond_init(&decomp_done_cond); decomp_file =3D f; for (i =3D 0; i < thread_count; i++) { - if (inflateInit(&decomp_param[i].stream) !=3D Z_OK) { + if (decompress_ops->load_setup(&decomp_param[i]) < 0) { goto exit; } =20 @@ -3323,7 +3436,7 @@ static int ram_load_postcopy(QEMUFile *f) case RAM_SAVE_FLAG_COMPRESS_PAGE: all_zero =3D false; len =3D qemu_get_be32(f); - if (len < 0 || len > compressBound(TARGET_PAGE_SIZE)) { + if (decompress_ops->check_len(len)) { error_report("Invalid compressed data length: %d", len); ret =3D -EINVAL; break; @@ -3590,7 +3703,7 @@ static int ram_load_precopy(QEMUFile *f) =20 case RAM_SAVE_FLAG_COMPRESS_PAGE: len =3D qemu_get_be32(f); - if (len < 0 || len > compressBound(TARGET_PAGE_SIZE)) { + if (decompress_ops->check_len(len)) { error_report("Invalid compressed data length: %d", len); ret =3D -EINVAL; break; --=20 2.23.0 From nobody Fri May 3 17:52:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604913061; cv=none; d=zohomail.com; s=zohoarc; b=V20VufKzKGYVRTgeRpSsyBafJpWLJFfUyWJnJ9FhjsWrT1eee+c8lrw/APXkc2okScNrhRCxcAlV2wDd6zRxan7LFHvm7t2ERN2bv2+6bRpKAJDpZ+TmkGDHNNDtRlf3BFDmahS3658QcdiBWvzwXhGHLZEhPwmo+yDcf5dvZpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604913061; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A1c9rt7Dhbt6lacPf4EZwl32CpvniM9pjqVma0synqQ=; b=i10NW/d02unA4AFO9/7kP7KUwChrlWhhoBsiRhsDdK3ajw3wU5KEp3N32ERJ8i2Z4Ylv1MkEP5gIsD38SLRRP34nefbzvnfpUJ1uAUMnYfG0EcmSrXB74dRKq49UpgUBQqWHy5NFiAVgmYT6IGVCxroQqPMpM12OXlz3SoSuc8U= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604913061625601.0112499372316; Mon, 9 Nov 2020 01:11:01 -0800 (PST) Received: from localhost ([::1]:46796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kc3CW-0005hn-GI for importer@patchew.org; Mon, 09 Nov 2020 04:11:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Ax-0004Pd-I0 for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:23 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2511) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3At-0006xo-1g for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:23 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CV4tR0f48zhhGL; Mon, 9 Nov 2020 17:09:03 +0800 (CST) Received: from localhost (10.174.186.67) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 17:09:03 +0800 From: Zeyu Jin To: , Subject: [RFC PATCH 4/6] migration: Add zstd support in multi-thread compression Date: Mon, 9 Nov 2020 17:08:48 +0800 Message-ID: <20201109090850.2424-5-jinzeyu@huawei.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201109090850.2424-1-jinzeyu@huawei.com> References: <20201109090850.2424-1-jinzeyu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.186.67] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=45.249.212.191; envelope-from=jinzeyu@huawei.com; helo=szxga05-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 03:39:34 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ying Fang , qemu-devel@nongnu.org, Zeyu Jin , zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch enables zstd option in multi-thread compression. Signed-off-by: Zeyu Jin Signed-off-by: Ying Fang --- hw/core/qdev-properties-system.c | 2 +- migration/ram.c | 128 ++++++++++++++++++++++++++++++- qapi/migration.json | 2 +- 3 files changed, 129 insertions(+), 3 deletions(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index d757b2cd70..54760d94b3 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -667,7 +667,7 @@ const PropertyInfo qdev_prop_multifd_compression =3D { const PropertyInfo qdev_prop_compress_method =3D { .name =3D "CompressMethod", .description =3D "multi-thread compression method, " - "zlib", + "zlib/zstd", .enum_table =3D &CompressMethod_lookup, .get =3D qdev_propinfo_get_enum, .set =3D qdev_propinfo_set_enum, diff --git a/migration/ram.c b/migration/ram.c index 94a7422204..a732d80db2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -57,6 +57,10 @@ #include "qemu/iov.h" #include "multifd.h" =20 +#ifdef CONFIG_ZSTD +#include +#include +#endif /***********************************************************/ /* ram save/restore */ =20 @@ -424,6 +428,11 @@ struct CompressParam { /* for zlib compression */ z_stream stream; =20 +#ifdef CONFIG_ZSTD + ZSTD_CStream *zstd_cs; + ZSTD_inBuffer in; + ZSTD_outBuffer out; +#endif }; typedef struct CompressParam CompressParam; =20 @@ -438,6 +447,12 @@ struct DecompressParam { =20 /* for zlib compression */ z_stream stream; + +#ifdef CONFIG_ZSTD + ZSTD_DStream *zstd_ds; + ZSTD_inBuffer in; + ZSTD_outBuffer out; +#endif }; typedef struct DecompressParam DecompressParam; =20 @@ -571,6 +586,102 @@ static int zlib_check_len(int len) return len < 0 || len > compressBound(TARGET_PAGE_SIZE); } =20 +#ifdef CONFIG_ZSTD +static int zstd_save_setup(CompressParam *param) +{ + int res; + param->zstd_cs =3D ZSTD_createCStream(); + if (!param->zstd_cs) { + return -1; + } + res =3D ZSTD_initCStream(param->zstd_cs, migrate_compress_level()); + if (ZSTD_isError(res)) { + return -1; + } + return 0; +} +static void zstd_save_cleanup(CompressParam *param) +{ + ZSTD_freeCStream(param->zstd_cs); + param->zstd_cs =3D NULL; +} +static ssize_t zstd_compress_data(CompressParam *param, size_t size) +{ + int ret; + uint8_t *dest =3D NULL; + uint8_t *p =3D param->originbuf; + QEMUFile *f =3D f =3D param->file; + ssize_t blen =3D qemu_put_compress_start(f, &dest); + if (blen < ZSTD_compressBound(size)) { + return -1; + } + param->out.dst =3D dest; + param->out.size =3D blen; + param->out.pos =3D 0; + param->in.src =3D p; + param->in.size =3D size; + param->in.pos =3D 0; + do { + ret =3D ZSTD_compressStream2(param->zstd_cs, ¶m->out, + ¶m->in, ZSTD_e_end); + } while (ret > 0 && (param->in.size - param->in.pos > 0) + && (param->out.size - param->out.pos > 0)); + if (ret > 0 && (param->in.size - param->in.pos > 0)) { + return -1; + } + if (ZSTD_isError(ret)) { + return -1; + } + blen =3D param->out.pos; + qemu_put_compress_end(f, blen); + return blen + sizeof(int32_t); +} +static int zstd_load_setup(DecompressParam *param) +{ + int ret; + param->zstd_ds =3D ZSTD_createDStream(); + if (!param->zstd_ds) { + return -1; + } + ret =3D ZSTD_initDStream(param->zstd_ds); + if (ZSTD_isError(ret)) { + return -1; + } + return 0; +} +static void zstd_load_cleanup(DecompressParam *param) +{ + ZSTD_freeDStream(param->zstd_ds); + param->zstd_ds =3D NULL; +} +static int +zstd_decompress_data(DecompressParam *param, uint8_t *dest, size_t size) +{ + int ret; + param->out.dst =3D dest; + param->out.size =3D size; + param->out.pos =3D 0; + param->in.src =3D param->compbuf; + param->in.size =3D param->len; + param->in.pos =3D 0; + do { + ret =3D ZSTD_decompressStream(param->zstd_ds, ¶m->out, ¶m-= >in); + } while (ret > 0 && (param->in.size - param->in.pos > 0) + && (param->out.size - param->out.pos > 0)); + if (ret > 0 && (param->in.size - param->in.pos > 0)) { + return -1; + } + if (ZSTD_isError(ret)) { + return -1; + } + return ret; +} +static int zstd_check_len(int len) +{ + return len < 0 || len > ZSTD_compressBound(TARGET_PAGE_SIZE); +} +#endif + static int set_compress_ops(void) { compress_ops =3D g_new0(MigrationCompressOps, 1); @@ -581,9 +692,16 @@ static int set_compress_ops(void) compress_ops->save_cleanup =3D zlib_save_cleanup; compress_ops->compress_data =3D zlib_compress_data; break; +#ifdef CONFIG_ZSTD + case COMPRESS_METHOD_ZSTD: + compress_ops->save_setup =3D zstd_save_setup; + compress_ops->save_cleanup =3D zstd_save_cleanup; + compress_ops->compress_data =3D zstd_compress_data; + break; +#endif default: return -1; - } + } =20 return 0; } @@ -599,6 +717,14 @@ static int set_decompress_ops(void) decompress_ops->decompress_data =3D zlib_decompress_data; decompress_ops->check_len =3D zlib_check_len; break; +#ifdef CONFIG_ZSTD + case COMPRESS_METHOD_ZSTD: + decompress_ops->load_setup =3D zstd_load_setup; + decompress_ops->load_cleanup =3D zstd_load_cleanup; + decompress_ops->decompress_data =3D zstd_decompress_data; + decompress_ops->check_len =3D zstd_check_len; + break; +#endif default: return -1; } diff --git a/qapi/migration.json b/qapi/migration.json index d262683a38..ac6d06c683 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -536,7 +536,7 @@ # ## { 'enum': 'CompressMethod', - 'data': [ 'zlib' ] } + 'data': [ 'zlib', { 'name': 'zstd', 'if': 'defined(CONFIG_ZSTD)' } ] } =20 ## # @BitmapMigrationBitmapAlias: --=20 2.23.0 From nobody Fri May 3 17:52:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604913463; cv=none; d=zohomail.com; s=zohoarc; b=QqCuyZOEANqFDOC/A9mGAxPn1NIDd2i7movDEQc2tLlbK7P9LXX9k5B/M3Dvw3t6Xe4siQ1XEMjEV+T6dJKrMiZmLh3UxGAF2AG2VLx6Ky57w1qnwdoue1SVmtNnx9XsIEWVuR2/koKXNG0PaIOhF84gFJ3wW39MdbQGAb6XemA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604913463; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qoZbLUcP0idhMfbAiqW6DvrUrEmZIb+eogiPXfp//9M=; b=RUSGQZYAYORSU6PyAQey5iK7fKP7m86VN6tGizJKrluV3wy6hTzqr8fXdZuE0gUwZQHVFcKRRqQZFr3m68ZgLftzfKRqNsoFHZJzZrZ4hbaPkY5nQJmY/K/bWB8UH5y3SSf0mSgreNvWdhFTbvBx7IUUwSMygtA7Qi7GSX5W1n0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604913463843460.97761332054245; Mon, 9 Nov 2020 01:17:43 -0800 (PST) Received: from localhost ([::1]:37554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kc3J0-0005HR-OI for importer@patchew.org; Mon, 09 Nov 2020 04:17:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Ay-0004Rd-Qz for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:24 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2082) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Av-0006yB-Py for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:24 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CV4tW0hf3zhhsv; Mon, 9 Nov 2020 17:09:07 +0800 (CST) Received: from localhost (10.174.186.67) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 17:09:04 +0800 From: Zeyu Jin To: , Subject: [RFC PATCH 5/6] migration: Add compress_level sanity check Date: Mon, 9 Nov 2020 17:08:49 +0800 Message-ID: <20201109090850.2424-6-jinzeyu@huawei.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201109090850.2424-1-jinzeyu@huawei.com> References: <20201109090850.2424-1-jinzeyu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.186.67] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=45.249.212.32; envelope-from=jinzeyu@huawei.com; helo=szxga06-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 04:09:11 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ying Fang , qemu-devel@nongnu.org, Zeyu Jin , zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Zlib compression has level from 1 to 9. However Zstd compression has level from 1 to 22 (level >=3D 20 not recommanded). Let's do sanity check here to make sure a vaild compress_level is given by user. Signed-off-by: Zeyu Jin Signed-off-by: Ying Fang --- migration/migration.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 2c68012029..6fc0c3b532 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1235,16 +1235,40 @@ void qmp_migrate_set_capabilities(MigrationCapabili= tyStatusList *params, } } =20 +static bool compress_level_check(MigrationParameters *params, Error **errp) +{ + switch (params->compress_method) { + case COMPRESS_METHOD_ZLIB: + if (params->compress_level > 9 || params->compress_level < 1) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level= ", + "a value in the range of 0 to 9 for Zlib method= "); + return false; + } + break; +#ifdef CONFIG_ZSTD + case COMPRESS_METHOD_ZSTD: + if (params->compress_level > 19 || params->compress_level < 1) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level= ", + "a value in the range of 1 to 19 for Zstd method"); + return false; + } + break; +#endif + default: + error_setg(errp, "Checking compress_level failed for unknown reaso= n"); + return false; + } + + return true; +} + /* * Check whether the parameters are valid. Error will be put into errp * (if provided). Return true if valid, otherwise false. */ static bool migrate_params_check(MigrationParameters *params, Error **errp) { - 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"); + if (params->has_compress_level && !compress_level_check(params, errp))= { return false; } =20 --=20 2.23.0 From nobody Fri May 3 17:52:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604913554; cv=none; d=zohomail.com; s=zohoarc; b=kh1FUVyweabGzdoZWbmJafLix2saLF5HFzHU7HxZQwJS0na4owBAseBh2UF5JOC/d++hGi4PECOnP7u06A44lJh5TQDx01JUyCAkD5oHLXx57BN3rSUCELnQX0RR8BEl2nECQuHQINzVYdofAqNfcUhyunWQ4TYQzyzV2uot0+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604913554; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gh67ea0L/y99MbpMv3oftbAIxtBO7t5LFhsJ4LJjdXU=; b=noD3c0a8F4Sv2hdF6pLwah153af8Ux6fJjHZAsO0bu1noL7V3l+RGXgL07xcLb9vl5gDdA9XEVaxVJ+4hTFD5xNrxZ/qFTOR9+O1f4bTFOK37ES+EKEm5Mf0uAOwjyiFU1lisSX4X6nICLIy31vIkLDK2el88w2Cx9jahZ7Mmjs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604913554722653.4392771839053; Mon, 9 Nov 2020 01:19:14 -0800 (PST) Received: from localhost ([::1]:43648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kc3KT-0007l4-GV for importer@patchew.org; Mon, 09 Nov 2020 04:19:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Az-0004S9-4N for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:25 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2085) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Av-0006z2-Pv for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:24 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CV4tY0TcXzhjDy; Mon, 9 Nov 2020 17:09:09 +0800 (CST) Received: from localhost (10.174.186.67) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 17:09:04 +0800 From: Zeyu Jin To: , Subject: [RFC PATCH 6/6] doc: Update multi-thread compression doc Date: Mon, 9 Nov 2020 17:08:50 +0800 Message-ID: <20201109090850.2424-7-jinzeyu@huawei.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201109090850.2424-1-jinzeyu@huawei.com> References: <20201109090850.2424-1-jinzeyu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.186.67] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=45.249.212.32; envelope-from=jinzeyu@huawei.com; helo=szxga06-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 04:09:11 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, WEIRD_PORT=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ying Fang , qemu-devel@nongnu.org, Zeyu Jin , zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Modify the doc to fit the previous changes. Signed-off-by: Zeyu Jin Signed-off-by: Ying Fang --- docs/multi-thread-compression.txt | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/docs/multi-thread-compression.txt b/docs/multi-thread-compress= ion.txt index bb88c6bdf1..d429963cb0 100644 --- a/docs/multi-thread-compression.txt +++ b/docs/multi-thread-compression.txt @@ -33,14 +33,15 @@ thread compression can be used to accelerate the compre= ssion process. =20 The decompression speed of Zlib is at least 4 times as quick as compression, if the source and destination CPU have equal speed, -keeping the compression thread count 4 times the decompression -thread count can avoid resource waste. +and you choose Zlib as compression method, keeping the compression +thread count 4 times the decompression thread count can avoid resource was= te. =20 Compression level can be used to control the compression speed and the -compression ratio. High compression ratio will take more time, level 0 -stands for no compression, level 1 stands for the best compression -speed, and level 9 stands for the best compression ratio. Users can -select a level number between 0 and 9. +compression ratio. High compression ratio will take more time, +level 1 stands for the best compression speed, and higher level means high= er +compression ration. For Zlib, users can select a level number between 0 an= d 9, +where level 0 stands for no compression. For Zstd, users can select a +level number between 1 and 22. =20 =20 When to use the multiple thread compression in live migration @@ -116,16 +117,19 @@ to support the multiple thread compression migration: 2. Activate compression on the source: {qemu} migrate_set_capability compress on =20 -3. Set the compression thread count on source: +3. Set the compression method: + {qemu} migrate_set_parameter compress_method zstd + +4. Set the compression thread count on source: {qemu} migrate_set_parameter compress_threads 12 =20 -4. Set the compression level on the source: +5. Set the compression level on the source: {qemu} migrate_set_parameter compress_level 1 =20 -5. Set the decompression thread count on destination: +6. Set the decompression thread count on destination: {qemu} migrate_set_parameter decompress_threads 3 =20 -6. Start outgoing migration: +7. Start outgoing migration: {qemu} migrate -d tcp:destination.host:4444 {qemu} info migrate Capabilities: ... compress: on @@ -136,6 +140,7 @@ The following are the default settings: compress_threads: 8 decompress_threads: 2 compress_level: 1 (which means best speed) + compress_method: zlib =20 So, only the first two steps are required to use the multiple thread compression in migration. You can do more if the default @@ -143,7 +148,7 @@ settings are not appropriate. =20 TODO =3D=3D=3D=3D -Some faster (de)compression method such as LZ4 and Quicklz can help -to reduce the CPU consumption when doing (de)compression. If using -these faster (de)compression method, less (de)compression threads +Comparing to Zlib, Some faster (de)compression method such as LZ4 +and Quicklz can help to reduce the CPU consumption when doing (de)compress= ion. +If using these faster (de)compression method, less (de)compression threads are needed when doing the migration. --=20 2.23.0