From patchwork Thu Jul 19 12:15:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10534259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B4A8601D2 for ; Thu, 19 Jul 2018 12:19:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B2BD29561 for ; Thu, 19 Jul 2018 12:19:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E6E829575; Thu, 19 Jul 2018 12:19:18 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6E1BE29561 for ; Thu, 19 Jul 2018 12:19:17 +0000 (UTC) Received: from localhost ([::1]:42076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg7ts-0003f7-Mk for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 Jul 2018 08:19:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg7qd-00028j-KK for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:15:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fg7qa-0005Po-EN for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:15:55 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:36632) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fg7qa-0005PI-5k for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:15:52 -0400 Received: by mail-pg1-x544.google.com with SMTP id s7-v6so151993pgv.3 for ; Thu, 19 Jul 2018 05:15:52 -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=mReR75DCk+TpnJZj+H9n61iCvECX4EIvqFABg0+KinE=; b=XSmoFszewfAkYZywSny2RwUb8fDAxtwANQWCawHJ7ohzlO7xgp60hJnxyLaB63dCjb Du8PJQwgf1ICPnQ7Mr0tmzWoqT7rqiGY4RfFVhT7wH9h1Qhw/3S5gJCae7a1r5r9oaEx R+atUHGIG8KS+fGeg8YpT6UNpb/LdavlnXlbHd/ZcfVr/VSUdmrVmC2asSCRo6CIbB6N gtUpLd1OenvkGizurHLZn4sKMAa8bqkTR/aIb4WgNtVVfF5Mw96Emnd4s2Fjzo9ygkrY 6bL9MWQQ2g09vP8TqmUSvjI8dFhmg97jiWvp8bK4E/inrI75uaMAHckQhgcFJiTay+ad o+Sg== 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=mReR75DCk+TpnJZj+H9n61iCvECX4EIvqFABg0+KinE=; b=JGpt5l7V7KOrAPGGIvArbimY/jufb980ywl42971rI1E5JvoJ5NrsYg7fhaUVRQp2F FYci3ATuWW4PPGz/9f7+Gzmf6dU3jp44/vOYnlVNpzORNc2/qfMQjHkTvZefvSKmlVKD +bNL67m/q5AnRVHGDqFdoXVPL1lTi4yIlPsaZ7N3L9jWHiwWNL8jvdBVOURErl0zSEQO KiqgrM45BK6UiTu+BxFkgrW7sOduq8dSTTfomGe14GZaqkhfDN/G8omcnLUB7u3Uumgx fSca7ginZk87UGPy/UNfSegNv5kG7U7CB046WNQemJw5CPSwX/AWqEZOfljIVdqkKQl6 21dQ== X-Gm-Message-State: AOUpUlF2daZNawamRa9MjA/jYWv+0B/Bk4Yuw9YGzygafoe3UAnQYz/0 l2wEn8jFHeJSw6ztmakj/ag= X-Google-Smtp-Source: AAOMgpfaLcuRrkn+YaNf9iL/fTYYvt3TW78eJ6T/SAqDSiQ5RI9fLY0wZY7JUQ/xxFvthPA2jSwqyg== X-Received: by 2002:a63:c114:: with SMTP id w20-v6mr9723873pgf.234.1532002551301; Thu, 19 Jul 2018 05:15:51 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id h190-v6sm21270456pge.85.2018.07.19.05.15.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 05:15:50 -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: Thu, 19 Jul 2018 20:15:15 +0800 Message-Id: <20180719121520.30026-4-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180719121520.30026-1-xiaoguangrong@tencent.com> References: <20180719121520.30026-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v2 3/8] migration: show the statistics of compression 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong Currently, it includes: pages: amount of pages compressed and transferred to the target VM busy: amount of count that no free thread to compress data busy-rate: rate of thread busy reduced-size: amount of bytes reduced by compression compression-rate: rate of compressed size Signed-off-by: Xiao Guangrong --- hmp.c | 13 +++++++++++++ migration/migration.c | 11 +++++++++++ migration/ram.c | 37 +++++++++++++++++++++++++++++++++++++ migration/ram.h | 1 + qapi/migration.json | 26 +++++++++++++++++++++++++- 5 files changed, 87 insertions(+), 1 deletion(-) diff --git a/hmp.c b/hmp.c index 47d36e3ccf..a9e2776d60 100644 --- a/hmp.c +++ b/hmp.c @@ -271,6 +271,19 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) info->xbzrle_cache->overflow); } + if (info->has_compression) { + monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", + info->compression->pages); + monitor_printf(mon, "compression busy: %" PRIu64 "\n", + info->compression->busy); + monitor_printf(mon, "compression busy rate: %0.2f\n", + info->compression->busy_rate); + monitor_printf(mon, "compression reduced size: %" PRIu64 "\n", + info->compression->reduced_size); + monitor_printf(mon, "compression rate: %0.2f\n", + info->compression->compression_rate); + } + if (info->has_cpu_throttle_percentage) { monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", info->cpu_throttle_percentage); diff --git a/migration/migration.c b/migration/migration.c index 0af75465b3..8fedf13889 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -754,6 +754,17 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s) info->xbzrle_cache->overflow = xbzrle_counters.overflow; } + if (migrate_use_compression()) { + info->has_compression = true; + info->compression = g_malloc0(sizeof(*info->compression)); + info->compression->pages = compression_counters.pages; + info->compression->busy = compression_counters.busy; + info->compression->busy_rate = compression_counters.busy_rate; + info->compression->reduced_size = compression_counters.reduced_size; + info->compression->compression_rate = + compression_counters.compression_rate; + } + if (cpu_throttle_active()) { info->has_cpu_throttle_percentage = true; info->cpu_throttle_percentage = cpu_throttle_get_percentage(); diff --git a/migration/ram.c b/migration/ram.c index 1b016e048d..e68b0e6dec 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -300,6 +300,15 @@ struct RAMState { uint64_t num_dirty_pages_period; /* xbzrle misses since the beginning of the period */ uint64_t xbzrle_cache_miss_prev; + + /* compression statistics since the beginning of the period */ + /* amount of count that no free thread to compress data */ + uint64_t compress_thread_busy_prev; + /* amount bytes reduced by compression */ + uint64_t compress_reduced_size_prev; + /* amount of compressed pages */ + uint64_t compress_pages_prev; + /* number of iterations at the beginning of period */ uint64_t iterations_prev; /* Iterations since start */ @@ -337,6 +346,8 @@ struct PageSearchStatus { }; typedef struct PageSearchStatus PageSearchStatus; +CompressionStats compression_counters; + struct CompressParam { bool done; bool quit; @@ -1597,6 +1608,24 @@ static void migration_update_rates(RAMState *rs, int64_t end_time) rs->xbzrle_cache_miss_prev) / iter_count; rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss; } + + if (migrate_use_compression()) { + uint64_t comp_pages; + + compression_counters.busy_rate = (double)(compression_counters.busy - + rs->compress_thread_busy_prev) / iter_count; + rs->compress_thread_busy_prev = compression_counters.busy; + + comp_pages = compression_counters.pages - rs->compress_pages_prev; + if (comp_pages) { + compression_counters.compression_rate = + (double)(compression_counters.reduced_size - + rs->compress_reduced_size_prev) / + (comp_pages * TARGET_PAGE_SIZE); + rs->compress_pages_prev = compression_counters.pages; + rs->compress_reduced_size_prev = compression_counters.reduced_size; + } + } } static void migration_bitmap_sync(RAMState *rs) @@ -1872,6 +1901,9 @@ static void flush_compressed_data(RAMState *rs) qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { len = qemu_put_qemu_file(rs->f, comp_param[idx].file); + /* 8 means a header with RAM_SAVE_FLAG_CONTINUE. */ + compression_counters.reduced_size += TARGET_PAGE_SIZE - len + 8; + compression_counters.pages++; ram_counters.transferred += len; } qemu_mutex_unlock(&comp_param[idx].mutex); @@ -1903,6 +1935,10 @@ retry: qemu_cond_signal(&comp_param[idx].cond); qemu_mutex_unlock(&comp_param[idx].mutex); pages = 1; + /* 8 means a header with RAM_SAVE_FLAG_CONTINUE. */ + compression_counters.reduced_size += TARGET_PAGE_SIZE - + bytes_xmit + 8; + compression_counters.pages++; ram_counters.transferred += bytes_xmit; break; } @@ -2233,6 +2269,7 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, if (res > 0) { return res; } + compression_counters.busy++; } else if (migrate_use_multifd()) { return ram_save_multifd_page(rs, block, offset); } diff --git a/migration/ram.h b/migration/ram.h index 457bf54b8c..a139066846 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -36,6 +36,7 @@ extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; +extern CompressionStats compression_counters; int xbzrle_cache_resize(int64_t new_size, Error **errp); uint64_t ram_bytes_remaining(void); diff --git a/qapi/migration.json b/qapi/migration.json index b4f394844b..5a34aa1754 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -75,6 +75,27 @@ 'cache-miss': 'int', 'cache-miss-rate': 'number', 'overflow': 'int' } } +## +# @CompressionStats: +# +# Detailed migration compression statistics +# +# @pages: amount of pages compressed and transferred to the target VM +# +# @busy: count of times that no free thread was available to compress data +# +# @busy-rate: rate of thread busy +# +# @reduced-size: amount of bytes reduced by compression +# +# @compression-rate: rate of compressed size +# +# Since: 3.0 +## +{ 'struct': 'CompressionStats', + 'data': {'pages': 'int', 'busy': 'int', 'busy-rate': 'number', + 'reduced-size': 'int', 'compression-rate': 'number' } } + ## # @MigrationStatus: # @@ -172,6 +193,8 @@ # only present when the postcopy-blocktime migration capability # is enabled. (Since 3.0) # +# @compression: migration compression statistics, only returned if compression +# feature is on and status is 'active' or 'completed' (Since 3.0) # # Since: 0.14.0 ## @@ -186,7 +209,8 @@ '*cpu-throttle-percentage': 'int', '*error-desc': 'str', '*postcopy-blocktime' : 'uint32', - '*postcopy-vcpu-blocktime': ['uint32']} } + '*postcopy-vcpu-blocktime': ['uint32'], + '*compression': 'CompressionStats'} } ## # @query-migrate: