From patchwork Tue Mar 13 07:57:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10277871 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 C2071602C2 for ; Tue, 13 Mar 2018 07:58:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACF3828BDA for ; Tue, 13 Mar 2018 07:58:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A196D28BE4; Tue, 13 Mar 2018 07:58:14 +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=-7.0 required=2.0 tests=BAYES_00,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 2F25228BDA for ; Tue, 13 Mar 2018 07:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752201AbeCMH6M (ORCPT ); Tue, 13 Mar 2018 03:58:12 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:41972 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752148AbeCMH6L (ORCPT ); Tue, 13 Mar 2018 03:58:11 -0400 Received: by mail-pf0-f177.google.com with SMTP id f80so5533666pfa.8 for ; Tue, 13 Mar 2018 00:58: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=Sy0QgZyuQbOLpLoSQmr/2TpPuWfOE10HoH7QZAwRxmo=; b=ouk+9VSauBsLZF3tdqUb+SUFoFHVKj2X2FvVtn346DgyAHWD2ZfuyCenfK7f+i1PR3 H0Rm1qSnxd7oSG5wHa0bMWJ3y7w8RG60LFT30LWJZXQW29s3RjQJ3haTt64Q/BJJbLKj fRDaA4FJ375NFR2C7gKhb+2CDVyitbqmCnm368JIuioC22Gtsilm0qble1k/6Va5b9nk eQy8VbdNjILTdhgJ+T9mCM++JrE+4gtpO5D9d6UvxXcXAZ7mF3eG0VPPhMWW4dEdSEnr e5GNdSmfEhdw7SmDG3s2MBPcLxFAsXlBgHlGPM7OFThHEZYvOFZDaRsb4DkostPCr4CG Vntw== 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=Sy0QgZyuQbOLpLoSQmr/2TpPuWfOE10HoH7QZAwRxmo=; b=aQvjTd0AgtLtNv4aHn7G5ninxf+F7t8X7I7tMv7T9sM2vuS5AnKianwjfQZIVNZpfo EXJzqwlj7S4tR+FJnZPT8SJKi0WyMbvZ2JHRFLkk/2sMZqp2H4PVamc9jPh1RA1Ca9Ed nfBD7DsUvTERSpLodefiPp3UGN5+m40X76aMuatRIe9z70o7RZMCDftjc5J0AISzENV1 Ff17AEaTxr7waWAIHaktRtAg1I9vHfTvxRU1JZaseXfwh3CSYlRMRZPgX41kHKYVZyQi fGghtLgctDnf9HQ1YnYlzrFSUmluzo2J2BG+FJ8UNypNkjYx6DSozCQTDVI5VKtFToO6 Ao2Q== X-Gm-Message-State: AElRT7HybrifY9IMAAukNqIowpOxu5oC9RdZR7/aeJz5feKmKQF8OoHd XBVEyW0mTkSKIb6klRGn374= X-Google-Smtp-Source: AG47ELtPvlz46blcov7/6si/Q6hz/C0t+a+AkQIZJ4xYQdF+KygoFZmGBXSSUrCghvj1VvrNRy6RUQ== X-Received: by 10.98.220.207 with SMTP id c76mr10691333pfl.159.1520927890438; Tue, 13 Mar 2018 00:58:10 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.35]) by smtp.gmail.com with ESMTPSA id x4sm16756537pgv.72.2018.03.13.00.58.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Mar 2018 00:58: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 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Xiao Guangrong Subject: [PATCH 6/8] migration: move calling save_zero_page to the common place Date: Tue, 13 Mar 2018 15:57:37 +0800 Message-Id: <20180313075739.11194-7-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313075739.11194-1-xiaoguangrong@tencent.com> References: <20180313075739.11194-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 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 Signed-off-by: Xiao Guangrong Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu --- migration/ram.c | 106 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 839665d866..9627ce18e9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1021,15 +1021,8 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_stage) trace_ram_save_page(block->idstr, (uint64_t)offset, p); XBZRLE_cache_lock(); - pages = 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 = save_xbzrle_page(rs, &p, current_addr, block, offset, last_stage); if (!last_stage) { @@ -1172,40 +1165,23 @@ static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss, p = block->host + offset; - /* 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 != rs->last_sent_block) { - flush_compressed_data(rs); - pages = 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 += 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; - } + /* + * 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); - if (pages == -1) { - pages = compress_page_with_multi_thread(rs, block, offset); - } else { - ram_release_pages(block->idstr, offset, pages); - } + pages = compress_page_with_multi_thread(rs, block, offset); } return pages; @@ -1447,6 +1423,25 @@ err: return -1; } +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 * @@ -1472,12 +1467,31 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, } /* - * 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 != rs->last_sent_block && save_page_use_compression(rs)) { + flush_compressed_data(rs); + } + + res = 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); + goto page_saved; + } + + if (save_page_use_compression(rs)) { res = ram_save_compressed_page(rs, pss, last_stage); } else { res = ram_save_page(rs, pss, last_stage);