Received: from eggs.gnu.org ([2001:4830:134:3::10]:56331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUCtn-0006w1-5h for qemu-devel@nongnu.org; Tue, 25 Aug 2015 08:00:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUCtj-0006EV-Uq for qemu-devel@nongnu.org; Tue, 25 Aug 2015 08:00:19 -0400 Received: from mga11.intel.com ([192.55.52.93]:23275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUCtj-0006E4-HL for qemu-devel@nongnu.org; Tue, 25 Aug 2015 08:00:15 -0400 From: Liang Li Date: Tue, 25 Aug 2015 19:59:09 +0800 Message-Id: <1440503950-14174-3-git-send-email-liang.z.li@intel.com> In-Reply-To: <1440503950-14174-1-git-send-email-liang.z.li@intel.com> References: <1440503950-14174-1-git-send-email-liang.z.li@intel.com> Subject: [Qemu-devel] [PATCH 2/3] migration: optimization for one compression thread List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: amit.shah@redhat.com, yang.z.zhang@intel.com, Liang Li , dgilbert@redhat.com, quintela@redhat.com When the compression thread count is set to 1, the current implementation is inefficient because of the following reason: 1. Thread synchronization cost; 2. Data copy; 3. No benefit from the separate compression thread; This patch optimizes the performance for the case of 1 compress thread. In this case, the compression is done in the migration thread, for some fast compression algorithm, it can help to improve the performance. Signed-off-by: Liang Li --- migration/ram.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 7f007e6..0cc4f81 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -318,8 +318,13 @@ void migrate_compress_threads_join(void) if (!migrate_use_compression()) { return; } - terminate_compression_threads(); + thread_count = migrate_compress_threads(); + if (thread_count == 1) { + return; + } + + terminate_compression_threads(); for (i = 0; i < thread_count; i++) { qemu_thread_join(compress_threads + i); qemu_fclose(comp_param[i].file); @@ -345,9 +350,12 @@ void migrate_compress_threads_create(void) if (!migrate_use_compression()) { return; } + thread_count = migrate_compress_threads(); + if (thread_count == 1) { + return; + } quit_comp_thread = false; compression_switch = true; - thread_count = migrate_compress_threads(); compress_threads = g_new0(QemuThread, thread_count); comp_param = g_new0(CompressParam, thread_count); comp_done_cond = g_new0(QemuCond, 1); @@ -782,6 +790,9 @@ static void flush_compressed_data(QEMUFile *f) return; } thread_count = migrate_compress_threads(); + if (thread_count == 1) { + return; + } for (idx = 0; idx < thread_count; idx++) { if (!comp_param[idx].done) { qemu_mutex_lock(comp_done_lock); @@ -883,18 +894,16 @@ static int ram_save_compressed_page(QEMUFile *f, RAMBlock *block, * out, keeping this order is important, because the 'cont' flag * is used to avoid resending the block name. */ - if (block != last_sent_block) { + if (block != last_sent_block || migrate_compress_threads() == 1) { flush_compressed_data(f); pages = save_zero_page(f, block, offset, p, bytes_transferred); if (pages == -1) { - set_compress_params(&comp_param[0], block, offset); - /* Use the qemu thread to compress the data to make sure the - * first page is sent out before other pages - */ - bytes_xmit = do_compress_ram_page(&comp_param[0]); - acct_info.norm_pages++; - qemu_put_qemu_file(f, comp_param[0].file); + bytes_xmit = save_page_header(f, block, offset | + RAM_SAVE_FLAG_COMPRESS_PAGE); + bytes_xmit += qemu_put_compression_data(f, p, TARGET_PAGE_SIZE, + migrate_compress_level()); *bytes_transferred += bytes_xmit; + acct_info.norm_pages++; pages = 1; } } else { -- 1.9.1