From patchwork Tue Aug 7 09:12:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10558429 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 1AC2913B4 for ; Tue, 7 Aug 2018 09:13:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 094F026CFF for ; Tue, 7 Aug 2018 09:13:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1CAD28068; Tue, 7 Aug 2018 09:13:12 +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 769E126CFF for ; Tue, 7 Aug 2018 09:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387493AbeHGL0e (ORCPT ); Tue, 7 Aug 2018 07:26:34 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:36615 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732952AbeHGL0d (ORCPT ); Tue, 7 Aug 2018 07:26:33 -0400 Received: by mail-pl0-f65.google.com with SMTP id e11-v6so6867622plb.3 for ; Tue, 07 Aug 2018 02:13:10 -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=64IrWQDQ1LSSbayQ3BFrpDYaoZU6o3Q5eD775BnwU4c=; b=QFp1QJRD8h/DSJUSOkIpb7xW3ZzD8Pyt3KO1e0BLE3/bVgzRGLOE14Xeiz6VzUL9Ne z1Htsw2w9kQnImNMreXRy/+xbKbLLzoYin0yMllpHsfXqq/rGXpcOXkmfhJh1s869WS4 grayqI/xWSKmZYRPey9+M7SD95TD+yb02z/JFvkdQ90svPmCfjJ6kZ4CPMkzl+71JC5u lMUCe3XOTcxSHI6H8ydeMTYqZcwzBjpTXfIGY4M7JkfXx0ODV50lFE5f7Y0BHu+1AFcb QY98/We2acJ26B/PxMJcMHUJWcXlionQXkKCwksmYhJeT7yV9XjlLeFvHY4DXNekyxLS bE7Q== 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=64IrWQDQ1LSSbayQ3BFrpDYaoZU6o3Q5eD775BnwU4c=; b=dAS4u+ku0XOfBvAwhyGi4xt1/wouf9gCfGuWFsqe6hpRYvsIji5rXzdeXGnPGIqqXI IaW58JAsyii/lwOHBSZNJZZjm/Cu7eQGVgV4ve7MUAHR9hdDU8cIcfI8opmfS5YQoMKF NaONnw8iaYorV5Fue3WBAqNdPp38AaO6PowqhWe4ljqOjqF4DmUlyDdHpe+5GSeJn6St q4p78cywjHIZwV5PQ0I2l1lDOVT5/l2mDmRt2eyh2okZpE2KSUZG0ytABSFw8axu6MU+ xx/sPi+8IHSLHggjV3aZ0yQ1kW5CQkIKaiS+YDDTvsMgW9kFQxUvzUr1rVSNBNowcvPg N3vg== X-Gm-Message-State: AOUpUlHYIoGCWMkL/MJhdUGj7rgKxK9CUrHrtBsBZo6ZHjIRnvQkbC6A s7bpFN30+siQQJXSIcI5l/c= X-Google-Smtp-Source: AAOMgpddQ3dYn2GuVwXOh8UAT2gc47dy87w/lhh6lToWDP2LPYL9FZcwWLv3r+xxOz7h5N61pOvU9Q== X-Received: by 2002:a17:902:6b46:: with SMTP id g6-v6mr17488145plt.251.1533633190426; Tue, 07 Aug 2018 02:13:10 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id z4-v6sm2159645pfl.11.2018.08.07.02.13.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Aug 2018 02:13:09 -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 09/10] migration: fix calculating xbzrle_counters.cache_miss_rate Date: Tue, 7 Aug 2018 17:12:08 +0800 Message-Id: <20180807091209.13531-10-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 As Peter pointed out: | - xbzrle_counters.cache_miss is done in save_xbzrle_page(), so it's | per-guest-page granularity | | - RAMState.iterations is done for each ram_find_and_save_block(), so | it's per-host-page granularity | | An example is that when we migrate a 2M huge page in the guest, we | will only increase the RAMState.iterations by 1 (since | ram_find_and_save_block() will be called once), but we might increase | xbzrle_counters.cache_miss for 2M/4K=512 times (we'll call | save_xbzrle_page() that many times) if all the pages got cache miss. | Then IMHO the cache miss rate will be 512/1=51200% (while it should | actually be just 100% cache miss). And he also suggested as xbzrle_counters.cache_miss_rate is the only user of rs->iterations we can adapt it to count guest page numbers After that, rename 'iterations' to 'handle_pages' to better reflect its meaning Suggested-by: Peter Xu Signed-off-by: Xiao Guangrong Reviewed-by: Peter Xu --- migration/ram.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 09be01dca2..bd7c18d1f9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -300,10 +300,10 @@ struct RAMState { uint64_t num_dirty_pages_period; /* xbzrle misses since the beginning of the period */ uint64_t xbzrle_cache_miss_prev; - /* number of iterations at the beginning of period */ - uint64_t iterations_prev; - /* Iterations since start */ - uint64_t iterations; + /* total handled pages at the beginning of period */ + uint64_t handle_pages_prev; + /* total handled pages since start */ + uint64_t handle_pages; /* number of dirty bits in the bitmap */ uint64_t migration_dirty_pages; /* last dirty_sync_count we have seen */ @@ -1587,19 +1587,19 @@ uint64_t ram_pagesize_summary(void) static void migration_update_rates(RAMState *rs, int64_t end_time) { - uint64_t iter_count = rs->iterations - rs->iterations_prev; + uint64_t page_count = rs->handle_pages - rs->handle_pages_prev; /* calculate period counters */ ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000 / (end_time - rs->time_last_bitmap_sync); - if (!iter_count) { + if (!page_count) { return; } if (migrate_use_xbzrle()) { xbzrle_counters.cache_miss_rate = (double)(xbzrle_counters.cache_miss - - rs->xbzrle_cache_miss_prev) / iter_count; + rs->xbzrle_cache_miss_prev) / page_count; rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss; } } @@ -1657,7 +1657,7 @@ static void migration_bitmap_sync(RAMState *rs) migration_update_rates(rs, end_time); - rs->iterations_prev = rs->iterations; + rs->handle_pages_prev = rs->handle_pages; /* reset period counters */ rs->time_last_bitmap_sync = end_time; @@ -3209,7 +3209,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) break; } - rs->iterations++; + rs->handle_pages += pages; /* we want to check in the 1st loop, just in case it was the 1st time and we had to sync the dirty bitmap.