From patchwork Thu May 5 07:32:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 618865 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 3r0n1z6Hswz9ssM for ; Thu, 5 May 2016 17:42:47 +1000 (AEST) Received: from localhost ([::1]:52222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayDvm-0002EC-QM for incoming@patchwork.ozlabs.org; Thu, 05 May 2016 03:42:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayDr5-00015i-I6 for qemu-devel@nongnu.org; Thu, 05 May 2016 03:37:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayDqt-0001L6-KN for qemu-devel@nongnu.org; Thu, 05 May 2016 03:37:46 -0400 Received: from mga09.intel.com ([134.134.136.24]:40529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayDqt-0001DH-DM for qemu-devel@nongnu.org; Thu, 05 May 2016 03:37:39 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 05 May 2016 00:36:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,581,1455004800"; d="scan'208";a="946675636" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.27]) by orsmga001.jf.intel.com with ESMTP; 05 May 2016 00:36:53 -0700 From: Liang Li To: qemu-devel@nongnu.org Date: Thu, 5 May 2016 15:32:55 +0800 Message-Id: <1462433579-13691-6-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462433579-13691-1-git-send-email-liang.z.li@intel.com> References: <1462433579-13691-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: 134.134.136.24 Subject: [Qemu-devel] [PATCH v2 5/9] migration: refine 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: amit.shah@redhat.com, Liang Li , dgilbert@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use qemu_put_compression_data to do the compression directly instead of using do_compress_ram_page, avoid some data copy. very small improvement, at the same time, add code to check if the compression is successful. Signed-off-by: Liang Li --- migration/ram.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 8a21c2c..1a45227 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -929,24 +929,20 @@ static int ram_save_compressed_page(QEMUFile *f, PageSearchStatus *pss, uint64_t *bytes_transferred) { int pages = -1; - uint64_t bytes_xmit; + uint64_t bytes_xmit = 0; uint8_t *p; - int ret; + int ret, blen; RAMBlock *block = pss->block; ram_addr_t offset = pss->offset; p = block->host + offset; - bytes_xmit = 0; ret = ram_control_save_page(f, block->offset, offset, TARGET_PAGE_SIZE, &bytes_xmit); if (bytes_xmit) { *bytes_transferred += bytes_xmit; pages = 1; } - if (block == last_sent_block) { - offset |= RAM_SAVE_FLAG_CONTINUE; - } if (ret != RAM_SAVE_CONTROL_NOT_SUPP) { if (ret != RAM_SAVE_CONTROL_DELAYED) { if (bytes_xmit > 0) { @@ -966,19 +962,22 @@ static int ram_save_compressed_page(QEMUFile *f, PageSearchStatus *pss, 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]); - if (bytes_xmit > 0) { + /* Make sure the first page is sent out before other pages */ + bytes_xmit = save_page_header(f, block, offset | + RAM_SAVE_FLAG_COMPRESS_PAGE); + blen = qemu_put_compression_data(f, p, TARGET_PAGE_SIZE, + migrate_compress_level()); + if (blen > 0) { + *bytes_transferred += bytes_xmit + blen; acct_info.norm_pages++; - qemu_put_qemu_file(f, comp_param[0].file); - *bytes_transferred += bytes_xmit; pages = 1; + } else { + qemu_file_set_error(f, blen); + error_report("compressed data failed!"); } } } else { + offset |= RAM_SAVE_FLAG_CONTINUE; pages = save_zero_page(f, block, offset, p, bytes_transferred); if (pages == -1) { pages = compress_page_with_multi_thread(f, block, offset,