From nobody Wed Nov 5 20:15:30 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536844565079545.2096622028874; Thu, 13 Sep 2018 06:16:05 -0700 (PDT) Received: from localhost ([::1]:42414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0RTX-000367-P3 for importer@patchew.org; Thu, 13 Sep 2018 09:16:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0R8G-0003D7-Qo for qemu-devel@nongnu.org; Thu, 13 Sep 2018 08:54:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g0R8F-0002w1-FY for qemu-devel@nongnu.org; Thu, 13 Sep 2018 08:54:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44038) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g0R8F-0002u2-7U for qemu-devel@nongnu.org; Thu, 13 Sep 2018 08:54:03 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7EE8986668; Thu, 13 Sep 2018 12:54:02 +0000 (UTC) Received: from secure.mitica (ovpn-116-187.ams2.redhat.com [10.36.116.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7016C5C1B4; Thu, 13 Sep 2018 12:54:00 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 13 Sep 2018 14:53:33 +0200 Message-Id: <20180913125343.10912-3-quintela@redhat.com> In-Reply-To: <20180913125343.10912-1-quintela@redhat.com> References: <20180913125343.10912-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 13 Sep 2018 12:54:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/12] migration: fix calculating xbzrle_counters.cache_miss_rate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, Xiao Guangrong , dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3D512 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=3D51200% (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 Reviewed-by: Juan Quintela Signed-off-by: Xiao Guangrong Message-Id: <20180903092644.25812-3-xiaoguangrong@tencent.com> Signed-off-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 79c89425a3..5a54836c28 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; /* protects modification of the bitmap */ @@ -1592,19 +1592,19 @@ uint64_t ram_pagesize_summary(void) =20 static void migration_update_rates(RAMState *rs, int64_t end_time) { - uint64_t iter_count =3D rs->iterations - rs->iterations_prev; + uint64_t page_count =3D rs->target_page_count - rs->target_page_count_= prev; =20 /* calculate period counters */ ram_counters.dirty_pages_rate =3D rs->num_dirty_pages_period * 1000 / (end_time - rs->time_last_bitmap_sync); =20 - if (!iter_count) { + if (!page_count) { return; } =20 if (migrate_use_xbzrle()) { xbzrle_counters.cache_miss_rate =3D (double)(xbzrle_counters.cache= _miss - - rs->xbzrle_cache_miss_prev) / iter_count; + rs->xbzrle_cache_miss_prev) / page_count; rs->xbzrle_cache_miss_prev =3D xbzrle_counters.cache_miss; } } @@ -1662,7 +1662,7 @@ static void migration_bitmap_sync(RAMState *rs) =20 migration_update_rates(rs, end_time); =20 - rs->iterations_prev =3D rs->iterations; + rs->target_page_count_prev =3D rs->target_page_count; =20 /* reset period counters */ rs->time_last_bitmap_sync =3D end_time; @@ -3196,7 +3196,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) done =3D 1; break; } - rs->iterations++; + rs->target_page_count +=3D pages; =20 /* we want to check in the 1st loop, just in case it was the 1st t= ime and we had to sync the dirty bitmap. --=20 2.17.1