From patchwork Fri Mar 30 07:51:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10317329 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 2D32960383 for ; Fri, 30 Mar 2018 07:55:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23C0B2A559 for ; Fri, 30 Mar 2018 07:55:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1893F2A565; Fri, 30 Mar 2018 07:55:42 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 978462A559 for ; Fri, 30 Mar 2018 07:55:41 +0000 (UTC) Received: from localhost ([::1]:40910 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1osu-00061W-Pl for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Mar 2018 03:55:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1oox-00026M-OQ for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1oow-0007gu-FN for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:35 -0400 Received: from mail-pf0-x22e.google.com ([2607:f8b0:400e:c00::22e]:33526) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1oow-0007gc-6f for qemu-devel@nongnu.org; Fri, 30 Mar 2018 03:51:34 -0400 Received: by mail-pf0-x22e.google.com with SMTP id f15so4989548pfn.0 for ; Fri, 30 Mar 2018 00:51:34 -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=+wi6bGU2RnsZmmSGZ1H+oLY4IV21UPz/4zJSdhuFFpk=; b=OZ8K0b1C1NUrLFTKwjokCXGWi0t8iAnvvSEGiDO6j3M2opouYkaia7PMNr1Ng+UAt9 iR7tSI9l9H+WGB6vUsxw2eySG9lw1F3TSMUGbhA6wrCdHC7dxxAxpDlRGMFtoqSIScmc 2hm1x9qpzAoS9MUxWQoJGtbabKoyrkw7jw6bqhppajOLak0W4qXxSXVl0JEmAKkpt5lq fzJrK/UKqjA4mt7j4/QoIskniggMaZ/ZU0H+UIPhQFERQ5cb70F9KyE2fP+U1crbdHEb KqcMbTIApbp6ZwkC+J5cObdUMiTrpfkagJjBwV1Tu5OyebfTR74uTXVP9IagzFvTrCvq p3zA== 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=+wi6bGU2RnsZmmSGZ1H+oLY4IV21UPz/4zJSdhuFFpk=; b=RQk5PSScb+WkuPOVhYJNwRO7BdGDk9ESR2U6hn5TFFFz3L73XHDsCpad0g6MP9tud9 zUq7LfLxlruB7wte7cob6Qs+wmmfWNj6JUDiE9IQ1QeiF8emIzCB1EhpnyUQgNIuXCqz td7TLh2faRko5SYeZD68e1jhBmHkddMaU8CRgH9WmtOvZ0ufDPvg+fJF/tK1Jc42drMW SZT1VPKexnLLo562T/mv83ClKUcKMlQTB1tUh/nFS6eLmfsw91J/JorHz2C1xRvAMnzC 4Hp5c9nr8RzfcEH41/nmM6uBEO3e7ZLMwQ8rpHAdlEmbj6jYF3vVxBHOmSaazvaHU0R5 sT2g== X-Gm-Message-State: AElRT7EFSS7hxI00/Dak0D+FccIE10AeITal/ISibXbRkdP48J63UUR2 +BL40rHKCX8DimlgV2YeaU8= X-Google-Smtp-Source: AIpwx499QIX7kCRMUOgXqvln5pFllza3vYmGLKwRni/CZ7bmREiUvMJPQkfW1ZoTjtaFp70HckSztw== X-Received: by 2002:a17:902:7245:: with SMTP id c5-v6mr11907280pll.217.1522396293229; Fri, 30 Mar 2018 00:51:33 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id r75sm16557107pfb.98.2018.03.30.00.51.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Mar 2018 00:51:32 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Fri, 30 Mar 2018 15:51:26 +0800 Message-Id: <20180330075128.26919-9-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180330075128.26919-1-xiaoguangrong@tencent.com> References: <20180330075128.26919-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22e Subject: [Qemu-devel] [PATCH v3 08/10] migration: move calling save_zero_page to the common place 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Xiao Guangrong --- migration/ram.c | 105 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 46 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index e0caf7182b..97917542c5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1038,15 +1038,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) { @@ -1194,40 +1187,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; @@ -1469,6 +1445,24 @@ 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 * @@ -1490,12 +1484,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); + return res; + } + + if (save_page_use_compression(rs)) { return ram_save_compressed_page(rs, pss, last_stage); }