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: 10558417 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 6396B13B4 for ; Tue, 7 Aug 2018 09:12:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 146A126223 for ; Tue, 7 Aug 2018 09:12:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0785829C09; Tue, 7 Aug 2018 09:12:49 +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 99E4529C06 for ; Tue, 7 Aug 2018 09:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732611AbeHGL0K (ORCPT ); Tue, 7 Aug 2018 07:26:10 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:33691 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730229AbeHGL0J (ORCPT ); Tue, 7 Aug 2018 07:26:09 -0400 Received: by mail-pg1-f196.google.com with SMTP id r5-v6so7565377pgv.0 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=rV0rrZUMheU8dqcqot4qBPYso0PAfy4uZRWMU7Pme3sQANMh5uFcFO0fDAFy0nRs9Q NDSm3QGVYc8lgZVNHa3+D7rt/CkqBlrKAqLCI7BTXF0hVb4vS/VYLFrrVNerpvfbT5nu NPzZ/hkN7EeAmpUlZbKDIRhKGn/m682cwcT2k3Qp0FP9PWH6nYcR1p4BkXroUcywwjPg ocyclW7YTjcMUmDrquZj2nYwJUUyLK89BxUgaSs3brO63uC5ZbcVkXiorO7Fb6y2E8ay MO/W+nPorAQPmxCxB/RBZI06WvCWQJaVNJ0zVmBavRqcEapvsIhK+2SJ6SAu6+tHVZin vqUg== X-Gm-Message-State: AOUpUlHUn9f2IL+9JiW31WmWs8GRV9lu9mJ245VwdFgWGZKd6YXWd+0q PjqQfKvTZ5HESowEIJi2OaI= 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 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 v3 03/10] migration: introduce save_zero_page_to_file 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> 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 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)