From patchwork Tue Aug 25 11:59:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 510472 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D2493140295 for ; Tue, 25 Aug 2015 22:00:56 +1000 (AEST) Received: from localhost ([::1]:59566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUCuM-0007X2-Rc for incoming@patchwork.ozlabs.org; Tue, 25 Aug 2015 08:00:54 -0400 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 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 25 Aug 2015 05:00:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,745,1432623600"; d="scan'208";a="790487484" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.27]) by fmsmga002.fm.intel.com with ESMTP; 25 Aug 2015 05:00:12 -0700 From: Liang Li To: qemu-devel@nongnu.org Date: Tue, 25 Aug 2015 19:59:09 +0800 Message-Id: <1440503950-14174-3-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 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> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Cc: amit.shah@redhat.com, yang.z.zhang@intel.com, Liang Li , dgilbert@redhat.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 2/3] migration: optimization for one compression thread X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 {