From patchwork Tue Aug 21 08:10:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10571187 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 CFCCE1390 for ; Tue, 21 Aug 2018 08:11:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3A0B29D5F for ; Tue, 21 Aug 2018 08:11:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C165029E21; Tue, 21 Aug 2018 08:11:14 +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 3B48129E03 for ; Tue, 21 Aug 2018 08:11:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726808AbeHULaU (ORCPT ); Tue, 21 Aug 2018 07:30:20 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:41648 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbeHULaU (ORCPT ); Tue, 21 Aug 2018 07:30:20 -0400 Received: by mail-pl0-f68.google.com with SMTP id p4-v6so4877959pll.8 for ; Tue, 21 Aug 2018 01:11:12 -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=KhbbMcS7jFEoTFCG7r76No1VG+edyYKzHscFtQ9vfmI=; b=PJEx/FzGvSX7/wPkHSirBaz9qv3UUVJRVa433c7l/MCm6n8SdEAIufC1zetkQg+Qtu rozDjPia6xkDmlyxnIL7RmmVUaKkphtFSpsedes1Y9Wd6JLtEDZcsLNeXvBGbiHmRP7a us+pTMEUunh4DKHmRVEbKN1Qk3GcOcVa63ZVuRr3t7by3UGIrzI3OFB10HFHJv77jJax fXIBbOKk/3w5pwbWXcpm9khrt3TsCGzRaCAcNwzbxaXjyoypV7mqK06wSjrCrYQZIwPr 9KoAXYDPDhE9h/GEu8erlg5Hl2Y5NcX7spH41HHcSg+6UoBISTnsY03wloafdSBT2e2J 1s2A== 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=KhbbMcS7jFEoTFCG7r76No1VG+edyYKzHscFtQ9vfmI=; b=t0a0topamoa/RQhPvbnA3R9ZK4nSAtCv49QoI0MgzlbI+h1ggCh6WuDKrn4kQV0bcC 3csEBaAQ8Q9Mjjd05XeAEwNJ2lVJSlGAgNaFJzuoVOIxOvzSXVil84R0T3UzlgzzUrBe ekiEt+62PxjA0zk1qAwKvQheTH2qH6GuJeF5uQ7nZLavsFMozi4DSKV6cGmMUEviArUE C1eVu9CUUPV0oxx0empzqd+hwzxcJRKq/eLhHFvmFlAhh5CaBhXDHEJ1o97m02Oq5fsF 6a7DcVO+oBXX79QkMEP8BWdpcpevZtPEuYhBHqzvPt64K5xAPOvUObAk1aHqDP8pKwkF 9VRw== X-Gm-Message-State: AOUpUlHXlOl+qEeuQP0beYb047gjNOX7pXSg/MQHVr5fbPwwbagqbYR7 rpHKrCkEW5iNrjdQ3HAarg8rrGCx X-Google-Smtp-Source: AA+uWPxjAiPHKdfReVI5Qkqfzj2888zaRG6Hz1f6pgSn7irgQRhH0qK1lpGxDlEViXT5gFGoEcQqzQ== X-Received: by 2002:a17:902:33c2:: with SMTP id b60-v6mr48775225plc.11.1534839072181; Tue, 21 Aug 2018 01:11:12 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.40]) by smtp.gmail.com with ESMTPSA id r64-v6sm20644023pfk.157.2018.08.21.01.11.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Aug 2018 01:11:11 -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 v4 08/10] migration: fix calculating xbzrle_counters.cache_miss_rate Date: Tue, 21 Aug 2018 16:10:27 +0800 Message-Id: <20180821081029.26121-9-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> 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 target guest page numbers After that, rename 'iterations' to 'target_page_count' 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 1d54285501..17c3eed445 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 target pages at the beginning of period */ + uint64_t target_page_count_prev; + /* total handled target pages since start */ + uint64_t target_page_count; /* number of dirty bits in the bitmap */ uint64_t migration_dirty_pages; /* protects modification of the bitmap */ @@ -1585,19 +1585,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->target_page_count - rs->target_page_count_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; } } @@ -1704,7 +1704,7 @@ static void migration_bitmap_sync(RAMState *rs) migration_update_rates(rs, end_time); - rs->iterations_prev = rs->iterations; + rs->target_page_count_prev = rs->target_page_count; /* reset period counters */ rs->time_last_bitmap_sync = end_time; @@ -3197,7 +3197,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) done = 1; break; } - rs->iterations++; + rs->target_page_count += 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.