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: 10534245 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 18F2E600F4 for ; Thu, 19 Jul 2018 12:15:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07D0F293A6 for ; Thu, 19 Jul 2018 12:15:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0425294BB; Thu, 19 Jul 2018 12:15:56 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91710293A6 for ; Thu, 19 Jul 2018 12:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731494AbeGSM6s (ORCPT ); Thu, 19 Jul 2018 08:58:48 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36151 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731154AbeGSM6r (ORCPT ); Thu, 19 Jul 2018 08:58:47 -0400 Received: by mail-pg1-f195.google.com with SMTP id s7-v6so152135pgv.3 for ; Thu, 19 Jul 2018 05:15: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=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=Y8lns7WzEbxIdF27hG7CVTT2a3OEFNFNqQ/M8XoxOu6KFFYvVH2dNCdBu4HFeBjt5H MlT392t7iQ5Q9GxYGCdJKyXxIHMRvCUZqUk40fmruKaobX3+gaLYZkIpOPUC6U9mk546 W7shW9uCDFYB7/Ho4taSkHXZzIetWTLNzQRS5YoX7Zh2yycdNdOrJWgvTb4rXx0PKwn9 bQ6641dyammAr3+2WfHlJTFAw2etcsi/sP7C/TRFskmEW232ZL5mykeH4ErYwiH+8zm7 jnCESiixAKDqG7X6euZ4HccK4YANBiHyDN8cpM4S/IDgPDKy6k4+ICzL9ZycY1u9ppEv QrSA== X-Gm-Message-State: AOUpUlHP0AZrYkHLRLzXTexbbp+z8B6wnANbAsDS18Tw+xDx1PADMAnR wFWajXpLC0VbhIUUCdlZrBU= 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 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, dgilbert@redhat.com, peterx@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn, eblake@redhat.com, Xiao Guangrong Subject: [PATCH v2 4/8] migration: introduce save_zero_page_to_file 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)