From nobody Sun Feb 8 14:35:18 2026 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 1537982181756859.86113148054; Wed, 26 Sep 2018 10:16:21 -0700 (PDT) Received: from localhost ([::1]:59877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5DQC-0002eJ-En for importer@patchew.org; Wed, 26 Sep 2018 13:16:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5DMq-0000Qy-JW for qemu-devel@nongnu.org; Wed, 26 Sep 2018 13:12:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5DMp-0006gB-HW for qemu-devel@nongnu.org; Wed, 26 Sep 2018 13:12:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5DMp-0006fC-8r for qemu-devel@nongnu.org; Wed, 26 Sep 2018 13:12:51 -0400 Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76949308212A; Wed, 26 Sep 2018 17:12:50 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD6CDDB561; Wed, 26 Sep 2018 17:12:48 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, xiaoguangrong@tencent.com, joserz@linux.ibm.com, wei@redhat.com, thuth@redhat.com, marcandre.lureau@redhat.com, fli@suse.com Date: Wed, 26 Sep 2018 18:12:22 +0100 Message-Id: <20180926171236.45203-3-dgilbert@redhat.com> In-Reply-To: <20180926171236.45203-1-dgilbert@redhat.com> References: <20180926171236.45203-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 26 Sep 2018 17:12:50 +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/16] 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: quintela@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 Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index f6fd8e5e09..0423ef0f08 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