From patchwork Tue Mar 27 09:10:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10312579 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 4BED560212 for ; Wed, 28 Mar 2018 09:12:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E8FB29846 for ; Wed, 28 Mar 2018 09:12:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FCB5298AB; Wed, 28 Mar 2018 09:12:37 +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=-5.4 required=2.0 tests=BAYES_00, DATE_IN_PAST_24_48, 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 AD4B429846 for ; Wed, 28 Mar 2018 09:12:36 +0000 (UTC) Received: from localhost ([::1]:38159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f178F-0002Kr-To for patchwork-qemu-devel@patchwork.kernel.org; Wed, 28 Mar 2018 05:12:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f176a-00014O-PO for qemu-devel@nongnu.org; Wed, 28 Mar 2018 05:10:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f176Y-0005BK-3T for qemu-devel@nongnu.org; Wed, 28 Mar 2018 05:10:52 -0400 Received: from mail-pl0-x231.google.com ([2607:f8b0:400e:c01::231]:45356) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f176X-0005Ay-Rq for qemu-devel@nongnu.org; Wed, 28 Mar 2018 05:10:50 -0400 Received: by mail-pl0-x231.google.com with SMTP id n15-v6so1193068plp.12 for ; Wed, 28 Mar 2018 02:10:49 -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=XUDzYoUh4OyYELgkFPvZrzIEe7Aa5QqBLX/5X+9TspI=; b=kVsqDVgNp/ZVXjqvo9zLRfQj+/8H3qHxD5dWPVT8ny+u/gaKXJZ1KJ52FzzlpDXU/s An2L/6hf2/j/j5z1k+F93aU+f1vtr12EIZf9ZT1ZULDLjjFKgGVQd2S9ZI4E4qNluYSG yyiVI581LLD608gJFH02xGMBEOS/TGyadASfNsrPeMbyBb13dgHOQEvVqsl/NBbHBUuf 3VhyGfVJl/SIxDTmp8UW7SNXXrzxTHhKdCya44n1MsmTLeZ3sduBRGLBWfEydbV3b4I3 W+eHe4lSuOWDgc5pJ2temUGl3kShM43WS/GLiuH8hR4rU+p6PpyjZtWqpvT9zC/lOURf WEsQ== 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=XUDzYoUh4OyYELgkFPvZrzIEe7Aa5QqBLX/5X+9TspI=; b=M+5NGuzoasusqGELIxRKKOnDPDtUk8WFxQ9gnWenW08ZVqScQsYYlJ/X16a6wjECho WazL80dEF27YifisThXYslVtCgRjeIqks+3bbrdGSrlJ+11ccfd9Uc11771+tlMCPyny CuOstKxiRD+LQH7d75DuiIQ1IShM82lQLqwJAmXjXWh/lRVuG3HPwmBy2+lkrRE8Ii+W pzFZIyQinQUdlPwFJmDUGTb6oo6UPXMgO9BXtyHGCFHzfojeYj6/Ae7iuywuks3O6/uy 54m+OXsENLC5bmIq4/SI+munKHm1NN3hzZsC0WRf3hcgGIL7xSsVuhrWhQ4gZu4xHnco Eoyw== X-Gm-Message-State: AElRT7FsqBWAc1ipCs9WlBig2pWrgHAvWHr2qTQZ1yQVZJdwK7id3O30 jn69F0IAhQIETMMUnLWZ+c9hpw== X-Google-Smtp-Source: AIpwx4/P/Cm0KdUo3LVP4hyh4BY4Jy8coxhBbKrJ7INS9Gb5GebDAZXQOTKhR10P28/Pw+oa/QvbDg== X-Received: by 2002:a17:902:b602:: with SMTP id b2-v6mr2979378pls.11.1522228249059; Wed, 28 Mar 2018 02:10:49 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.38]) by smtp.gmail.com with ESMTPSA id q9sm5590648pgs.89.2018.03.28.02.10.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Mar 2018 02:10:48 -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: Tue, 27 Mar 2018 17:10:41 +0800 Message-Id: <20180327091043.30220-9-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> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::231 Subject: [Qemu-devel] [PATCH v2 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 ce3ef4382d..771763985d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1040,15 +1040,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) { @@ -1196,40 +1189,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; @@ -1471,6 +1447,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 * @@ -1492,12 +1486,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); }