From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522396393308364.3383198209523; Fri, 30 Mar 2018 00:53:13 -0700 (PDT) Received: from localhost ([::1]:40885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oqV-0002yw-51 for importer@patchew.org; Fri, 30 Mar 2018 03:53:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1ooa-0001nZ-Pm for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1ooZ-0007YK-M8 for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:12 -0400 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]:40324) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1ooZ-0007YA-F9 for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:11 -0400 Received: by mail-pf0-x230.google.com with SMTP id y66so4951060pfi.7 for ; Fri, 30 Mar 2018 00:51:11 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TL1XWhIt+sETAFduxXn4nL0YeK0YLzCPZxJw286oiUg=; b=fkYfeXLNWTokAx+6DNAhYPnDbPLJm6dad6fMSDm5YwNHgSioZXDznY1vmfNfXAQsTJ HcstQ/sV6qp05R9xYXwVf5kgh0b5PHM7PPoEw5VvNOLJS9oFAUT5kJzFeKzVQTYcBh6e 1YuduK0oOI6D3VzlG5JhRAFb3w+j+K4Y/SJEeGhjFD2MR5D2jnwTMUsyFctswu8WToY6 UGF2YltTXTVTyNCeCAzs/8DNWtYgDcK1NVkZUoZ8uSYuFTWAXS727Lu+f8VOvjn5Mtuy 6vwym0PuglBWNch4KTedrfIItqBZZonm0+BLB/iZxJ9zYN7qUbJIcy3HVAo+0/8BIX4N GkUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TL1XWhIt+sETAFduxXn4nL0YeK0YLzCPZxJw286oiUg=; b=RxYV8ugpDCE61bpvWZTodszQZ2LHSSrBtXhnUjfXyIS8FeZm+A94hJi6wV3M+ySUEC hMlij2qIS85fvNL0Wrz7d4YZDZthEBMC7ZQ/oWTSRJRAkPS8tEQItJaL8w/O1f7pXicM r2gNKdn/j5B72VXDwnLFV7eAIOy2Ik6WLblHQ/led+Pec97fIuL7o9yYMg2WWjsRCQ5W 4DPZrYCpT3zc0RaM6uwmVlnheeRQY/QwJ+kBoVR/Mf88DJS3Az+Sv47IDg+LOtBRhzpi vnu6ILq7v0jtgwHhmlEm8Bb8W+BrERvTtNnCdi3PC+25cRX6PN+EMBq6tK731tP2VNfL cvEQ== X-Gm-Message-State: AElRT7Hgb4ZiE1N1FIUhmNVjq94ZanAsZohn8bS3uQ6dB4ITZm3pWDKu tmfmWp3O+uFqILGA1oSHSynQ1A== X-Google-Smtp-Source: AIpwx49Yo86miJbjqYl1E+Ix7xB8o+9/j2fblwDnibBCk6c4MIyXl+eH0NOf72Z30zlEf9h+kHGQyw== X-Received: by 10.99.169.1 with SMTP id u1mr7936032pge.251.1522396270551; Fri, 30 Mar 2018 00:51:10 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:19 +0800 Message-Id: <20180330075128.26919-2-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::230 Subject: [Qemu-devel] [PATCH v3 01/10] migration: stop compressing page in migration thread 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong As compression is a heavy work, do not do it in migration thread, instead, we post it out as a normal page Reviewed-by: Wei Wang Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Xiao Guangrong --- migration/ram.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 0e90efa092..409c847a76 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1137,7 +1137,7 @@ static int ram_save_compressed_page(RAMState *rs, Pag= eSearchStatus *pss, int pages =3D -1; uint64_t bytes_xmit =3D 0; uint8_t *p; - int ret, blen; + int ret; RAMBlock *block =3D pss->block; ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; =20 @@ -1167,23 +1167,23 @@ static int ram_save_compressed_page(RAMState *rs, P= ageSearchStatus *pss, if (block !=3D rs->last_sent_block) { flush_compressed_data(rs); pages =3D save_zero_page(rs, block, offset); - if (pages =3D=3D -1) { - /* Make sure the first page is sent out before other pages= */ - bytes_xmit =3D save_page_header(rs, rs->f, block, offset | - RAM_SAVE_FLAG_COMPRESS_PAGE); - blen =3D qemu_put_compression_data(rs->f, p, TARGET_PAGE_S= IZE, - migrate_compress_level()); - if (blen > 0) { - ram_counters.transferred +=3D bytes_xmit + blen; - ram_counters.normal++; - pages =3D 1; - } else { - qemu_file_set_error(rs->f, blen); - error_report("compressed data failed!"); - } - } if (pages > 0) { ram_release_pages(block->idstr, offset, pages); + } else { + /* + * Make sure the first page is sent out before other pages. + * + * we post it as normal page as compression will take much + * CPU resource. + */ + ram_counters.transferred +=3D save_page_header(rs, rs->f, = block, + offset | RAM_SAVE_FLAG_PAG= E); + qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, + migrate_release_ram() & + migration_in_postcopy()); + ram_counters.transferred +=3D TARGET_PAGE_SIZE; + ram_counters.normal++; + pages =3D 1; } } else { pages =3D save_zero_page(rs, block, offset); --=20 2.14.3 From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522396621162938.9238638743117; Fri, 30 Mar 2018 00:57:01 -0700 (PDT) Received: from localhost ([::1]:40911 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1ouB-0006f4-PJ for importer@patchew.org; Fri, 30 Mar 2018 03:56:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1ooe-0001rb-BC for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1ood-0007Zq-1x for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:16 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:46018) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1ooc-0007Yl-P5 for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:14 -0400 Received: by mail-pg0-x242.google.com with SMTP id y63so4657021pgy.12 for ; Fri, 30 Mar 2018 00:51:14 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hNuC+4bZFPdGAJU7WLg4keKNaBKEm4YNYO51mRso5uw=; b=tqQ/0z7PJJgVV7niydlmq3RkyX0yFWRwv4DgFhlOLiXuI4fzFi5AiC/3gYlu/1VWY9 FJZxRmkVD+YtLM88rYhJehf0SYem8TbfXZtYwBBmww255mrAtKJClzb+mspE1pQaf08u AWYUAInFF1Syp4HZTX9bzMtRkaUQEZH9363iVoKP0XEUSx8sT8Ck6xv3kO2E+8FuO9vB Tj6G/VFxMekx2r/l9sC6VpnjxIL8HcQwNfKQbhb73uKla20d2XBXu0dIe2JIYpLsxPGx l4c9wIl3RypikAwHFo8u1dXqc+CB8n9gheUdnevTvwUI19G4bmSyqFJnDHJMLDErada+ herg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hNuC+4bZFPdGAJU7WLg4keKNaBKEm4YNYO51mRso5uw=; b=qIyABHbitA+Urj027hLBvikti1eZM/MKN2GCR3tzjCB66TiD9eI9EFwSZpIXjwPyCR Gtt1TZA0Fj1QkQIkzRb3C8BtKvzYYrBBhS9qdkOWWm+S0x5jwF+WUoWdGD2gROpPa8YF XtIJJW8WLMBO8bp+eAunRxABiwdI1cf7nlAukePaSivKAN0FmaFkYHS2O/uIl2+STCMb x74LDrlywy2S28oN/0VOKQKQ0rdkw7OpqP/D3aRnOcb8c4MGrE0mw5wF8qgm1+2EfQYh ownI0npLBYh7RlGDwbJXu1lB9OfTrMg6vp7uqkQFl0P1dMTfspLYZ2AhPgrfqnzBHNM0 nhJg== X-Gm-Message-State: AElRT7GsPwc4C+JtDNHWRxlLABkwTYawOnd1ROQS62I71nundjtkOB23 y1aL5coesGzjUffQos8wsPQ= X-Google-Smtp-Source: AIpwx4+FIL/wfnAJn/PjTZjUgFm8YcEDD/nUjuoaSmX/d+/9Jp7imvtJCWopoalLIQ4Dct6uY3oizg== X-Received: by 10.99.95.84 with SMTP id t81mr7458494pgb.400.1522396273683; Fri, 30 Mar 2018 00:51:13 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:20 +0800 Message-Id: <20180330075128.26919-3-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH v3 02/10] migration: stop compression to allocate and free memory frequently 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Current code uses compress2() to compress memory which manages memory internally, that causes huge memory is allocated and freed very frequently More worse, frequently returning memory to kernel will flush TLBs and trigger invalidation callbacks on mmu-notification which interacts with KVM MMU, that dramatically reduce the performance of VM So, we maintain the memory by ourselves and reuse it for each compression Reviewed-by: Peter Xu Reviewed-by: Jiang Biao Signed-off-by: Xiao Guangrong --- migration/qemu-file.c | 39 ++++++++++++++++++++++++++++++++------- migration/qemu-file.h | 6 ++++-- migration/ram.c | 41 ++++++++++++++++++++++++++++++++--------- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index bb63c779cc..bafe3a0c0d 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -658,8 +658,32 @@ uint64_t qemu_get_be64(QEMUFile *f) return v; } =20 -/* Compress size bytes of data start at p with specific compression - * level and store the compressed data to the buffer of f. +/* 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. * * When f is not writable, return -1 if f has no space to save the * compressed data. @@ -667,9 +691,8 @@ uint64_t qemu_get_be64(QEMUFile *f) * do fflush first, if f still has no space to save the compressed * data, return -1. */ - -ssize_t qemu_put_compression_data(QEMUFile *f, const uint8_t *p, size_t si= ze, - int level) +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); =20 @@ -683,8 +706,10 @@ ssize_t qemu_put_compression_data(QEMUFile *f, const u= int8_t *p, size_t size, return -1; } } - if (compress2(f->buf + f->buf_index + sizeof(int32_t), (uLongf *)&blen, - (Bytef *)p, size, level) !=3D Z_OK) { + + blen =3D qemu_compress_data(stream, f->buf + f->buf_index + sizeof(int= 32_t), + blen, p, size); + if (blen < 0) { error_report("Compress Failed!"); return 0; } diff --git a/migration/qemu-file.h b/migration/qemu-file.h index f4f356ab12..2ccfcfb2a8 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -25,6 +25,8 @@ #ifndef MIGRATION_QEMU_FILE_H #define MIGRATION_QEMU_FILE_H =20 +#include + /* Read a chunk of data from a file at the given position. The pos argume= nt * can be ignored if the file is only be used for streaming. The number of * bytes actually read should be returned. @@ -132,8 +134,8 @@ 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, const uint8_t *p, size_t si= ze, - int level); +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 /* diff --git a/migration/ram.c b/migration/ram.c index 409c847a76..a21514a469 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -269,6 +269,7 @@ struct CompressParam { QemuCond cond; RAMBlock *block; ram_addr_t offset; + z_stream stream; }; typedef struct CompressParam CompressParam; =20 @@ -299,7 +300,7 @@ static QemuThread *decompress_threads; static QemuMutex decomp_done_lock; static QemuCond decomp_done_cond; =20 -static int do_compress_ram_page(QEMUFile *f, RAMBlock *block, +static int do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *b= lock, ram_addr_t offset); =20 static void *do_data_compress(void *opaque) @@ -316,7 +317,7 @@ static void *do_data_compress(void *opaque) param->block =3D NULL; qemu_mutex_unlock(¶m->mutex); =20 - do_compress_ram_page(param->file, block, offset); + do_compress_ram_page(param->file, ¶m->stream, block, offse= t); =20 qemu_mutex_lock(&comp_done_lock); param->done =3D true; @@ -357,10 +358,19 @@ static void compress_threads_save_cleanup(void) terminate_compression_threads(); thread_count =3D migrate_compress_threads(); for (i =3D 0; i < thread_count; i++) { + /* + * we use it as a indicator which shows if the thread is + * properly init'd or not + */ + if (!comp_param[i].file) { + break; + } qemu_thread_join(compress_threads + i); - qemu_fclose(comp_param[i].file); qemu_mutex_destroy(&comp_param[i].mutex); qemu_cond_destroy(&comp_param[i].cond); + deflateEnd(&comp_param[i].stream); + qemu_fclose(comp_param[i].file); + comp_param[i].file =3D NULL; } qemu_mutex_destroy(&comp_done_lock); qemu_cond_destroy(&comp_done_cond); @@ -370,12 +380,12 @@ static void compress_threads_save_cleanup(void) comp_param =3D NULL; } =20 -static void compress_threads_save_setup(void) +static int compress_threads_save_setup(void) { int i, thread_count; =20 if (!migrate_use_compression()) { - return; + return 0; } thread_count =3D migrate_compress_threads(); compress_threads =3D g_new0(QemuThread, thread_count); @@ -383,6 +393,11 @@ static void compress_threads_save_setup(void) qemu_cond_init(&comp_done_cond); qemu_mutex_init(&comp_done_lock); for (i =3D 0; i < thread_count; i++) { + if (deflateInit(&comp_param[i].stream, + migrate_compress_level()) !=3D Z_OK) { + goto exit; + } + /* comp_param[i].file is just used as a dummy buffer to save data, * set its ops to empty. */ @@ -395,6 +410,11 @@ static void compress_threads_save_setup(void) do_data_compress, comp_param + i, QEMU_THREAD_JOINABLE); } + return 0; + +exit: + compress_threads_save_cleanup(); + return -1; } =20 /* Multiple fd's */ @@ -1031,7 +1051,7 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss, bool last_stage) return pages; } =20 -static int do_compress_ram_page(QEMUFile *f, RAMBlock *block, +static int do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *b= lock, ram_addr_t offset) { RAMState *rs =3D ram_state; @@ -1040,8 +1060,7 @@ static int do_compress_ram_page(QEMUFile *f, RAMBlock= *block, =20 bytes_sent =3D save_page_header(rs, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); - blen =3D qemu_put_compression_data(f, p, TARGET_PAGE_SIZE, - migrate_compress_level()); + blen =3D qemu_put_compression_data(f, stream, p, TARGET_PAGE_SIZE); if (blen < 0) { bytes_sent =3D 0; qemu_file_set_error(migrate_get_current()->to_dst_file, blen); @@ -2214,9 +2233,14 @@ static int ram_save_setup(QEMUFile *f, void *opaque) RAMState **rsp =3D opaque; RAMBlock *block; =20 + if (compress_threads_save_setup()) { + return -1; + } + /* migration has already setup the bitmap, reuse it. */ if (!migration_in_colo_state()) { if (ram_init_all(rsp) !=3D 0) { + compress_threads_save_cleanup(); return -1; } } @@ -2236,7 +2260,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque) } =20 rcu_read_unlock(); - compress_threads_save_setup(); =20 ram_control_before_iterate(f, RAM_CONTROL_SETUP); ram_control_after_iterate(f, RAM_CONTROL_SETUP); --=20 2.14.3 From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152239655503815.508533669682151; Fri, 30 Mar 2018 00:55:55 -0700 (PDT) Received: from localhost ([::1]:40905 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1ot7-0005g3-QA for importer@patchew.org; Fri, 30 Mar 2018 03:55:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1ooj-0001vP-6I for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1oog-0007cS-2z for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:21 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:39525) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1oof-0007bw-QZ for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:18 -0400 Received: by mail-pg0-x242.google.com with SMTP id b9so4667317pgf.6 for ; Fri, 30 Mar 2018 00:51:17 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x+RwRDuZuJhN0B5SsGyzuGuKpCQoGdTNXJgZeG1BcQk=; b=gJOlFVQKeMC8CEKZ4FoSuhqOA2G1xCZGHMH/lS5n0LlV6AV06LEvcsw8GfOg8PJJjO IVYPKPDE6K19UA/Yzsvmw2cxGlP8u/+Zsb76vevH0WekIuExAM4zS9BUslEJo25A9yDX ZH+GO3APAlBnE9wI54Kx7H9AbgcG+c2gG0/CQWPQozemghMKY7AbAXvkVrtzRYeqxXdn 0ncIsuCTLWaVbb3uWqL3+BhNC7SHq3BCz4AAOPCOC4++wAVFWWKLY8/v84fxNDmMcDQ4 Qw4Jv9wVaTM+i1xDZMh4GzoR4vsjE09Ym2KuI6m89SWEDPmn7A4gvXFOWKi8bmHG8lCz kbeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x+RwRDuZuJhN0B5SsGyzuGuKpCQoGdTNXJgZeG1BcQk=; b=BDHp4Tf4rRTc4wyb7RlEfdxynpCXZnC+cYU/h7BZuv0ILV67gm/FVcMKWAiFFTvuWF pCrJp+gwWbLu1VeAoMTbHjsYHO4x2Esdmyvh06i8kP81cwKca6QEcRVL2g+je6+m6bBU MIevqguuTdJ5Q3m5Ut3ljhI9WHs4wt4NuK7lY2mbDIRFP5SUqolJQJBOAkXDBuiXZa9Z gwOtzBG+lAKuXqW043OiICa7e7rwAwf67lgbdZNgEdjTx9Ct6rsQji/cRXvayJugf0Js 2mNMqwHQWzGqS6q2y1HtBNQbz3ACU0g0R8XjR1DlEA4xDBqYedUzUO6KXGyos5g4Ng6A 4uVA== X-Gm-Message-State: AElRT7EyumOrTwQIlPeG1GLNxFy28B/Ua+xzG69e6WV6M6VVli349uB2 01uZEZ7HLFIrG85RZVl2HVo= X-Google-Smtp-Source: AIpwx4/S2y5p6A1v+f43qHdNiyC3zaIQIG7IUBGIwQgzEuA2pzDw/BpaguXe8r6K4ioFFv6amaF2NQ== X-Received: by 10.98.144.205 with SMTP id q74mr9015562pfk.55.1522396276915; Fri, 30 Mar 2018 00:51:16 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:21 +0800 Message-Id: <20180330075128.26919-4-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH v3 03/10] migration: stop decompression to allocate and free memory frequently 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Current code uses uncompress() to decompress memory which manages memory internally, that causes huge memory is allocated and freed very frequently, more worse, frequently returning memory to kernel will flush TLBs So, we maintain the memory by ourselves and reuse it for each decompression Reviewed-by: Peter Xu Reviewed-by: Jiang Biao Signed-off-by: Xiao Guangrong --- migration/ram.c | 112 +++++++++++++++++++++++++++++++++++++++++-----------= ---- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index a21514a469..fb24b2f32f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -281,6 +281,7 @@ struct DecompressParam { void *des; uint8_t *compbuf; int len; + z_stream stream; }; typedef struct DecompressParam DecompressParam; =20 @@ -2524,6 +2525,31 @@ 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(z_stream *stream, uint8_t *dest, size_t dest_len, + const uint8_t *source, size_t source_len) +{ + int err; + + err =3D inflateReset(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 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; @@ -2540,13 +2566,13 @@ static void *do_data_decompress(void *opaque) qemu_mutex_unlock(¶m->mutex); =20 pagesize =3D TARGET_PAGE_SIZE; - /* uncompress() will return failed in some case, especially - * when the page is dirted when doing the compression, it's - * not a problem because the dirty page will be retransferred + /* qemu_uncompress_data() will return failed in some case, + * especially when the page is dirtied when doing the compress= ion, + * it's not a problem because the dirty page will be retransfe= rred * and uncompress() won't break the data in other pages. */ - uncompress((Bytef *)des, &pagesize, - (const Bytef *)param->compbuf, len); + qemu_uncompress_data(¶m->stream, des, pagesize, param->com= pbuf, + len); =20 qemu_mutex_lock(&decomp_done_lock); param->done =3D true; @@ -2581,30 +2607,6 @@ static void wait_for_decompress_done(void) qemu_mutex_unlock(&decomp_done_lock); } =20 -static void compress_threads_load_setup(void) -{ - int i, thread_count; - - if (!migrate_use_compression()) { - return; - } - thread_count =3D migrate_decompress_threads(); - decompress_threads =3D g_new0(QemuThread, thread_count); - decomp_param =3D g_new0(DecompressParam, thread_count); - qemu_mutex_init(&decomp_done_lock); - qemu_cond_init(&decomp_done_cond); - for (i =3D 0; i < thread_count; i++) { - qemu_mutex_init(&decomp_param[i].mutex); - qemu_cond_init(&decomp_param[i].cond); - decomp_param[i].compbuf =3D g_malloc0(compressBound(TARGET_PAGE_SI= ZE)); - decomp_param[i].done =3D true; - decomp_param[i].quit =3D false; - qemu_thread_create(decompress_threads + i, "decompress", - do_data_decompress, decomp_param + i, - QEMU_THREAD_JOINABLE); - } -} - static void compress_threads_load_cleanup(void) { int i, thread_count; @@ -2614,16 +2616,30 @@ static void compress_threads_load_cleanup(void) } thread_count =3D migrate_decompress_threads(); for (i =3D 0; i < thread_count; i++) { + /* + * we use it as a indicator which shows if the thread is + * properly init'd or not + */ + if (!decomp_param[i].compbuf) { + break; + } + qemu_mutex_lock(&decomp_param[i].mutex); decomp_param[i].quit =3D true; qemu_cond_signal(&decomp_param[i].cond); qemu_mutex_unlock(&decomp_param[i].mutex); } for (i =3D 0; i < thread_count; i++) { + if (!decomp_param[i].compbuf) { + break; + } + 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); g_free(decomp_param[i].compbuf); + decomp_param[i].compbuf =3D NULL; } g_free(decompress_threads); g_free(decomp_param); @@ -2631,6 +2647,39 @@ static void compress_threads_load_cleanup(void) decomp_param =3D NULL; } =20 +static int compress_threads_load_setup(void) +{ + int i, thread_count; + + if (!migrate_use_compression()) { + return 0; + } + + thread_count =3D migrate_decompress_threads(); + decompress_threads =3D g_new0(QemuThread, thread_count); + decomp_param =3D g_new0(DecompressParam, thread_count); + qemu_mutex_init(&decomp_done_lock); + qemu_cond_init(&decomp_done_cond); + for (i =3D 0; i < thread_count; i++) { + if (inflateInit(&decomp_param[i].stream) !=3D Z_OK) { + goto exit; + } + + decomp_param[i].compbuf =3D g_malloc0(compressBound(TARGET_PAGE_SI= ZE)); + qemu_mutex_init(&decomp_param[i].mutex); + qemu_cond_init(&decomp_param[i].cond); + decomp_param[i].done =3D true; + decomp_param[i].quit =3D false; + qemu_thread_create(decompress_threads + i, "decompress", + do_data_decompress, decomp_param + i, + QEMU_THREAD_JOINABLE); + } + return 0; +exit: + compress_threads_load_cleanup(); + return -1; +} + static void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len) { @@ -2670,8 +2719,11 @@ static void decompress_data_with_multi_threads(QEMUF= ile *f, */ static int ram_load_setup(QEMUFile *f, void *opaque) { + if (compress_threads_load_setup()) { + return -1; + } + xbzrle_load_setup(); - compress_threads_load_setup(); ramblock_recv_map_init(); return 0; } --=20 2.14.3 From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15223964073461003.2467276150787; Fri, 30 Mar 2018 00:53:27 -0700 (PDT) Received: from localhost ([::1]:40886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oqk-0003Bu-3Y for importer@patchew.org; Fri, 30 Mar 2018 03:53:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1ook-0001wU-La for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1ooj-0007dI-Hk for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:22 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:33902) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1ooj-0007d8-9g for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:21 -0400 Received: by mail-pg0-x244.google.com with SMTP id y16so4127107pgv.1 for ; Fri, 30 Mar 2018 00:51:21 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8MaSOZcU4ADW+tt8vgk9V0Mk5exgLp67IWn/wz9dXMA=; b=fPooZpTozvrQlWWyKFsfEFLtHBkR2/wFNWvxc7wqSPxHPbwJlCgpcorVUSeZlIJkgG ljmY/N4ABtOICMYpmJ3ZBWdUhpkjG1e3lcYN7iYvlUfyAu2T7I3i/tfsgbpqT6ztK+yC v1QsKAT/mMPbPtG9Ou8uJK+I7UC+gTS1Ex9JBS07pLTIXXbW/TcVrNzEQK0k7FmQTGmw zbi5yYig/ZcLHOPCl23deluhH1IlCZDwvIi7u4nyBAJ6nfyAEf4s9Tn+t6cL1yfCLgKr lJz3/py3Dqhdu7RBf0Anfh4f5prnAyThF1o0kzfvYtlU9kz5Wl9iSXslcMLkpS4wUmej 8/VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8MaSOZcU4ADW+tt8vgk9V0Mk5exgLp67IWn/wz9dXMA=; b=VwMtrN2MkpB65XCYHfyWkT2RqFSKi1fOnkoXbcxDefraUYjzbkFJ7xrDDZg4j59xou VuJJF947I9ppeTJxt+g0f2ygqd2RoR/oVbC0MtBItZKMDVwLCHCDuFS6F/bkmLhLkY0p h/XhkDVTpQgzdzAB2Z0eC5JoyYQrqWaHCYLo9MEO2THM+hNAuR5yP3QOlGqBjF1+4pbc 8O8QCTIkR0xyj3QyUFdJrWxxCtz6QbwgTTfBu46eCBMQyOvd6GV6ES2SR/hCRya87T1h Il7WRSCBanka9WKrHzTPCmB3DZz85CqAaBsoueZRzyWalUAnw14e6HU9F+N8wQiGjCHa VHzQ== X-Gm-Message-State: AElRT7Hqe58y7XbTWDhAJUXfLC50goykbdORx03tF977+V3UnI5Gg78E r6iv1BSR+UBJLlrB0ncqx6Y= X-Google-Smtp-Source: AIpwx48GR9TGINSvbaSEdFfL/Lr2g7TnPVvrdEpNddw3Cop42TwE/I5elgF+4LTmWUPCvIDDS0lp1w== X-Received: by 10.101.72.13 with SMTP id h13mr5874640pgs.420.1522396280318; Fri, 30 Mar 2018 00:51:20 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:22 +0800 Message-Id: <20180330075128.26919-5-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH v3 04/10] migration: detect compression and decompression errors 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Currently the page being compressed is allowed to be updated by the VM on the source QEMU, correspondingly the destination QEMU just ignores the decompression error. However, we completely miss the chance to catch real errors, then the VM is corrupted silently To make the migration more robuster, we copy the page to a buffer first to avoid it being written by VM, then detect and handle the errors of both compression and decompression errors properly Reviewed-by: Peter Xu Signed-off-by: Xiao Guangrong --- migration/qemu-file.c | 4 ++-- migration/ram.c | 56 +++++++++++++++++++++++++++++++++++------------= ---- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index bafe3a0c0d..0463f4c321 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -710,9 +710,9 @@ ssize_t qemu_put_compression_data(QEMUFile *f, z_stream= *stream, blen =3D qemu_compress_data(stream, f->buf + f->buf_index + sizeof(int= 32_t), blen, p, size); if (blen < 0) { - error_report("Compress Failed!"); - return 0; + return -1; } + qemu_put_be32(f, blen); if (f->ops->writev_buffer) { add_to_iovec(f, f->buf + f->buf_index, blen, false); diff --git a/migration/ram.c b/migration/ram.c index fb24b2f32f..72cb8dfb66 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -269,7 +269,10 @@ struct CompressParam { QemuCond cond; RAMBlock *block; ram_addr_t offset; + + /* internally used fields */ z_stream stream; + uint8_t *originbuf; }; typedef struct CompressParam CompressParam; =20 @@ -296,13 +299,14 @@ static QemuCond comp_done_cond; /* The empty QEMUFileOps will be used by file in CompressParam */ static const QEMUFileOps empty_ops =3D { }; =20 +static QEMUFile *decomp_file; static DecompressParam *decomp_param; static QemuThread *decompress_threads; static QemuMutex decomp_done_lock; static QemuCond decomp_done_cond; =20 static int do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *b= lock, - ram_addr_t offset); + ram_addr_t offset, uint8_t *source_buf); =20 static void *do_data_compress(void *opaque) { @@ -318,7 +322,8 @@ static void *do_data_compress(void *opaque) param->block =3D NULL; qemu_mutex_unlock(¶m->mutex); =20 - do_compress_ram_page(param->file, ¶m->stream, block, offse= t); + do_compress_ram_page(param->file, ¶m->stream, block, offse= t, + param->originbuf); =20 qemu_mutex_lock(&comp_done_lock); param->done =3D true; @@ -370,6 +375,7 @@ static void compress_threads_save_cleanup(void) 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); qemu_fclose(comp_param[i].file); comp_param[i].file =3D NULL; } @@ -394,8 +400,14 @@ static int compress_threads_save_setup(void) qemu_cond_init(&comp_done_cond); qemu_mutex_init(&comp_done_lock); for (i =3D 0; i < thread_count; i++) { + comp_param[i].originbuf =3D g_try_malloc(TARGET_PAGE_SIZE); + if (!comp_param[i].originbuf) { + goto exit; + } + if (deflateInit(&comp_param[i].stream, migrate_compress_level()) !=3D Z_OK) { + g_free(comp_param[i].originbuf); goto exit; } =20 @@ -1053,7 +1065,7 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss, bool last_stage) } =20 static int do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *b= lock, - ram_addr_t offset) + ram_addr_t offset, uint8_t *source_buf) { RAMState *rs =3D ram_state; int bytes_sent, blen; @@ -1061,7 +1073,14 @@ static int do_compress_ram_page(QEMUFile *f, z_strea= m *stream, RAMBlock *block, =20 bytes_sent =3D save_page_header(rs, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); - blen =3D qemu_put_compression_data(f, stream, p, TARGET_PAGE_SIZE); + + /* + * 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); + blen =3D qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_= SIZE); if (blen < 0) { bytes_sent =3D 0; qemu_file_set_error(migrate_get_current()->to_dst_file, blen); @@ -2555,7 +2574,7 @@ static void *do_data_decompress(void *opaque) DecompressParam *param =3D opaque; unsigned long pagesize; uint8_t *des; - int len; + int len, ret; =20 qemu_mutex_lock(¶m->mutex); while (!param->quit) { @@ -2566,13 +2585,13 @@ static void *do_data_decompress(void *opaque) qemu_mutex_unlock(¶m->mutex); =20 pagesize =3D TARGET_PAGE_SIZE; - /* qemu_uncompress_data() will return failed in some case, - * especially when the page is dirtied when doing the compress= ion, - * it's not a problem because the dirty page will be retransfe= rred - * and uncompress() won't break the data in other pages. - */ - qemu_uncompress_data(¶m->stream, des, pagesize, param->com= pbuf, - len); + + ret =3D qemu_uncompress_data(¶m->stream, des, pagesize, + param->compbuf, len); + if (ret < 0) { + error_report("decompress data failed"); + qemu_file_set_error(decomp_file, ret); + } =20 qemu_mutex_lock(&decomp_done_lock); param->done =3D true; @@ -2589,12 +2608,12 @@ static void *do_data_decompress(void *opaque) return NULL; } =20 -static void wait_for_decompress_done(void) +static int wait_for_decompress_done(void) { int idx, thread_count; =20 if (!migrate_use_compression()) { - return; + return 0; } =20 thread_count =3D migrate_decompress_threads(); @@ -2605,6 +2624,7 @@ static void wait_for_decompress_done(void) } } qemu_mutex_unlock(&decomp_done_lock); + return qemu_file_get_error(decomp_file); } =20 static void compress_threads_load_cleanup(void) @@ -2645,9 +2665,10 @@ static void compress_threads_load_cleanup(void) g_free(decomp_param); decompress_threads =3D NULL; decomp_param =3D NULL; + decomp_file =3D NULL; } =20 -static int compress_threads_load_setup(void) +static int compress_threads_load_setup(QEMUFile *f) { int i, thread_count; =20 @@ -2660,6 +2681,7 @@ static int compress_threads_load_setup(void) decomp_param =3D g_new0(DecompressParam, thread_count); qemu_mutex_init(&decomp_done_lock); 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) { goto exit; @@ -2719,7 +2741,7 @@ static void decompress_data_with_multi_threads(QEMUFi= le *f, */ static int ram_load_setup(QEMUFile *f, void *opaque) { - if (compress_threads_load_setup()) { + if (compress_threads_load_setup(f)) { return -1; } =20 @@ -3074,7 +3096,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) } } =20 - wait_for_decompress_done(); + ret |=3D wait_for_decompress_done(); rcu_read_unlock(); trace_ram_load_complete(ret, seq_iter); return ret; --=20 2.14.3 From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522396736227589.0599641471172; Fri, 30 Mar 2018 00:58:56 -0700 (PDT) Received: from localhost ([::1]:41126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1ow1-00008Q-9C for importer@patchew.org; Fri, 30 Mar 2018 03:58:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oop-0001xX-0J for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1oom-0007eB-On for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:26 -0400 Received: from mail-pf0-x232.google.com ([2607:f8b0:400e:c00::232]:34955) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1oom-0007ds-Fv for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:24 -0400 Received: by mail-pf0-x232.google.com with SMTP id u86so4982794pfd.2 for ; Fri, 30 Mar 2018 00:51:24 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XsxfFpBYGEbNF2r+20A4GycRAcq4g/gPhN8+JOpd+Vo=; b=fbYlrjEIv9f6gh1vz7NZfRbJf/B/7krvCd5Q9k6RSgAN2MzIOd6SbNWaq84wkruztz LUGHbWhxxq8CQUXfpGnbsAhvxauxxhqjTm9RTfc1PzHOQ33MG1+zF80rOsV/05Gr+UT5 k126Pf2wboTfAwSTKtzwTKm2baZXtXHrZIIKh+OC7TYQjtRzJeZ4FswNemxW7+gmZs3/ xnAMA1g2NU9GWtNrZASdezQwGQYWpNGwxOzl3d54Fi+Ls9UX59Es5R4EIeV6ETRc5/Wt OimyWFzodlaHnQQtFaxNdphz+/FdeV1vHZl4e1NFGqKXgdzWx3VPiKNNpzBPBrRbPDfY GBCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XsxfFpBYGEbNF2r+20A4GycRAcq4g/gPhN8+JOpd+Vo=; b=Ch3jl70jmJSf2DKDUSv4nkfnDtfkSEcWeB0faBty50zfhaXBuhjao9hoNNYjCClDdU XiuBj6qzupOPQPu4Sic1oKbh9UM+4p8f0zOZUrpPqBYihj+q4nu1z5rEuACSkiNTtWQe 1uZyr+2D07Yc5tfYqyrEpxzb0YBm8qZpoWxQooPcnM+b2Bq6wosKvAn3sTPbQtsnomcM 4SlGiaEejVJFI4jOJ6aJIKGd9f/fNOR4OuPR6+c5MMUFUGP77LqLQOB+XjQREsX39pVc Z8Jm6z9m0QMYjFks/ZI4sK8vHRuIomfJlxx4gSClBj5coTl1S1uFZLX1d7lRpDJvspcN cwcw== X-Gm-Message-State: AElRT7GbvyVa5KxncgGoCFP/DMVVKFB7WDmL0olBERqOLRqg+6aTzcW9 kLjLZ2eXTWEBP7TiA4k1x8o= X-Google-Smtp-Source: AIpwx4/9nQfJjQPiGAdrNg1d+khfAPHGRGGHXSrjU2Jz3x1WIki/by36qQkIHJBjsfVn5yHkGSTWtw== X-Received: by 10.101.74.69 with SMTP id a5mr7982694pgu.32.1522396283467; Fri, 30 Mar 2018 00:51:23 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:23 +0800 Message-Id: <20180330075128.26919-6-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::232 Subject: [Qemu-devel] [PATCH v3 05/10] migration: introduce control_save_page() 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Abstract the common function control_save_page() to cleanup the code, no logic is changed Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Xiao Guangrong --- migration/ram.c | 174 +++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 89 insertions(+), 85 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 72cb8dfb66..79c7958993 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -974,6 +974,44 @@ static void ram_release_pages(const char *rbname, uint= 64_t offset, int pages) ram_discard_range(rbname, offset, pages << TARGET_PAGE_BITS); } =20 +/* + * @pages: the number of pages written by the control path, + * < 0 - error + * > 0 - number of pages written + * + * Return true if the pages has been saved, otherwise false is returned. + */ +static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t of= fset, + int *pages) +{ + uint64_t bytes_xmit =3D 0; + int ret; + + *pages =3D -1; + ret =3D ram_control_save_page(rs->f, block->offset, offset, TARGET_PAG= E_SIZE, + &bytes_xmit); + if (ret =3D=3D RAM_SAVE_CONTROL_NOT_SUPP) { + return false; + } + + if (bytes_xmit) { + ram_counters.transferred +=3D bytes_xmit; + *pages =3D 1; + } + + if (ret =3D=3D RAM_SAVE_CONTROL_DELAYED) { + return true; + } + + if (bytes_xmit > 0) { + ram_counters.normal++; + } else if (bytes_xmit =3D=3D 0) { + ram_counters.duplicate++; + } + + return true; +} + /** * ram_save_page: send the given page to the stream * @@ -990,56 +1028,36 @@ static void ram_release_pages(const char *rbname, ui= nt64_t offset, int pages) static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_st= age) { int pages =3D -1; - uint64_t bytes_xmit; - ram_addr_t current_addr; uint8_t *p; - int ret; bool send_async =3D true; RAMBlock *block =3D pss->block; ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; + ram_addr_t current_addr =3D block->offset + offset; =20 p =3D block->host + offset; trace_ram_save_page(block->idstr, (uint64_t)offset, p); =20 - /* In doubt sent page as normal */ - bytes_xmit =3D 0; - ret =3D ram_control_save_page(rs->f, block->offset, - offset, TARGET_PAGE_SIZE, &bytes_xmit); - if (bytes_xmit) { - ram_counters.transferred +=3D bytes_xmit; - pages =3D 1; + if (control_save_page(rs, block, offset, &pages)) { + return pages; } =20 XBZRLE_cache_lock(); - - current_addr =3D block->offset + offset; - - if (ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { - if (ret !=3D RAM_SAVE_CONTROL_DELAYED) { - if (bytes_xmit > 0) { - ram_counters.normal++; - } else if (bytes_xmit =3D=3D 0) { - ram_counters.duplicate++; - } - } - } else { - pages =3D save_zero_page(rs, block, offset); - if (pages > 0) { - /* Must let xbzrle know, otherwise a previous (now 0'd) cached - * page would be stale + pages =3D save_zero_page(rs, block, offset); + if (pages > 0) { + /* Must let xbzrle know, otherwise a previous (now 0'd) cached + * page would be stale + */ + xbzrle_cache_zero_page(rs, current_addr); + ram_release_pages(block->idstr, offset, pages); + } else if (!rs->ram_bulk_stage && + !migration_in_postcopy() && migrate_use_xbzrle()) { + pages =3D save_xbzrle_page(rs, &p, current_addr, block, + offset, last_stage); + if (!last_stage) { + /* Can't send this cached data async, since the cache page + * might get updated before it gets to the wire */ - xbzrle_cache_zero_page(rs, current_addr); - ram_release_pages(block->idstr, offset, pages); - } else if (!rs->ram_bulk_stage && - !migration_in_postcopy() && migrate_use_xbzrle()) { - pages =3D save_xbzrle_page(rs, &p, current_addr, block, - offset, last_stage); - if (!last_stage) { - /* Can't send this cached data async, since the cache page - * might get updated before it gets to the wire - */ - send_async =3D false; - } + send_async =3D false; } } =20 @@ -1174,63 +1192,49 @@ static int ram_save_compressed_page(RAMState *rs, P= ageSearchStatus *pss, bool last_stage) { int pages =3D -1; - uint64_t bytes_xmit =3D 0; uint8_t *p; - int ret; RAMBlock *block =3D pss->block; ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; =20 p =3D block->host + offset; =20 - ret =3D ram_control_save_page(rs->f, block->offset, - offset, TARGET_PAGE_SIZE, &bytes_xmit); - if (bytes_xmit) { - ram_counters.transferred +=3D bytes_xmit; - pages =3D 1; + if (control_save_page(rs, block, offset, &pages)) { + return pages; } - if (ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { - if (ret !=3D RAM_SAVE_CONTROL_DELAYED) { - if (bytes_xmit > 0) { - ram_counters.normal++; - } else if (bytes_xmit =3D=3D 0) { - ram_counters.duplicate++; - } + + /* When starting the process of a new block, the first page of + * the block should be sent out before other pages in the same + * block, and all the pages in last block should have been sent + * out, keeping this order is important, because the 'cont' flag + * is used to avoid resending the block name. + */ + if (block !=3D rs->last_sent_block) { + flush_compressed_data(rs); + pages =3D save_zero_page(rs, block, offset); + if (pages > 0) { + ram_release_pages(block->idstr, offset, pages); + } else { + /* + * Make sure the first page is sent out before other pages. + * + * we post it as normal page as compression will take much + * CPU resource. + */ + ram_counters.transferred +=3D save_page_header(rs, rs->f, bloc= k, + offset | RAM_SAVE_FLAG_PAGE); + qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, + migrate_release_ram() & + migration_in_postcopy()); + ram_counters.transferred +=3D TARGET_PAGE_SIZE; + ram_counters.normal++; + pages =3D 1; } } else { - /* When starting the process of a new block, the first page of - * the block should be sent out before other pages in the same - * block, and all the pages in last block should have been sent - * out, keeping this order is important, because the 'cont' flag - * is used to avoid resending the block name. - */ - if (block !=3D rs->last_sent_block) { - flush_compressed_data(rs); - pages =3D save_zero_page(rs, block, offset); - if (pages > 0) { - ram_release_pages(block->idstr, offset, pages); - } else { - /* - * Make sure the first page is sent out before other pages. - * - * we post it as normal page as compression will take much - * CPU resource. - */ - ram_counters.transferred +=3D save_page_header(rs, rs->f, = block, - offset | RAM_SAVE_FLAG_PAG= E); - qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, - migrate_release_ram() & - migration_in_postcopy()); - ram_counters.transferred +=3D TARGET_PAGE_SIZE; - ram_counters.normal++; - pages =3D 1; - } + pages =3D save_zero_page(rs, block, offset); + if (pages =3D=3D -1) { + pages =3D compress_page_with_multi_thread(rs, block, offset); } else { - pages =3D save_zero_page(rs, block, offset); - if (pages =3D=3D -1) { - pages =3D compress_page_with_multi_thread(rs, block, offse= t); - } else { - ram_release_pages(block->idstr, offset, pages); - } + ram_release_pages(block->idstr, offset, pages); } } =20 --=20 2.14.3 From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152239641579646.71784088180459; Fri, 30 Mar 2018 00:53:35 -0700 (PDT) Received: from localhost ([::1]:40887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oqq-0003GT-Q7 for importer@patchew.org; Fri, 30 Mar 2018 03:53:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oos-00020m-98 for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1oop-0007es-Of for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:30 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:45699) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1oop-0007eW-Iz for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:27 -0400 Received: by mail-pf0-x242.google.com with SMTP id l27so4977719pfk.12 for ; Fri, 30 Mar 2018 00:51:27 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DRP+RppCJq6ffQzj9IFqI19nyCxOb1EhZLgbovYRwHQ=; b=sRafEtKRBnU7ygVDRMqpxofr6AVPtGhF5A/+FUhZqYo1HqbN29oHkXcGM1q4oVerks dPbAGH06gSEsAA1O99Nf2jPpkykYW6gD9NP7b4ntQaduawvASk+qLHiCsfKq/AZsp+jW 4ZKd4RUWF2imX2Xfl1ggadGyWZclErtl5IMm0us0NwjyPzrkApvhGsyexb8BS4AS0CyP wjRMay7GIzAZ6CbeZ6pzOPKx61kaA2jv7BglpowHlfo4QDVfFLOzLx09bI/QHcHaQpMB OF7tFv7UkxNgJZzlBSBnyiXSYReNqIQMvYVwtqiSoIq1ac0kmPrvpeVafhJzof2IHwLc +djQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DRP+RppCJq6ffQzj9IFqI19nyCxOb1EhZLgbovYRwHQ=; b=PSw5yK1LyfCInzb6Ix53Hh+wnP3nAHz6teKGE2gK0uoaMh4MifgNwN7O52oTCmNV4Y iSYSfL4rf3XhAUXrdAQkOvFZCf+ZfmbHSs6cBvcHkf7n4efuy28gu5EZ3tgEh87/7Une Rn89W6+6SL6NKa7TqCAEqMqcbVWrHdMW9gK9QLJy4eeMZH8xEvb28CtM29rfDTbl7MME 6Q1DJPizE7VaYEOpfDRMfEPAXgFltqCNZwMeJjS6Ty9wC5leXWHZn+Gn46Z0GvcUW9ho 7fnzstnL6pxyQqP5Rx/P8Ctow9N9LGljcpJpyucyZo3C38VlIm7wULbYyeuvyaBtPzxb WZYA== X-Gm-Message-State: AElRT7EPkOv/aajikFUZ+mXcLG/truVAINK22q4L1Z9CSC/NvpcxPzk5 0sx9s/jiJIsvY35NdlWq7Ko= X-Google-Smtp-Source: AIpwx4+F9bEKcsHkq2aRSywhGCcGReH9p1IU4h7JnBMkOu7iZDItWv1HCoPUOsWxqxO264XU86Ikbw== X-Received: by 10.101.80.205 with SMTP id s13mr7601502pgp.285.1522396286672; Fri, 30 Mar 2018 00:51:26 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:24 +0800 Message-Id: <20180330075128.26919-7-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH v3 06/10] migration: move some code to ram_save_host_page 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Move some code from ram_save_target_page() to ram_save_host_page() to make it be more readable for latter patches that dramatically clean ram_save_target_page() up Reviewed-by: Peter Xu Signed-off-by: Xiao Guangrong --- migration/ram.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 79c7958993..c3628b020e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1483,38 +1483,23 @@ err: * Returns the number of pages written * * @rs: current RAM state - * @ms: current migration state * @pss: data about the page we want to send * @last_stage: if we are at the completion stage */ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, bool last_stage) { - int res =3D 0; - - /* Check the pages is dirty and if it is send it */ - if (migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { - /* - * If xbzrle is on, stop using the data compression after first - * round of migration even if compression is enabled. In theory, - * xbzrle can do better than compression. - */ - if (migrate_use_compression() && - (rs->ram_bulk_stage || !migrate_use_xbzrle())) { - res =3D ram_save_compressed_page(rs, pss, last_stage); - } else { - res =3D ram_save_page(rs, pss, last_stage); - } - - if (res < 0) { - return res; - } - if (pss->block->unsentmap) { - clear_bit(pss->page, pss->block->unsentmap); - } + /* + * If xbzrle is on, stop using the data compression after first + * round of migration even if compression is enabled. In theory, + * xbzrle can do better than compression. + */ + if (migrate_use_compression() && + (rs->ram_bulk_stage || !migrate_use_xbzrle())) { + return ram_save_compressed_page(rs, pss, last_stage); } =20 - return res; + return ram_save_page(rs, pss, last_stage); } =20 /** @@ -1543,12 +1528,22 @@ static int ram_save_host_page(RAMState *rs, PageSea= rchStatus *pss, qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS; =20 do { + /* Check the pages is dirty and if it is send it */ + if (!migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { + pss->page++; + continue; + } + tmppages =3D ram_save_target_page(rs, pss, last_stage); if (tmppages < 0) { return tmppages; } =20 pages +=3D tmppages; + if (pss->block->unsentmap) { + clear_bit(pss->page, pss->block->unsentmap); + } + pss->page++; } while ((pss->page & (pagesize_bits - 1)) && offset_in_ramblock(pss->block, pss->page << TARGET_PAGE_BITS)= ); --=20 2.14.3 From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522396568325747.6442745471483; Fri, 30 Mar 2018 00:56:08 -0700 (PDT) Received: from localhost ([::1]:40909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1otL-0005wx-8I for importer@patchew.org; Fri, 30 Mar 2018 03:56:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oot-00022F-Qh for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1oos-0007fS-Sj for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:31 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:40031) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1oos-0007fH-Md for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:30 -0400 Received: by mail-pg0-x242.google.com with SMTP id h3so605482pgq.7 for ; Fri, 30 Mar 2018 00:51:30 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/ZZQLnC9y24MXAI8Da5LGtqV6MHDiGUV+fTyxg3VeSw=; b=VAiKecXbrcjVXQ2ok143KSidvX2BvjimmqOX0TUWc9hZVzBFReONLXLPL7klX9UdVo zuNumchQTk5KlVmyTVd86dFTx/f4EpCmqxLl96ZAT4IjUQuf2XdU2oLs8+BB3BnavqIG tcJAhyI5nePqWB1SL0rTRp4n76UewSTtbizPc3RCrQjQgbPPQSdSrrPmkGOYuSKlYMOP NNbxZhjCbjSWnsCpOy5XAafeDCbRGkemwGEAMJ+GaVgUhzGM1bqzeUKjM6v8JJQkqhSI suQF8jGut7wkT6toOFhinajQTPZNG8D9ZESuzbjsjboYQfFumeupHsyKCit5WQDIGXPp tYaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/ZZQLnC9y24MXAI8Da5LGtqV6MHDiGUV+fTyxg3VeSw=; b=M47NX6MvePyhXcPpblZNsuYYj7Pz8z1kxQG7MvZcLi8Q6QdUU3y3TdlIlEduAH9+s5 IKAxRhq0aJGDzg5NfRVWbNP2pmVqLxTgYyYwMlul80DPaEOcvAfex1LL5K/+eSt8KC2i CLtgwbfYPYJHzTAfnqGZB31G3FamdJjsrhQOtDhIR7HWU3vqmSiFlxBg5M9bv0kHlaAP SMQACmO8g4ov0RjQDREPgIjqqCHy5rbf0g48320FcydLGEChx7b9CNbIX7rdF6TZRUHA +JYqGIrxdp3gPgx5Y1w+6MC25M/FrErKxAFtlbxkLzGlxNQvQglVfxv+emw3jGSVJAPX jyDQ== X-Gm-Message-State: AElRT7G4Cv4GjLoCtZ6plNz/hKJ30vxOfQMn6EyHqResgP79XYJpRq+u yeYTo+vcxKfmns55swa7piU= X-Google-Smtp-Source: AIpwx499QewCw8XsiB+XE4Ny9hS7XIFQeNNQg93yKU0F1VYeZ78Nl1FMDWOt2yEl8CdItfDSY8FLdg== X-Received: by 2002:a17:902:7003:: with SMTP id y3-v6mr1544141plk.212.1522396289858; Fri, 30 Mar 2018 00:51:29 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:25 +0800 Message-Id: <20180330075128.26919-8-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH v3 07/10] migration: move calling control_save_page to the common place 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong The function is called by both ram_save_page and ram_save_target_page, so move it to the common caller to cleanup the code Reviewed-by: Peter Xu Signed-off-by: Xiao Guangrong --- migration/ram.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index c3628b020e..e0caf7182b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1037,10 +1037,6 @@ static int ram_save_page(RAMState *rs, PageSearchSta= tus *pss, bool last_stage) p =3D block->host + offset; trace_ram_save_page(block->idstr, (uint64_t)offset, p); =20 - if (control_save_page(rs, block, offset, &pages)) { - return pages; - } - XBZRLE_cache_lock(); pages =3D save_zero_page(rs, block, offset); if (pages > 0) { @@ -1198,10 +1194,6 @@ static int ram_save_compressed_page(RAMState *rs, Pa= geSearchStatus *pss, =20 p =3D block->host + offset; =20 - if (control_save_page(rs, block, offset, &pages)) { - return pages; - } - /* When starting the process of a new block, the first page of * the block should be sent out before other pages in the same * block, and all the pages in last block should have been sent @@ -1489,6 +1481,14 @@ err: static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, bool last_stage) { + RAMBlock *block =3D pss->block; + ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; + int res; + + if (control_save_page(rs, block, offset, &res)) { + return res; + } + /* * If xbzrle is on, stop using the data compression after first * round of migration even if compression is enabled. In theory, --=20 2.14.3 From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522396574140748.5627672894784; Fri, 30 Mar 2018 00:56:14 -0700 (PDT) Received: from localhost ([::1]:40910 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1otQ-00061W-T9 for importer@patchew.org; Fri, 30 Mar 2018 03:56:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oox-00026M-OQ for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1oow-0007gu-FN for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:35 -0400 Received: from mail-pf0-x22e.google.com ([2607:f8b0:400e:c00::22e]:33526) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1oow-0007gc-6f for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:34 -0400 Received: by mail-pf0-x22e.google.com with SMTP id f15so4989548pfn.0 for ; Fri, 30 Mar 2018 00:51:34 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+wi6bGU2RnsZmmSGZ1H+oLY4IV21UPz/4zJSdhuFFpk=; b=OZ8K0b1C1NUrLFTKwjokCXGWi0t8iAnvvSEGiDO6j3M2opouYkaia7PMNr1Ng+UAt9 iR7tSI9l9H+WGB6vUsxw2eySG9lw1F3TSMUGbhA6wrCdHC7dxxAxpDlRGMFtoqSIScmc 2hm1x9qpzAoS9MUxWQoJGtbabKoyrkw7jw6bqhppajOLak0W4qXxSXVl0JEmAKkpt5lq fzJrK/UKqjA4mt7j4/QoIskniggMaZ/ZU0H+UIPhQFERQ5cb70F9KyE2fP+U1crbdHEb KqcMbTIApbp6ZwkC+J5cObdUMiTrpfkagJjBwV1Tu5OyebfTR74uTXVP9IagzFvTrCvq p3zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+wi6bGU2RnsZmmSGZ1H+oLY4IV21UPz/4zJSdhuFFpk=; b=RQk5PSScb+WkuPOVhYJNwRO7BdGDk9ESR2U6hn5TFFFz3L73XHDsCpad0g6MP9tud9 zUq7LfLxlruB7wte7cob6Qs+wmmfWNj6JUDiE9IQ1QeiF8emIzCB1EhpnyUQgNIuXCqz td7TLh2faRko5SYeZD68e1jhBmHkddMaU8CRgH9WmtOvZ0ufDPvg+fJF/tK1Jc42drMW SZT1VPKexnLLo562T/mv83ClKUcKMlQTB1tUh/nFS6eLmfsw91J/JorHz2C1xRvAMnzC 4Hp5c9nr8RzfcEH41/nmM6uBEO3e7ZLMwQ8rpHAdlEmbj6jYF3vVxBHOmSaazvaHU0R5 sT2g== X-Gm-Message-State: AElRT7EFSS7hxI00/Dak0D+FccIE10AeITal/ISibXbRkdP48J63UUR2 +BL40rHKCX8DimlgV2YeaU8= X-Google-Smtp-Source: AIpwx499QIX7kCRMUOgXqvln5pFllza3vYmGLKwRni/CZ7bmREiUvMJPQkfW1ZoTjtaFp70HckSztw== X-Received: by 2002:a17:902:7245:: with SMTP id c5-v6mr11907280pll.217.1522396293229; Fri, 30 Mar 2018 00:51:33 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:26 +0800 Message-Id: <20180330075128.26919-9-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22e Subject: [Qemu-devel] [PATCH v3 08/10] migration: move calling save_zero_page to the common place 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong save_zero_page() is always our first approach to try, move it to the common place before calling ram_save_compressed_page and ram_save_page Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Xiao Guangrong --- migration/ram.c | 105 +++++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 59 insertions(+), 46 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index e0caf7182b..97917542c5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1038,15 +1038,8 @@ static int ram_save_page(RAMState *rs, PageSearchSta= tus *pss, bool last_stage) trace_ram_save_page(block->idstr, (uint64_t)offset, p); =20 XBZRLE_cache_lock(); - pages =3D save_zero_page(rs, block, offset); - if (pages > 0) { - /* Must let xbzrle know, otherwise a previous (now 0'd) cached - * page would be stale - */ - xbzrle_cache_zero_page(rs, current_addr); - ram_release_pages(block->idstr, offset, pages); - } else if (!rs->ram_bulk_stage && - !migration_in_postcopy() && migrate_use_xbzrle()) { + if (!rs->ram_bulk_stage && !migration_in_postcopy() && + migrate_use_xbzrle()) { pages =3D save_xbzrle_page(rs, &p, current_addr, block, offset, last_stage); if (!last_stage) { @@ -1194,40 +1187,23 @@ static int ram_save_compressed_page(RAMState *rs, P= ageSearchStatus *pss, =20 p =3D block->host + offset; =20 - /* When starting the process of a new block, the first page of - * the block should be sent out before other pages in the same - * block, and all the pages in last block should have been sent - * out, keeping this order is important, because the 'cont' flag - * is used to avoid resending the block name. - */ if (block !=3D rs->last_sent_block) { - flush_compressed_data(rs); - pages =3D save_zero_page(rs, block, offset); - if (pages > 0) { - ram_release_pages(block->idstr, offset, pages); - } else { - /* - * Make sure the first page is sent out before other pages. - * - * we post it as normal page as compression will take much - * CPU resource. - */ - ram_counters.transferred +=3D save_page_header(rs, rs->f, bloc= k, - offset | RAM_SAVE_FLAG_PAGE); - qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, - migrate_release_ram() & - migration_in_postcopy()); - ram_counters.transferred +=3D TARGET_PAGE_SIZE; - ram_counters.normal++; - pages =3D 1; - } + /* + * Make sure the first page is sent out before other pages. + * + * we post it as normal page as compression will take much + * CPU resource. + */ + ram_counters.transferred +=3D save_page_header(rs, rs->f, block, + offset | RAM_SAVE_FLAG_PAGE); + qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, + migrate_release_ram() & + migration_in_postcopy()); + ram_counters.transferred +=3D TARGET_PAGE_SIZE; + ram_counters.normal++; + pages =3D 1; } else { - pages =3D save_zero_page(rs, block, offset); - if (pages =3D=3D -1) { - pages =3D compress_page_with_multi_thread(rs, block, offset); - } else { - ram_release_pages(block->idstr, offset, pages); - } + pages =3D compress_page_with_multi_thread(rs, block, offset); } =20 return pages; @@ -1469,6 +1445,24 @@ err: return -1; } =20 +static bool save_page_use_compression(RAMState *rs) +{ + if (!migrate_use_compression()) { + return false; + } + + /* + * If xbzrle is on, stop using the data compression after first + * round of migration even if compression is enabled. In theory, + * xbzrle can do better than compression. + */ + if (rs->ram_bulk_stage || !migrate_use_xbzrle()) { + return true; + } + + return false; +} + /** * ram_save_target_page: save one target page * @@ -1490,12 +1484,31 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss, } =20 /* - * If xbzrle is on, stop using the data compression after first - * round of migration even if compression is enabled. In theory, - * xbzrle can do better than compression. + * When starting the process of a new block, the first page of + * the block should be sent out before other pages in the same + * block, and all the pages in last block should have been sent + * out, keeping this order is important, because the 'cont' flag + * is used to avoid resending the block name. */ - if (migrate_use_compression() && - (rs->ram_bulk_stage || !migrate_use_xbzrle())) { + if (block !=3D rs->last_sent_block && save_page_use_compression(rs)) { + flush_compressed_data(rs); + } + + res =3D save_zero_page(rs, block, offset); + if (res > 0) { + /* Must let xbzrle know, otherwise a previous (now 0'd) cached + * page would be stale + */ + if (!save_page_use_compression(rs)) { + XBZRLE_cache_lock(); + xbzrle_cache_zero_page(rs, block->offset + offset); + XBZRLE_cache_unlock(); + } + ram_release_pages(block->idstr, offset, res); + return res; + } + + if (save_page_use_compression(rs)) { return ram_save_compressed_page(rs, pss, last_stage); } =20 --=20 2.14.3 From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522396703185833.8595541074279; Fri, 30 Mar 2018 00:58:23 -0700 (PDT) Received: from localhost ([::1]:41111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1ovW-00086T-1g for importer@patchew.org; Fri, 30 Mar 2018 03:58:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1op1-000292-0C for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1ooz-0007ie-I6 for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:39 -0400 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]:44557) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1ooz-0007iY-Bj for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:37 -0400 Received: by mail-pf0-x229.google.com with SMTP id m68so4981236pfm.11 for ; Fri, 30 Mar 2018 00:51:37 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Wee6hB1rpXgOf1s4KkwmsEQwUMDIgf1HCAuTBaNpP/Y=; b=p5YThq44g+eWNXQrDIPkhNE3ZCZNRHVF6TS+w8CFE2FB+896Gv8MLRfUsm7VqBLsXz 4Rr06Q3/FybzAwqn5bmUOePDNN7c5MJWTPofB7uXySV/6NUPz5eO0o1AOF54dGwuFhmm qMgfu3SNRzIYN2MUeioq87CRCs9Tq2kLsfcppFaMhgQ5v8hU7TX2dJDBTU4K84w4duL6 7qoYWoobKXK0zAqUC0jUXTilS1u3G2QAq8LRxZnIdCpYEQJjAVKzBbsJ9xRBmK3ix7/o P7UOl6StujhSf7MUQ0MmMV8l8fAbYmXMDIqmy904Q6q7zT3ajCh+qvQEsSmGoMan9rDN drdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Wee6hB1rpXgOf1s4KkwmsEQwUMDIgf1HCAuTBaNpP/Y=; b=pQdOPDJtOVfKgQIrEdy/8X6EJwsuwmAXj/fOmMnNad9APZVCnJOkB5OR4mgvBBJ3pe n8ttlmPkoKhquN4+3sRnlUqcbOcv/rGIJZyFYoV3T/U58qLu373qdq/nmyJPRjuEswjD NAfEExpCbJfUfo0FrlCDUQkWs9H8WuyzVTZMfiqt8S32GM2FEaag/AR0Pzyj0nYs82rl m5S5IGiZJZ49cNyct8hiyW5N6kd66qZVS85pdBBIHF6mx06IFGv276/sf7kdt9v4aDHn 1i3oASKcz2a8aiJ4+ZLWC6cYeQjyfg18yX0+V1IEym6tHCFIQtCrW0XFLdsp5hKkU2ji RjPA== X-Gm-Message-State: AElRT7GSZN7NWSSrydgcU/Ww7b9v16654MRiiLR8AJSI8NyIIYQt5koX yDSXT/NXVJTi7BQHoZi1QZI= X-Google-Smtp-Source: AIpwx4+OmQ4yIbx6a9RaLiC58mNRUVmQdui2ZYnJPzwhiIGrj7GUpKMUuQQC5KwvJtC+tEnE4g9F5g== X-Received: by 10.98.194.142 with SMTP id w14mr6336042pfk.226.1522396296426; Fri, 30 Mar 2018 00:51:36 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:27 +0800 Message-Id: <20180330075128.26919-10-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::229 Subject: [Qemu-devel] [PATCH v3 09/10] migration: introduce save_normal_page() 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong It directly sends the page to the stream neither checking zero nor using xbzrle or compression Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Xiao Guangrong --- migration/ram.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 97917542c5..2eb4c0bf49 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1012,6 +1012,34 @@ static bool control_save_page(RAMState *rs, RAMBlock= *block, ram_addr_t offset, return true; } =20 +/* + * directly send the page to the stream + * + * Returns the number of pages written. + * + * @rs: current RAM state + * @block: block that contains the page we want to send + * @offset: offset inside the block for the page + * @buf: the page to be sent + * @async: send to page asyncly + */ +static int save_normal_page(RAMState *rs, RAMBlock *block, ram_addr_t offs= et, + uint8_t *buf, bool async) +{ + ram_counters.transferred +=3D save_page_header(rs, rs->f, block, + offset | RAM_SAVE_FLAG_PA= GE); + if (async) { + qemu_put_buffer_async(rs->f, buf, TARGET_PAGE_SIZE, + migrate_release_ram() & + migration_in_postcopy()); + } else { + qemu_put_buffer(rs->f, buf, TARGET_PAGE_SIZE); + } + ram_counters.transferred +=3D TARGET_PAGE_SIZE; + ram_counters.normal++; + return 1; +} + /** * ram_save_page: send the given page to the stream * @@ -1052,18 +1080,7 @@ static int ram_save_page(RAMState *rs, PageSearchSta= tus *pss, bool last_stage) =20 /* XBZRLE overflow or normal page */ if (pages =3D=3D -1) { - ram_counters.transferred +=3D - save_page_header(rs, rs->f, block, offset | RAM_SAVE_FLAG_PAGE= ); - if (send_async) { - qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, - migrate_release_ram() & - migration_in_postcopy()); - } else { - qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); - } - ram_counters.transferred +=3D TARGET_PAGE_SIZE; - pages =3D 1; - ram_counters.normal++; + pages =3D save_normal_page(rs, block, offset, p, send_async); } =20 XBZRLE_cache_unlock(); @@ -1194,14 +1211,7 @@ static int ram_save_compressed_page(RAMState *rs, Pa= geSearchStatus *pss, * we post it as normal page as compression will take much * CPU resource. */ - ram_counters.transferred +=3D save_page_header(rs, rs->f, block, - offset | RAM_SAVE_FLAG_PAGE); - qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, - migrate_release_ram() & - migration_in_postcopy()); - ram_counters.transferred +=3D TARGET_PAGE_SIZE; - ram_counters.normal++; - pages =3D 1; + pages =3D save_normal_page(rs, block, offset, p, true); } else { pages =3D compress_page_with_multi_thread(rs, block, offset); } --=20 2.14.3 From nobody Mon May 6 05:47:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522396814748290.5227144009914; Fri, 30 Mar 2018 01:00:14 -0700 (PDT) Received: from localhost ([::1]:41169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oxH-0001Kv-S7 for importer@patchew.org; Fri, 30 Mar 2018 04:00:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1op3-0002Bb-IW for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1op2-0007mQ-Nm for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:41 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:41910) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1op2-0007lT-H5 for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:40 -0400 Received: by mail-pg0-x241.google.com with SMTP id t10so4664569pgv.8 for ; Fri, 30 Mar 2018 00:51:40 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oy/IApCirRmzaHbTwpG1z5Fsc+1VQHF3Ps2Wiwo+R9A=; b=NN7GXWPAM90+aXEv4/t9cDf5vimyjTW2jIlurUHJako170j6nZnHE5QtkjUKYlnewy 9Cdh70rm6khBRaIoQll5Cc8a+S1uK3T2x6vIklOKOnZr9HAKzKidpRax/6rrM8fvSkQ3 nwb1FRY+6kTkCkgxntW972CNXTgPqLZqSds+KCf3kqGy6NFvvZXnltuMJM9lXsbDCcV2 zvd8TIkCkLpHmABsT7PDXSpBNOFwpNuaHmleJzd5HR/j2Hopn7b3KmfXlFxqlZzga00A 3nQ+GVwe5z2Q663MQh1oe6Ew4hN+F/e+uw3IDQDqge9ddfcoHED//w3rUGXIsLe3napW eppg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oy/IApCirRmzaHbTwpG1z5Fsc+1VQHF3Ps2Wiwo+R9A=; b=iHDXX2QdZgcazoa8thmaaPcKbzeS9iM/QvtJz7mg7kGbrr4FJh9OPmPvKJtFVYgScq New6zGyDR4raEu/HjdHyXrpIMLY1I9o0TbXMI3i9oyzJ1IMFtn5q6f0DDrypFrI7MyWp S9qcsjunruNycZMIKsInoic/T1vAPR7DeP0naENVVKSIFX3gmySylp/LbnOVLN7g5tFg k0eIh/l8d+zsnCFuWFfsYiaUkb43kKsnB8YsRfynOnzbg5N/p1rpoQT6rLev4JSeaYVB oFMx0sBoYEmAyPS9JADEv4Ge1ofzQHJXWxw8QCODyo0WNfVm3g8V68tQZdaAu2jjPlhh /QjA== X-Gm-Message-State: AElRT7HD8l9b30cFd/aVMkkyYzlFgtEQ2HZ03nNk5JZ8FBxFmtcBQT/I 1gwbNgHPSxaatTeY4bvisbc= X-Google-Smtp-Source: AIpwx4/69JA39+KfAL7idvDwICh58VUyhgBgNIseTLxZGkSDeH5x1KhWSRV9tM1vfBhYVkWghaTL4A== X-Received: by 2002:a17:902:2943:: with SMTP id g61-v6mr12061088plb.238.1522396299595; Fri, 30 Mar 2018 00:51:39 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:28 +0800 Message-Id: <20180330075128.26919-11-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH v3 10/10] migration: remove ram_save_compressed_page() 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Now, we can reuse the path in ram_save_page() to post the page out as normal, then the only thing remained in ram_save_compressed_page() is compression that we can move it out to the caller Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Xiao Guangrong --- migration/ram.c | 45 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 2eb4c0bf49..912810c18e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1184,41 +1184,6 @@ static int compress_page_with_multi_thread(RAMState = *rs, RAMBlock *block, return pages; } =20 -/** - * ram_save_compressed_page: compress the given page and send it to the st= ream - * - * Returns the number of pages written. - * - * @rs: current RAM state - * @block: block that contains the page we want to send - * @offset: offset inside the block for the page - * @last_stage: if we are at the completion stage - */ -static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss, - bool last_stage) -{ - int pages =3D -1; - uint8_t *p; - RAMBlock *block =3D pss->block; - ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; - - p =3D block->host + offset; - - if (block !=3D rs->last_sent_block) { - /* - * Make sure the first page is sent out before other pages. - * - * we post it as normal page as compression will take much - * CPU resource. - */ - pages =3D save_normal_page(rs, block, offset, p, true); - } else { - pages =3D compress_page_with_multi_thread(rs, block, offset); - } - - return pages; -} - /** * find_dirty_block: find the next dirty page and update any state * associated with the search process. @@ -1518,8 +1483,14 @@ static int ram_save_target_page(RAMState *rs, PageSe= archStatus *pss, return res; } =20 - if (save_page_use_compression(rs)) { - return ram_save_compressed_page(rs, pss, last_stage); + /* + * Make sure the first page is sent out before other pages. + * + * we post it as normal page as compression will take much + * CPU resource. + */ + if (block =3D=3D rs->last_sent_block && save_page_use_compression(rs))= { + res =3D compress_page_with_multi_thread(rs, block, offset); } =20 return ram_save_page(rs, pss, last_stage); --=20 2.14.3