From patchwork Tue Mar 27 09:10:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10312555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8648560212 for ; Wed, 28 Mar 2018 09:10:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78B6A29C2C for ; Wed, 28 Mar 2018 09:10:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D3CA29C34; Wed, 28 Mar 2018 09:10:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=2.0 tests=BAYES_00, DATE_IN_PAST_12_24, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D930729C2C for ; Wed, 28 Mar 2018 09:10:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751223AbeC1JK2 (ORCPT ); Wed, 28 Mar 2018 05:10:28 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:38064 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751166AbeC1JK0 (ORCPT ); Wed, 28 Mar 2018 05:10:26 -0400 Received: by mail-pg0-f68.google.com with SMTP id a15so710098pgn.5 for ; Wed, 28 Mar 2018 02:10: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=TL1XWhIt+sETAFduxXn4nL0YeK0YLzCPZxJw286oiUg=; b=eoN1Ck9XMmxWPUpfGeNrYdJbnYwiF0+2GycSflA1NyHlURopUJhE7orbNDpDQjF4Wc B50IAIndhiB8WKEiwmbrrzUrlLA3vQxFOkUGlAvie9BOc63zAUdZ+2oW2lIFhqtQM96F vtK6squJBjOh7Jvs9MSx6N2xkpBxsWADbWKj9MtJRGSYunSFO6G1pydvdjEONVEutlx7 SlSZbcP02WjPq3hlnFgdllpl1N2vFVrK7aDOV8g8RgolntwIw+BM0JNxS7z3NYYo4g7R 7VsXz+gzgg9t1SG8jsdwUjMMM0LEnxFZ8YVl1L5t2mfUEAAtaW69GfnCKSAvtkeWbas/ 0Upw== 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=E4Q4s3g/uDQvCnjPoLMJyYo848SEgTAStjIrt1cIUS09aSfRiqdi0wtbnrPJkBDles 0ZYccGa9vlRuHG9v5WLvhWEzqyNmCRSuWgIYbNfOLnvFT0JRLvH7T86yyc0sQU2C0ZGY eUs3WYxyG8qzFJGKhZfjHmA2YxS70k61xjjixPY2vAyqxuyCUqd7rfsQsxvwLGV/ZVOG ad5kunrmIe2gOx+DzEoKHCfPPZaJaZyGJHGFp1h6PdIOXXiR0XmBy9rFJ69eK8g5RjPv d1PUbbUpaWT+lWDTdZEz9xUNLZxqVwgPtcJj2Vvn1NrIlEZnfYX8pk5YrVt93xmEuHiZ IikQ== X-Gm-Message-State: AElRT7FxspYo1TMGZrNjtAyB+ER8VAGPdtdnMnb1BNs8nu78dIUL66+W RNuCnlilYzeTuibQNqtajkg= X-Google-Smtp-Source: AIpwx4/XAroKcoWqFf+tJ+h/MPP5W2h4lw0W+/qd8TqK6uFYtn3iGkom5/PPudB6Ft/BNhhJCChn/Q== X-Received: by 10.98.174.23 with SMTP id q23mr2311480pff.103.1522228226272; Wed, 28 Mar 2018 02:10:26 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id q9sm5590648pgs.89.2018.03.28.02.10.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Mar 2018 02:10:25 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, dgilbert@redhat.com, peterx@redhat.com, jiang.biao2@zte.com.cn, wei.w.wang@intel.com, Xiao Guangrong Subject: [PATCH v2 01/10] migration: stop compressing page in migration thread Date: Tue, 27 Mar 2018 17:10:34 +0800 Message-Id: <20180327091043.30220-2-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180327091043.30220-1-xiaoguangrong@tencent.com> References: <20180327091043.30220-1-xiaoguangrong@tencent.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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, PageSearchStatus *pss, int pages = -1; uint64_t bytes_xmit = 0; uint8_t *p; - int ret, blen; + int ret; RAMBlock *block = pss->block; ram_addr_t offset = pss->page << TARGET_PAGE_BITS; @@ -1167,23 +1167,23 @@ static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss, if (block != rs->last_sent_block) { flush_compressed_data(rs); pages = save_zero_page(rs, block, offset); - if (pages == -1) { - /* Make sure the first page is sent out before other pages */ - bytes_xmit = save_page_header(rs, rs->f, block, offset | - RAM_SAVE_FLAG_COMPRESS_PAGE); - blen = qemu_put_compression_data(rs->f, p, TARGET_PAGE_SIZE, - migrate_compress_level()); - if (blen > 0) { - ram_counters.transferred += bytes_xmit + blen; - ram_counters.normal++; - pages = 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 += 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 += TARGET_PAGE_SIZE; + ram_counters.normal++; + pages = 1; } } else { pages = save_zero_page(rs, block, offset);