From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Wei Wang <wei.w.wang@intel.com>
Cc: kevin.tian@intel.com, quintela@redhat.com, qemu-devel@nongnu.org,
peterx@redhat.com, dgilbert@redhat.com, gloryxiao@tencent.com,
yi.y.sun@intel.com
Subject: Re: [PATCH v1 2/2] migration/xbzrle: add encoding rate
Date: Mon, 20 Apr 2020 10:30:06 +0100 [thread overview]
Message-ID: <20200420093006.GI346737@redhat.com> (raw)
In-Reply-To: <1587352003-3312-3-git-send-email-wei.w.wang@intel.com>
On Mon, Apr 20, 2020 at 11:06:43AM +0800, Wei Wang wrote:
> Users may need to check the xbzrle encoding rate to know if the guest
> memory is xbzrle encoding-friendly, and dynamically turn off the
> encoding if the encoding rate is low.
>
> Signed-off-by: Yi Sun <yi.y.sun@intel.com>
> Signed-off-by: Wei Wang <wei.w.wang@intel.com>
> ---
> migration/migration.c | 1 +
> migration/ram.c | 31 +++++++++++++++++++++++++++++--
> monitor/hmp-cmds.c | 2 ++
> qapi/migration.json | 5 ++++-
> slirp | 2 +-
> 5 files changed, 37 insertions(+), 4 deletions(-)
>
> diff --git a/migration/migration.c b/migration/migration.c
> index 8e7ee0d76b..84a556a4ac 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -930,6 +930,7 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s)
> info->xbzrle_cache->pages = xbzrle_counters.pages;
> info->xbzrle_cache->cache_miss = xbzrle_counters.cache_miss;
> info->xbzrle_cache->cache_miss_rate = xbzrle_counters.cache_miss_rate;
> + info->xbzrle_cache->encoding_rate = xbzrle_counters.encoding_rate;
> info->xbzrle_cache->overflow = xbzrle_counters.overflow;
> }
>
> diff --git a/migration/ram.c b/migration/ram.c
> index bca5878f25..c87c38ec80 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -327,6 +327,10 @@ struct RAMState {
> uint64_t num_dirty_pages_period;
> /* xbzrle misses since the beginning of the period */
> uint64_t xbzrle_cache_miss_prev;
> + /* Amount of xbzrle pages since the beginning of the period */
> + uint64_t xbzrle_pages_prev;
> + /* Amount of encoded bytes since the beginning of the period */
> + uint64_t encoded_size_prev;
>
> /* compression statistics since the beginning of the period */
> /* amount of count that no free thread to compress data */
> @@ -696,6 +700,18 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **current_data,
> return -1;
> }
>
> + /*
> + * Reaching here means the page has hit the xbzrle cache, no matter what
> + * encoding result it is (normal encoding, overflow or skipping the page),
> + * count the page as encoded. This is used to caculate the encoding rate.
> + *
> + * Example: 2 pages (8KB) being encoded, first page encoding generates 2KB,
> + * 2nd page turns out to be skipped (i.e. no new bytes written to the
> + * page), the overall encoding rate will be 8KB / 2KB = 4, which has the
> + * skipped page included. In this way, the encoding rate can tell if the
> + * guest page is good for xbzrle encoding.
> + */
> + xbzrle_counters.pages++;
> prev_cached_page = get_cached_data(XBZRLE.cache, current_addr);
>
> /* save current buffer into memory */
> @@ -736,7 +752,6 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **current_data,
> qemu_put_be16(rs->f, encoded_size);
> qemu_put_buffer(rs->f, XBZRLE.encoded_buf, encoded_size);
> bytes_xbzrle += encoded_size + 1 + 2;
> - xbzrle_counters.pages++;
> xbzrle_counters.encoded_size += encoded_size;
> ram_counters.transferred += bytes_xbzrle;
>
> @@ -859,7 +874,7 @@ uint64_t ram_get_total_transferred_pages(void)
> static void migration_update_rates(RAMState *rs, int64_t end_time)
> {
> uint64_t page_count = rs->target_page_count - rs->target_page_count_prev;
> - double compressed_size;
> + double compressed_size, encoded_size, unencoded_size;
>
> /* calculate period counters */
> ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000
> @@ -873,6 +888,18 @@ static void migration_update_rates(RAMState *rs, int64_t end_time)
> xbzrle_counters.cache_miss_rate = (double)(xbzrle_counters.cache_miss -
> rs->xbzrle_cache_miss_prev) / page_count;
> rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss;
> + unencoded_size = (xbzrle_counters.pages - rs->xbzrle_pages_prev) *
> + TARGET_PAGE_SIZE;
> + encoded_size = xbzrle_counters.encoded_size - rs->encoded_size_prev;
> + if (xbzrle_counters.pages == rs->xbzrle_pages_prev) {
> + xbzrle_counters.encoding_rate = 0;
> + } else if (!encoded_size) {
> + xbzrle_counters.encoding_rate = UINT64_MAX;
> + } else {
> + xbzrle_counters.encoding_rate = unencoded_size / encoded_size;
> + }
> + rs->xbzrle_pages_prev = xbzrle_counters.pages;
> + rs->encoded_size_prev = xbzrle_counters.encoded_size;
> }
>
> if (migrate_use_compression()) {
> diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
> index 6d3b35ca64..07f41e582f 100644
> --- a/monitor/hmp-cmds.c
> +++ b/monitor/hmp-cmds.c
> @@ -303,6 +303,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
> info->xbzrle_cache->cache_miss);
> monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
> info->xbzrle_cache->cache_miss_rate);
> + monitor_printf(mon, "xbzrle encoding rate: %0.2f\n",
> + info->xbzrle_cache->encoding_rate);
> monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n",
> info->xbzrle_cache->overflow);
> }
> diff --git a/qapi/migration.json b/qapi/migration.json
> index bf195ff6ac..ee4513c565 100644
> --- a/qapi/migration.json
> +++ b/qapi/migration.json
> @@ -70,6 +70,8 @@
> #
> # @cache-miss-rate: rate of cache miss (since 2.1)
> #
> +# @encoding-rate: rate of cache miss
> +#
> # @overflow: number of overflows
> #
> # Since: 1.2
> @@ -77,7 +79,7 @@
> { 'struct': 'XBZRLECacheStats',
> 'data': {'cache-size': 'int', 'encoded_size': 'int', 'pages': 'int',
> 'cache-miss': 'int', 'cache-miss-rate': 'number',
> - 'overflow': 'int' } }
> + 'encoding-rate': 'number', 'overflow': 'int' } }
>
> ##
> # @CompressionStats:
> @@ -337,6 +339,7 @@
> # "pages":2444343,
> # "cache-miss":2244,
> # "cache-miss-rate":0.123,
> +# "encoding-rate":80.1,
> # "overflow":34434
> # }
> # }
> diff --git a/slirp b/slirp
> index 55ab21c9a3..126c04acba 160000
> --- a/slirp
> +++ b/slirp
> @@ -1 +1 @@
> -Subproject commit 55ab21c9a36852915b81f1b41ebaf3b6509dd8ba
> +Subproject commit 126c04acbabd7ad32c2b018fe10dfac2a3bc1210
Accidental inclusion of submodule changes
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2020-04-20 9:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-20 3:06 [PATCH v1 0/2] Migration xbzrle changes Wei Wang
2020-04-20 3:06 ` [PATCH v1 1/2] migration/xbzrle: replace transferred xbzrle bytes with encoded bytes Wei Wang
2020-04-20 9:29 ` Daniel P. Berrangé
2020-04-20 9:49 ` Wei Wang
2020-04-21 19:21 ` Dr. David Alan Gilbert
2020-04-22 2:51 ` Wei Wang
2020-04-24 10:47 ` Dr. David Alan Gilbert
2020-04-27 7:26 ` Wei Wang
2020-04-20 3:06 ` [PATCH v1 2/2] migration/xbzrle: add encoding rate Wei Wang
2020-04-20 9:30 ` Daniel P. Berrangé [this message]
2020-04-20 14:53 ` Eric Blake
2020-04-21 1:14 ` Wei Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200420093006.GI346737@redhat.com \
--to=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=gloryxiao@tencent.com \
--cc=kevin.tian@intel.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=wei.w.wang@intel.com \
--cc=yi.y.sun@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).