From patchwork Mon Sep 3 09:26:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10585629 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 1151B5A4 for ; Mon, 3 Sep 2018 09:27:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AF94294F8 for ; Mon, 3 Sep 2018 09:27:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2DA52956E; Mon, 3 Sep 2018 09:27:02 +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 8BC11294F8 for ; Mon, 3 Sep 2018 09:27:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727062AbeICNqS (ORCPT ); Mon, 3 Sep 2018 09:46:18 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44531 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726869AbeICNqR (ORCPT ); Mon, 3 Sep 2018 09:46:17 -0400 Received: by mail-pg1-f196.google.com with SMTP id r1-v6so8340977pgp.11 for ; Mon, 03 Sep 2018 02:27:00 -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=E4iFB29osfxzkuTgHYrtMGQRw1k89sq8DvMO5tpJsPg=; b=eLBi4gZghBvQFff6eAktAHL9PJnxtCf12EUPm55jltnERw+J5SRXnpTxZ2yYgfW4Rh eyXGempVvbZXm17gLBYdH0ABC9qzWSsEGE6wzpvfUoElfpA2KFPESMhdy/7EHEQ3biGr oFkZciqYsIQ5+LyV0RcvyaRfeCZeX1ZORQ5duLiTMdjU0WN5ParXfseIoKGishv9ZJBt 7OHDiraEYhc/AiQ/CtsqrqKKMavDQqE4Q8t0zdAVp5Bz1mvVr627pDrfyTzvHoaq40iB OhrntoRGFC2tZPgws/Xg4dfLj0VTQSGV7scJZASbnzEMq/ZQlNqWsuvZGbog5yaIhxV4 20xQ== 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=E4iFB29osfxzkuTgHYrtMGQRw1k89sq8DvMO5tpJsPg=; b=OHJl/YDdKp9RZNNjE1XF3bQ2J+4X5PbPByNQW78e+Z8IilHv4N8QscjSQvMW3v3tEO 9s7aklC7fCucpw4CXIr+cZXbgnXl+4VGonRaeXTHzIriPcAU/JBR3WGnizoU4ywDpaNw /4fgW0TY0Rx4bZu1b2v2YZsHpk9mOIWnR44ejlLTS2HD5v6I1VY0pitkT+5cslgstaGf HtLm75NbFSLr1JkTrCRN5wIBDm+uuy+GpY3/sgpa1sCTVZaptDUWCiH6ypw5OxW5W4MG gR5TgaHma0pDziqIkK6DgL8P7KAbWe9pTOjmPJo62M7LsmYxxbremmGfpG8WVfVdcb+s 5geg== X-Gm-Message-State: APzg51BIboWTfZqHuNTgO1KKxmIPsm4m9GBeuCYLDRDfctrA/nk3l9Pc cbfjeULcVcIT+dBMZcEhD8g= X-Google-Smtp-Source: ANB0VdaHG69sRDefiHAaTDacoUQyG4GBHlWH2QwEpmH3xwzr5f1OxZluHwbPvwv+8xECQxGBKd6uIw== X-Received: by 2002:a63:6ce:: with SMTP id 197-v6mr25018713pgg.338.1535966820521; Mon, 03 Sep 2018 02:27:00 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.40]) by smtp.gmail.com with ESMTPSA id 3-v6sm33543102pfq.10.2018.09.03.02.26.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 02:27:00 -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, quintela@redhat.com, Xiao Guangrong Subject: [PATCH v5 2/4] migration: fix calculating xbzrle_counters.cache_miss_rate Date: Mon, 3 Sep 2018 17:26:42 +0800 Message-Id: <20180903092644.25812-3-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180903092644.25812-1-xiaoguangrong@tencent.com> References: <20180903092644.25812-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 Reviewed-by: Peter Xu Signed-off-by: Xiao Guangrong Reviewed-by: Juan Quintela --- migration/ram.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 2ad07b5e15..25af797c0a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -301,10 +301,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; /* last dirty_sync_count we have seen */ @@ -1594,19 +1594,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; } } @@ -1664,7 +1664,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; @@ -3209,7 +3209,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.