From patchwork Tue Aug 21 08:10:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10571201 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 1134C1390 for ; Tue, 21 Aug 2018 08:15:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0322A27F91 for ; Tue, 21 Aug 2018 08:15:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB29129B47; Tue, 21 Aug 2018 08:15:39 +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 9298127F91 for ; Tue, 21 Aug 2018 08:15:39 +0000 (UTC) Received: from localhost ([::1]:51488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fs1pC-00005J-IZ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 21 Aug 2018 04:15:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fs1kg-0003sD-IG for qemu-devel@nongnu.org; Tue, 21 Aug 2018 04:10:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fs1kd-0004WH-Hv for qemu-devel@nongnu.org; Tue, 21 Aug 2018 04:10:58 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:35814) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fs1kd-0004UC-1I for qemu-devel@nongnu.org; Tue, 21 Aug 2018 04:10:55 -0400 Received: by mail-pf1-x42f.google.com with SMTP id p12-v6so8133679pfh.2 for ; Tue, 21 Aug 2018 01:10:54 -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=AvZxw0tuZk/hGJGvBJF4lHrIGTeeG/JUIgTOcxIgscYLK02WRZsc54vUnM5ItpYrhg yg0miwrpM8dd96UXRjddwM/zcXqxg67T6wV6xSvQBdi58F4nHGJyMUPu9Q2pV9nF59Eh 6OfIDmtUAM2TdBt78UyKwAX3TVHg4QcF+m6KcIjrrHCvREk7vm9AJhe+XrrL9SdWodIF 4X8VUMOV5GwOkU/9DgvqBp0Zy3kSQMDSuuXr+fcyBYobgcggUgDQTl+N82OGkcazd4Tx gQEcihhdIihS04T6seeK/OO+3Nfr4LE+m7pvftHHdo0ek2Ja739mo50QFxZWNC6faJpG D4KQ== 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=gSM0xbJURI51n8OyDm7L37JhBRcITt+ZIcQGy5S5tvbFkT26Ib2iYCJvZwQcozwxY/ FEf7CDrWWaQ0WVvon5dbqGRQ7tLijyehAexPfMZX9Lsc5niZkl+q9FlE76v60UJLMp/l 6iUz+3OY1W0eka6LYi1W5S4Otxc9SnTIGl0zDrmjY4cZdWIrjxSihjVFtyVHWdbn+OLX jzdkOV6lo4t7iKO7CVubHl8oVVpIHWGmfkarqisa3kXaIwEOMCc2kXgglGoJoCNeHdMU AWtUB4YcGvgEO4K2MA0G/aWbKZnWAFbVQO4cY8y9PLQoN497/iDGJOc31Aq87QsIVfNH N1rQ== X-Gm-Message-State: AOUpUlEUofeHuRCJ8iZSPTn9NMRVZUJMxqXgP9dskddC3WcgEyn9SgZ4 YwkxFWfVRpG6Hj7oDgnM02Y= X-Google-Smtp-Source: AA+uWPwmx3lfBQJvjuSAyB9JbnOIs2F0XNt2DA1++Q5Cf5BU14dMQ7uH3jPYzx5wzai1Ai1mEgjGGw== X-Received: by 2002:a65:5803:: with SMTP id g3-v6mr46790443pgr.117.1534839053709; Tue, 21 Aug 2018 01:10:53 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.40]) by smtp.gmail.com with ESMTPSA id r64-v6sm20644023pfk.157.2018.08.21.01.10.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Aug 2018 01:10:53 -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, 21 Aug 2018 16:10:22 +0800 Message-Id: <20180821081029.26121-4-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180821081029.26121-1-xiaoguangrong@tencent.com> References: <20180821081029.26121-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::42f Subject: [Qemu-devel] [PATCH v4 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 Reviewed-by: Juan Quintela --- 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)