From patchwork Thu Jul 19 12:15:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 946238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jJbPGKmP"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41WY443c3hz9rxs for ; Thu, 19 Jul 2018 22:19:48 +1000 (AEST) Received: from localhost ([::1]:42081 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg7uM-0004Oy-4b for incoming@patchwork.ozlabs.org; Thu, 19 Jul 2018 08:19:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg7qh-0002Bx-Kq for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:16:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fg7qd-0005Rb-JY for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:15:59 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:43532) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fg7qd-0005R7-D2 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:15:55 -0400 Received: by mail-pg1-x541.google.com with SMTP id v13-v6so3582142pgr.10 for ; Thu, 19 Jul 2018 05:15:55 -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=wEcNUFI0wdozoTLrgZXruOP9i+eqNPRyhLre85OGP5w=; b=jJbPGKmPQKaTXPoqM2PKwAi4jRndVDlwoEZ1obj03HpB6rH7YwSPU+cZlZnE2QtEuI Gq7bKhTtk8c3YPTKqnsH2my3re4wVe4ARo14nuueI1vScwGXOxv30U/q0jom/ggmxQ3N kR65XNcLC8otFmQnY5osLZZSjYl2iUQZV+deXK9erDTh/VDk5P3WBluAIaCGkHCxY+Ew jrn1irBs/zSd76G38PbdgW5KEw8gwWse5DWGvQh7wJzIe+MBaQXuT2I14XvigLkpjKc+ 1pF+gdjC6qiMkg4BOOczaI7z9oUcSdmhraYXyj+LMdXnE7dKnSBqv/Map8YgAsRsC7qN Yw4Q== 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=wEcNUFI0wdozoTLrgZXruOP9i+eqNPRyhLre85OGP5w=; b=bRnr/wcFA7lh0HtE67lCaOFAiysCiW61aG3XEbaQo9T3a1kgbMG6422aVMe/4Xd2FP tzXMua8OUYEgtaEEtijmS+s/rnGUij5ZnIPBOtptcerHr9PEePd3kgbsE1wG16FTg4vu A4A+GlIYpdA+Uy9eiXg5dhPnUmlx4BVp82nfGpzPqxw1+KIUPiLtPn4jMImI1mqgxXsc 7raVxvXBKPfV03XOEwuVsXjsHrGTwNulTeGYDhsJfRoEHMKzuysZmszwzZ4iYlPoKD6n +cRvZXd8Xwt3qEaF8d0Eko9CJXG4xbvs4ruDcintK5LFEqhUBs7/qVcXhkfNme51lFGz bjIg== X-Gm-Message-State: AOUpUlHhekZWqWwFozm8Oe0TL2mflEj/1qu+M7klLLAEkrWbLQtstay/ WS3ykBFvlMggIJJcHWSsEz+56v3y X-Google-Smtp-Source: AAOMgpd5ovkSHqsxe043T0iz+OmS2kj92HWQLTksnZxJs5DnKiizTH8Vm7Iqm1sTpgn3fO5PfTYCZQ== X-Received: by 2002:a63:bf43:: with SMTP id i3-v6mr9871707pgo.342.1532002554658; Thu, 19 Jul 2018 05:15:54 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id h190-v6sm21270456pge.85.2018.07.19.05.15.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 05:15:54 -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: Thu, 19 Jul 2018 20:15:16 +0800 Message-Id: <20180719121520.30026-5-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180719121520.30026-1-xiaoguangrong@tencent.com> References: <20180719121520.30026-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 v2 4/8] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Xiao Guangrong It will be used by the compression threads Signed-off-by: Xiao Guangrong Reviewed-by: Peter Xu --- migration/ram.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index e68b0e6dec..ce6e69b649 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1696,27 +1696,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)