From patchwork Tue Aug 7 09:12:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10558443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 55A8F14E5 for ; Tue, 7 Aug 2018 09:17:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 459C626538 for ; Tue, 7 Aug 2018 09:17:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38ED129690; Tue, 7 Aug 2018 09:17:03 +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.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,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 DE93B26538 for ; Tue, 7 Aug 2018 09:17:02 +0000 (UTC) Received: from localhost ([::1]:38033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmy6w-0006zx-2j for patchwork-qemu-devel@patchwork.kernel.org; Tue, 07 Aug 2018 05:17:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmy2t-0003CO-8Z for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:12:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmy2p-00056Q-WE for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:12:51 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:37341) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmy2p-00056G-PZ for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:12:47 -0400 Received: by mail-pg1-x541.google.com with SMTP id n7-v6so7556650pgq.4 for ; Tue, 07 Aug 2018 02:12:47 -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=NsmhccRCp5gWMJ0cmbdhkw17Dbew1msB4Oy/3ymK/ko=; b=VdAadeq4a+hsKW8NyZ0bPVrTumkfiG/Kr3mchOmTJX21881YoJcQix1DtazH75t+pp vcPZoAeOBXh38F332znUMh4k5ACldc4d/FNPPljiCD3t+x0Eu4qfY6fLvUXMzoJGnUZI QE8n0UmaMyJbMtHUpS/ho9mcn+6tssw4lbzlQmsFTeN/S0Nmev8Tk5LM+6aCL7KsgUJB Bk9zV+q8PSy/BsnVmxG/Pa8iwhJm6GU3UsqnUXPinjZ3VKU/hvX1M4KtDY59I5/MPd2c eGaDIAOm91gir3dhXIQUBo9Xdy+B1RxnXTbXxaZnO/n62ZSrlFUBpsk767vM/jsVLJ8r mbyQ== 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=NsmhccRCp5gWMJ0cmbdhkw17Dbew1msB4Oy/3ymK/ko=; b=Lfp2/IKCYa1yscFb49k9dS2HG2TtvzPLnkLMKZfFGB8Ym43WeYwOP9VpsmeG4EyYrj 9JhBYb3Ni4OseRONuSPYd5GRtV/iljKzXYsItu2bnEoIyxEJm8PrwyBD+/WSAttUmQJV yxECIZYDSvvEduFq9Jsbox0ci2/leferi6AE8LqsZruC/q/rdUpo21Lxfq3JvnUr42gD Ow9VutYIb85p8cjWBtkHRlJN8oHK7xDlGEZvb2FSKlf8btPAH9qDe0oGTPb+yxyZtH0g kPFhR0JKun1fKofDN/CpabbwYfZdMIXEMijmFp3Ahna9RCUi9syh4+tdWE+sq44cRJWS ywlA== X-Gm-Message-State: AOUpUlGwjiExNlr+9K2XGV9zzvZVhGYXzNkzPSAw97uMgPh5ockHNmks JuhDrerJUpXAlz0G5JbgsZw= X-Google-Smtp-Source: AAOMgpcrn/iPQWL41RfvsVBEryGl4xwf+a+P9u77MDSjGneBykAgRUdJYWvHtgcAWXEDI5EAegXXNQ== X-Received: by 2002:a65:6455:: with SMTP id s21-v6mr17352098pgv.394.1533633166956; Tue, 07 Aug 2018 02:12:46 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id z4-v6sm2159645pfl.11.2018.08.07.02.12.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Aug 2018 02:12:46 -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, 7 Aug 2018 17:12:02 +0800 Message-Id: <20180807091209.13531-4-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180807091209.13531-1-xiaoguangrong@tencent.com> References: <20180807091209.13531-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH v3 03/10] migration: introduce save_zero_page_to_file 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 It will be used by the compression threads Reviewed-by: Peter Xu Signed-off-by: Xiao Guangrong --- migration/ram.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index d631b9a6fe..49ace30614 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1667,27 +1667,47 @@ static void migration_bitmap_sync(RAMState *rs) /** * save_zero_page: send the zero page to the stream * - * Returns the number of pages written. + * Returns the size of data written to the file, 0 means the page is not + * a zero page * * @rs: current RAM state + * @file: the file where the data is saved * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) +static int save_zero_page_to_file(RAMState *rs, QEMUFile *file, + RAMBlock *block, ram_addr_t offset) { uint8_t *p = block->host + offset; - int pages = -1; + int len = 0; if (is_zero_range(p, TARGET_PAGE_SIZE)) { - ram_counters.duplicate++; - ram_counters.transferred += - save_page_header(rs, rs->f, block, offset | RAM_SAVE_FLAG_ZERO); - qemu_put_byte(rs->f, 0); - ram_counters.transferred += 1; - pages = 1; + len += save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_ZERO); + qemu_put_byte(file, 0); + len += 1; } + return len; +} - return pages; +/** + * save_zero_page: send the zero page to the stream + * + * Returns the number of pages written. + * + * @rs: current RAM state + * @block: block that contains the page we want to send + * @offset: offset inside the block for the page + */ +static int save_zero_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) +{ + int len = save_zero_page_to_file(rs, rs->f, block, offset); + + if (len) { + ram_counters.duplicate++; + ram_counters.transferred += len; + return 1; + } + return -1; } static void ram_release_pages(const char *rbname, uint64_t offset, int pages)