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: 954422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QFp1QJRD"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41l88r6GH9z9rxx for ; Tue, 7 Aug 2018 19:19:08 +1000 (AEST) Received: from localhost ([::1]:38045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmy8w-0007uM-EM for incoming@patchwork.ozlabs.org; Tue, 07 Aug 2018 05:19:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmy3E-0003Rf-Dn for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:13:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmy3D-0005Cl-Cs for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:13:12 -0400 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:42158) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmy3D-0005Cb-62 for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:13:11 -0400 Received: by mail-pl0-x244.google.com with SMTP id g6-v6so3295886plq.9 for ; Tue, 07 Aug 2018 02:13:11 -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=PkOiIVD9nfz5i/R9UnsQke36exFY4Ro3r7dlQ2yZCDp0+W/k3RALViBsyS1uaDOilJ Qs5tLvTfKq2QslzHN8DUfJusui4zSOOEtcLLy/z3uPJtHaHiJ6cT+6zFxWDM5OM+f0Yw R+KuTtJVz3ArWhnUgxsN0HaO04P4eqcR4elgV7/U72eHg+DG2Q82rWTfQLinZ6lQcPoX BsvI86WgRoilgx9qE0lLpH6vYHRTiETfETppWNTHCaFo+3JPQ5ZyD7ZmC+as972V4Ozw YjO4t641uOFO1fsXdgE3cesoOCmtdMa/tKHg8BNJAaOp5TtwPx0G+O6JaDBnivVRUXeB dkfw== X-Gm-Message-State: AOUpUlEo7VLjmZVwAAO1pg5l63OkmSJpJ5VDyqi4cuwmw+olQZC34pr7 709K2ZmlwPyOW5YNPfiQi1Q= 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 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> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::244 Subject: [Qemu-devel] [PATCH v3 09/10] 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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.