Skip to contentSkip to conversation

XBZRLE delta for live migration of large memory app

PATCH Superseded Orit Wasserman 2 participants 19 messages Jul 5, 2012 – Jul 6, 2012 Kbuild

v15 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v15 cover XBZRLE delta for live migration of large memory app

Changes from v14:
- rebase on top on Juan's patches
- Use clz64 to calculate pow2floor (round down to power of 2)
- Fix xbzrle_encode_buffer and xbzrle_decode_buffer
- Fix QMP commands documentation
Changes from v13:
- Fix round to power of 2 of cache size
- Add more checks to the XBZRLE encoding.
- use comparison instead of XOR when calculating zrun_len
- use strcmp trick for calculating nzrun_len (algorithm from Eric Blake)
- Fix other comments by Eric Blake
- Fix comments from Blue Swirl
- Display migration statics after migration completes
Changes from v12:
- use bool for blk and shared params
- use long when decoding buffer
- fix QMP commands
- always display migration parameters in "info migrate"
- update current_addr inside the while loop in ram_save_block
- display statistics after migration completes
- fix other review comments from Eric Blake

Changes from v11:
- divide patch 7 to several smaller patches.
- Use an array for setting migration parameters QMP only (there is not support for arrays in HMP commands). parameters can be enabled or disabled.
- Do not use XBZRLE in stage 3 , it is a very sensitive stage and CPU can be an issue.
- Fix review comments by Juan Quintela and Eric Blake

Changes from v10:
- Cache size will be in bytes, in case it is not a power of 2 it will be reduced to the nearest power of 2.
- fix documentation
- use cache_init with number of pages not cache size.

Changes from v9:
- move cache implementation to separate files. Kept our own implementation because GCache or GHashTable have no size limit.
- Add migrate_set_parameter function
- removed XBZRLE option from migrate command
- add cache size information to query_migrate command
- add documantation file
- write/read the exact XBZRLE header format
- fix other review comments by Anthony and Juan

Changes from v8:
Implement more effiecent cache_resize method fix set_cachesize command

Changes from v7:
Copy current page before encoding it, this will prevents page content change during the encoding.
Allow changing the cache size during an active migration. Fix comments by Avi.

Changes from v6:
1) add assert checks to ULEB encoding/decoding
2) no need to send last zero run

Changes from v5:
1) Add migration capabilities
2) Use ULEB to encode run length
3) Do not send unmodified (dirty) page
3) Fix other patch comments

Using GCache or GHashTable requires allocating new buffer on every content change and have no size limit , so I decided to keep the simple cache implementation.

Changes from v4:
1) Rebase
2) divide patch into 9 patches
3) move memory allocation into cache_insert

Future work :
Use SSE for encoding.
Page ranking acording to their dirty rate and automatic activation/deactivation of the feature - will be sent in a separate patch series.

By using XBZRLE (Xor Based Zero Run Length Encoding) we can reduce VM downtime and total live-migration time of VMs running memory write intensive workloads typical of large enterprise applications such as SAP ERP Systems, and generally speaking for any application with a sparse memory update pattern.

The compression format uses the fact that we will have many zero (zero represents an unchanged value).
We repesent the page data delta by zero and non zero runs.
We represent a zero run with it's length (in bytes).
We represent a non zero run with it's length (in bytes) and the data. The run length is encoded using ULEB128 (http://en.wikipedia.org/wiki/LEB128)

page = zrun nzrun
| zrun nzrun page

zrun = length

nzrun = length byte...

length = uleb128 encoded integer

On the sender side XBZRLE is used as a compact delta encoding of page updates, retrieving the old page content from an LRU cache (default size of 512 MB). The receiving side uses the existing page content and XBZRLE to decode the new page content.

This is a more compact way to store the delta than the previous version.

This work was originally based on research results published VEE 2011: Evaluation of Delta Compression Techniques for Efficient Live Migration of Large Virtual Machines by Benoit, Svard, Tordsson and Elmroth. Additionally the delta encoder XBRLE was improved further using XBZRLE instead.

XBZRLE has a sustained bandwidth of 2-2.5 GB/s for typical workloads making it ideal for in-line, real-time encoding such as is needed for live-migration.

A typical usage scenario:
On incoming QEMU:
{qemu} migrate_set_parameter xbzrle on
On outgoing QEMU:
{qemu} migrate_set_parameter xbzrle on
{qemu} migrate_set_cachesize 256m
{qemu} migrate -d tcp:destination.host:4444
{qemu} info migrate
...
cache size : 64 MBytes
transferred ram: A kbytes
remaining ram: B kbytes
total ram: C kbytes
cache size: D bytes
xbzrle transferred: E kbytes
xbzrle pages: F pages
xbzrle cache miss: G
xbzrle overflow : H

Testing: live migration with XBZRLE completed in 110 seconds, without live migration was not able to complete.

A simple synthetic memory r/w load generator:

..    include <stdlib.h>
..    include <stdio.h>
..    int main()
..    {

.. char *buf = (char *) calloc(4096, 4096);
.. while (1) {
.. int i;
.. for (i = 0; i < 4096 * 4; i++) {
.. buf[i * 4096 / 4]++;
.. }
.. printf(".");
.. }
.. }

Orit Wasserman (9):
Add migration capabilities
Add XBZRLE documentation
Add cache handling functions
Add uleb encoding/decoding functions
Change ram_save_block to return -1 if there are no more changes Add xbzrle_encode_buffer and xbzrle_decode_buffer functions Add XBZRLE to ram_save_block and ram_save_live
Add set_cachesize command
Add XBZRLE statistics

 Makefile.objs             |    1 +
 arch_init.c               |  272 +++++++++++++++++++++++++++++++++++++++++++--
 cutils.c                  |   41 +++++++
 docs/xbzrle.txt           |  136 ++++++++++++++++++++++
 hmp-commands.hx           |   35 ++++++
 hmp.c                     |   90 +++++++++++++++
 hmp.h                     |    3 +
 include/qemu/page_cache.h |   79 +++++++++++++
 migration.c               |  160 ++++++++++++++++++++++++++-
 migration.h               |   21 ++++
 monitor.c                 |    7 +
 page_cache.c              |  216 +++++++++++++++++++++++++++++++++++
 qapi-schema.json          |  102 ++++++++++++++++-
 qemu-common.h             |   21 ++++
 qmp-commands.hx           |  127 ++++++++++++++++++++-
 savevm.c                  |  157 ++++++++++++++++++++++++++
 16 files changed, 1449 insertions(+), 19 deletions(-)
 create mode 100644 docs/xbzrle.txt
 create mode 100644 include/qemu/page_cache.h
 create mode 100644 page_cache.c
Signature · 1 line
1.7.7.6
#1 lore raw

PATCH v15 1/9 Add migration capabilities

Add migration capabilities that can be queried by the management. The management can query the source QEMU and the destination QEMU in order to verify both support some migration capability (currently only XBZRLE). The management can enable a capability for the next migration by using migrate_set_parameter command.

---
 hmp-commands.hx  |   16 ++++++++++++
 hmp.c            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    2 +
 migration.c      |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 migration.h      |    2 +
 monitor.c        |    7 +++++
 qapi-schema.json |   53 ++++++++++++++++++++++++++++++++++++++-
 qmp-commands.hx  |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 8 files changed, 280 insertions(+), 7 deletions(-)
hmp-commands.hx +16 -0
index f5d9d91..9245bef 100644
@@ -861,6 +861,20 @@ Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
 
     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "",
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+ETEXI
+
+    {
         .name       = "client_migrate_info",
         .args_type  = "protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?",
         .params     = "protocol hostname port tls-port cert-subject",
@@ -1419,6 +1433,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migration_capabilities
+show migration capabilities
 @item info balloon
 show balloon information
 @item info qtree
hmp.c +64 -0

85 lines not on this page · raw message

hmp.h +2 -0
index 79d138d..09ba198 100644
@@ -25,6 +25,7 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_info_mice(Monitor *mon);
 void hmp_info_migrate(Monitor *mon);
+void hmp_info_migration_capabilities(Monitor *mon);
 void hmp_info_cpus(Monitor *mon);
 void hmp_info_block(Monitor *mon);
 void hmp_info_blockstats(Monitor *mon);
@@ -51,6 +52,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict);
 void hmp_set_password(Monitor *mon, const QDict *qdict);
 void hmp_expire_password(Monitor *mon, const QDict *qdict);
 void hmp_eject(Monitor *mon, const QDict *qdict);
migration.c +70 -2

106 lines not on this page · raw message

migration.h +2 -0
index de13004..acc0b94 100644
@@ -18,6 +18,7 @@
 #include "qemu-common.h"
 #include "notify.h"
 #include "error.h"
+#include "qapi-types.h"
 
 struct MigrationParams {
     bool blk;
@@ -38,6 +39,7 @@ struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };
 
 void process_incoming_migration(QEMUFile *f);
monitor.c +7 -0
index f6107ba..e2be6cd 100644
@@ -2687,6 +2687,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_migrate,
     },
     {
+        .name       = "migration_capabilities",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration capabilities",
+        .mhandler.info = hmp_info_migration_capabilities,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
qapi-schema.json +51 -2

68 lines not on this page · raw message

qmp-commands.hx +68 -3

104 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#2 lore raw

PATCH v15 2/9 Add XBZRLE documentation

In reply to Orit Wasserman
---
 docs/xbzrle.txt |  136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 136 insertions(+), 0 deletions(-)
 create mode 100644 docs/xbzrle.txt
docs/xbzrle.txt new file +136 -0
new file mode 100644
index 0000000..cb567e6
@@ -0,0 +1,136 @@
+XBZRLE (Xor Based Zero Run Length Encoding)
+===========================================
+
+Using XBZRLE (Xor Based Zero Run Length Encoding) allows for the reduction
+of VM downtime and the total live-migration time of Virtual machines.
+It is particularly useful for virtual machines running memory write intensive
+workloads that are typical of large enterprise applications such as SAP ERP
+Systems, and generally speaking for any application that uses a sparse memory
+update pattern.
+
+Instead of sending the changed guest memory page this solution will send a
+compressed version of the updates, thus reducing the amount of data sent during
+live migration.
+In order to be able to calculate the update, the previous memory pages need to
+be stored on the source. Those pages are stored in a dedicated cache
+(hash table) and are
+accessed by their address.
+The larger the cache size the better the chances are that the page has already
+been stored in the cache.
+A small cache size will result in high cache miss rate.
+Cache size can be changed before and during migration.
+
+Format
+=======
+
+The compression format performs a XOR between the previous and current content
+of the page, where zero represents an unchanged value.
+The page data delta is represented by zero and non zero runs.
+A zero run is represented by its length (in bytes).
+A non zero run is represented by its length (in bytes) and the new data.
+The run length is encoded using ULEB128 (http://en.wikipedia.org/wiki/LEB128)
+
+There can be more than one valid encoding, the sender may send a longer encoding
+for the benefit of reducing computation cost.
+
+page = zrun nzrun
+       | zrun nzrun page
+
+zrun = length
+
+nzrun = length byte...
+
+length = uleb128 encoded integer
+
+On the sender side XBZRLE is used as a compact delta encoding of page updates,
+retrieving the old page content from the cache (default size of 512 MB). The
+receiving side uses the existing page's content and XBZRLE to decode the new
+page's content.
+
+This work was originally based on research results published
+VEE 2011: Evaluation of Delta Compression Techniques for Efficient Live
+Migration of Large Virtual Machines by Benoit, Svard, Tordsson and Elmroth.
+Additionally the delta encoder XBRLE was improved further using the XBZRLE
+instead.
+
+XBZRLE has a sustained bandwidth of 2-2.5 GB/s for typical workloads making it
+ideal for in-line, real-time encoding such as is needed for live-migration.
+
+Example
+old buffer:
+1001 zeros
+05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 00 00 6b 00 6d
+3074 zeros
+
+new buffer:
+1001 zeros
+01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 00 00 67 00 69
+3704 zeros
+
+encoded buffer:
+
+encoded length 24
+e9 07 0f 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 03 01 67 01 01 69
+
+Migration Capabilities
+======================
+In order to use XBZRLE the destination QEMU version should be able to
+decode the new format.
+Adding a new migration capabilities command that will allow external management
+to query for it support.
+A typical use for the destination
+    {qemu} info migrate_capabilities
+    {qemu} xbzrle, ...
+
+In order to enable capabilities for future live migration,
+a new command migrate_set_parameter is introduced:
+    {qemu} migrate_set_parameter xbzrle
+
+Usage
+======
+
+1. Activate xbzrle
+2. Set the XBZRLE cache size - the cache size is in MBytes and should be a
+power of 2. The cache default value is 64MBytes.
+3. start outgoing migration
+
+A typical usage scenario:
+On the incoming QEMU:
+    {qemu} migrate_set_parameter xbzrle on
+On the outgoing QEMU:
+    {qemu} migrate_set_parameter xbzrle on
+    {qemu} migrate_set_cachesize 256m
+    {qemu} migrate -d tcp:destination.host:4444
+    {qemu} info migrate
+    ...
+    cache size: 67108864 bytes
+    transferred ram-duplicate: A kbytes
+    transferred ram-normal: B kbytes
+    transferred ram-xbrle: C kbytes
+    overflow ram-xbrle: D pages
+    cache-miss ram-xbrle: E pages
+
+cache-miss: the number of cache misses to date - high cache-miss rate
+indicates that the cache size is set too low.
+overflow: the number of overflows in the decoding which where the delta could
+not be compressed. This can happen if the changes in the pages are too large
+or there are many short changes; for example, changing every second byte (half a
+page).
+
+Testing: Testing indicated that live migration with XBZRLE was completed in 110
+seconds, whereas without it would not be able to complete.
+
+A simple synthetic memory r/w load generator:
+..    include <stdlib.h>
+..    include <stdio.h>
+..    int main()
+..    {
+..        char *buf = (char *) calloc(4096, 4096);
+..        while (1) {
+..            int i;
+..            for (i = 0; i < 4096 * 4; i++) {
+..                buf[i * 4096 / 4]++;
+..            }
+..            printf(".");
+..        }
+..    }
Signature · 1 line
1.7.7.6
#3 lore raw

Re: [Qemu-devel] [PATCH v15 2/9] Add XBZRLE documentation

docs/xbzrle.txt line 63

Quoted 13 lines · Orit Wasserman
---
 docs/xbzrle.txt |  136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 136 insertions(+), 0 deletions(-)
 create mode 100644 docs/xbzrle.txt
docs/xbzrle.txt new file +6 -0
+
+Example
+old buffer:
+1001 zeros
+05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 00 00 6b 00 6d
+3074 zeros

This _still_ doesn't add up to 4096:

1001 + 20 + 3074 = 4095

docs/xbzrle.txt line 68

Quoted 5 lines
docs/xbzrle.txt new file +5 -0
+
+new buffer:
+1001 zeros
+01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 00 00 67 00 69
+3704 zeros

Still a transposition error.

Also, this still has the flaw that it is too weak of an example - the only unchanged bytes happen to also be zero bytes to begin with; it would be much nicer if the example included at least one non-zero byte that did not change between old and new.

docs/xbzrle.txt line 73

Quoted 5 lines
docs/xbzrle.txt new file +5 -0
+
+encoded buffer:
+
+encoded length 24
+e9 07 0f 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 03 01 67 01 01 69
                                                         ^^

That says you have a zrun of 3 bytes, but the example only shows a zrun of 2 bytes.

It feels like I'm pulling teeth to get a good example. If you will just squash in the following (hand-written) diff below, you will then have 4096 bytes in both old and new buffers, and your encoded buffer listing a zrun of 3 will be correct, plus you will be demonstrating a non-zero byte that remained unchanged.

@@ ???,??? @@
Example
old buffer:
1001 zeros
-05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 00 00 6b 00 6d +05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 68 00 00 6b 00 6d
3074 zeros

new buffer:
1001 zeros
-01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 00 00 67 00 69 -3704 zeros
+01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 68 00 00 67 00 69 +3074 zeros

encoded buffer:

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw

Re: [Qemu-devel] [PATCH v15 2/9] Add XBZRLE documentation

Quoted 55 lines · Eric Blake

docs/xbzrle.txt line 63

Quoted 13 lines · Orit Wasserman
---
 docs/xbzrle.txt |  136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 136 insertions(+), 0 deletions(-)
 create mode 100644 docs/xbzrle.txt
docs/xbzrle.txt new file +6 -0
+
+Example
+old buffer:
+1001 zeros
+05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 00 00 6b 00 6d
+3074 zeros

This _still_ doesn't add up to 4096:

1001 + 20 + 3074 = 4095

docs/xbzrle.txt line 68

Quoted 5 lines
docs/xbzrle.txt new file +5 -0
+
+new buffer:
+1001 zeros
+01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 00 00 67 00 69
+3704 zeros

Still a transposition error.

Also, this still has the flaw that it is too weak of an example - the only unchanged bytes happen to also be zero bytes to begin with; it would be much nicer if the example included at least one non-zero byte that did not change between old and new.

docs/xbzrle.txt line 73

Quoted 5 lines
docs/xbzrle.txt new file +5 -0
+
+encoded buffer:
+
+encoded length 24
+e9 07 0f 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 03 01 67 01 01 69
                                                         ^^

That says you have a zrun of 3 bytes, but the example only shows a zrun of 2 bytes.

It feels like I'm pulling teeth to get a good example. If you will just squash in the following (hand-written) diff below, you will then have 4096 bytes in both old and new buffers, and your encoded buffer listing a zrun of 3 will be correct, plus you will be demonstrating a non-zero byte that remained unchanged.

@@ ???,??? @@
Example
old buffer:
1001 zeros
-05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 00 00 6b 00 6d +05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 68 00 00 6b 00 6d
3074 zeros

Quoted 9 lines

new buffer:
1001 zeros
-01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 00 00 67 00 69 -3704 zeros
+01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 68 00 00 67 00 69 +3074 zeros

encoded buffer:

I will use this example ,
thanks,
Orit

#5 lore raw

PATCH v15 3/9 Add cache handling functions

In reply to Orit Wasserman

Add LRU page cache mechanism.
The page are accessed by their address.

---
 Makefile.objs             |    1 +
 cutils.c                  |    8 ++
 include/qemu/page_cache.h |   79 ++++++++++++++++
 page_cache.c              |  216 +++++++++++++++++++++++++++++++++++++++++++++
 qemu-common.h             |   13 +++
 5 files changed, 317 insertions(+), 0 deletions(-)
 create mode 100644 include/qemu/page_cache.h
 create mode 100644 page_cache.c
Makefile.objs +1 -0
index 625c4d5..d7a199e 100644
@@ -77,6 +77,7 @@ common-obj-y += qemu-char.o #aio.o
 common-obj-y += block-migration.o iohandler.o
 common-obj-y += pflib.o
 common-obj-y += bitmap.o bitops.o
+common-obj-y += page_cache.o
 
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
 common-obj-$(CONFIG_WIN32) += version.o
cutils.c +8 -0
index af308cd..02d5bd0 100644
@@ -549,3 +549,11 @@ int qemu_sendv(int sockfd, struct iovec *iov, int len, int iov_offset)
     return do_sendv_recvv(sockfd, iov, len, iov_offset, 1);
 }
 
+/* round down to the nearest power of 2*/
+int64_t pow2floor(int64_t value)
+{
+    if (!is_power_of_2(value)) {
+        value = 0x8000000000000000ULL >> clz64(value);
+    }
+    return value;
+}
include/qemu/page_cache.h new file +79 -0

79 lines not on this page · raw message

page_cache.c new file +216 -0

216 lines not on this page · raw message

qemu-common.h +13 -0
index c8c6b2a..a6987d7 100644
@@ -1,3 +1,4 @@
+
 /* Common header file that is included by all of qemu.  */
 #ifndef QEMU_COMMON_H
 #define QEMU_COMMON_H
@@ -417,6 +418,18 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
 /* Round number up to multiple */
 #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m))
 
+static inline bool is_power_of_2(int64_t value)
+{
+    if (!value) {
+        return 0;
+    }
+
+    return !(value & (value - 1));
+}
+
+/* round down to the nearest power of 2*/
+int64_t pow2floor(int64_t value);
+
 #include "module.h"
 
 #endif
Signature · 1 line
1.7.7.6
#6 lore raw

PATCH v15 4/9 Add uleb encoding/decoding functions

In reply to Orit Wasserman

Implement Unsigned Little Endian Base 128.

---
 cutils.c      |   33 +++++++++++++++++++++++++++++++++
 qemu-common.h |    8 ++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)
cutils.c +33 -0
index 02d5bd0..7d99fe0 100644
@@ -557,3 +557,36 @@ int64_t pow2floor(int64_t value)
     }
     return value;
 }
+
+/*
+ * Implementation of  ULEB128 (http://en.wikipedia.org/wiki/LEB128)
+ * Input is limited to 14-bit numbers
+ */
+int uleb128_encode_small(uint8_t *out, uint32_t n)
+{
+    g_assert(n <= 0x3fff);
+    if (n < 0x80) {
+        *out++ = n;
+        return 1;
+    } else {
+        *out++ = (n & 0x7f) | 0x80;
+        *out++ = n >> 7;
+        return 2;
+    }
+}
+
+int uleb128_decode_small(const uint8_t *in, uint32_t *n)
+{
+    if (!(*in & 0x80)) {
+        *n = *in++;
+        return 1;
+    } else {
+        *n = *in++ & 0x7f;
+        /* we exceed 14 bit number */
+        if (*in & 0x80) {
+            return -1;
+        }
+        *n |= *in++ << 7;
+        return 2;
+    }
+}
qemu-common.h +8 -0
index a6987d7..ae2b850 100644
@@ -432,4 +432,12 @@ int64_t pow2floor(int64_t value);
 
 #include "module.h"
 
+/*
+ * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128)
+ * Input is limited to 14-bit numbers
+ */
+
+int uleb128_encode_small(uint8_t *out, uint32_t n);
+int uleb128_decode_small(const uint8_t *in, uint32_t *n);
+
 #endif
Signature · 1 line
1.7.7.6
#7 lore raw

PATCH v15 5/9 Change ram_save_block to return -1 if there are no more changes

In reply to Orit Wasserman

It will return 0 if the page is unmodifed.

---
 arch_init.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
arch_init.c +7 -4
index 9fd6346..e36899e 100644
@@ -188,7 +188,7 @@ static int ram_save_block(QEMUFile *f)
 {
     RAMBlock *block = last_block;
     ram_addr_t offset = last_offset;
-    int bytes_sent = 0;
+    int bytes_sent = -1;
     MemoryRegion *mr;
 
     if (!block)
@@ -349,8 +349,11 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
         int bytes_sent;
 
         bytes_sent = ram_save_block(f);
-        bytes_transferred += bytes_sent;
-        if (bytes_sent == 0) { /* no more blocks */
+        /* bytes_sent 0 represent unchanged page,
+           bytes_sent -1 represent no more blocks*/
+        if (bytes_sent > 0) {
+            bytes_transferred += bytes_sent;
+        } else if (bytes_sent == -1) { /* no more blocks */
             break;
         }
         /* we want to check in the 1st loop, just in case it was the 1st time
@@ -387,7 +390,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
         int bytes_sent;
 
         /* flush all remaining blocks regardless of rate limiting */
-        while ((bytes_sent = ram_save_block(f)) != 0) {
+        while ((bytes_sent = ram_save_block(f)) != -1) {
             bytes_transferred += bytes_sent;
         }
         migration_end();
Signature · 1 line
1.7.7.6
#8 lore raw

PATCH v15 6/9 Add xbzrle_encode_buffer and xbzrle_decode_buffer functions

In reply to Orit Wasserman
---
 migration.h |    4 ++
 savevm.c    |  157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 161 insertions(+), 0 deletions(-)
migration.h +4 -0
index acc0b94..c46af82 100644
@@ -100,4 +100,8 @@ void migrate_add_blocker(Error *reason);
  */
 void migrate_del_blocker(Error *reason);
 
+int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
+                         uint8_t *dst, int dlen);
+int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);
+
 #endif
savevm.c +157 -0

160 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#9 lore raw

Re: [Qemu-devel] [PATCH v15 6/9] Add xbzrle_encode_buffer and xbzrle_decode_buffer functions

On 07/05/2012 06:51 AM, Orit Wasserman wrote:

This commit message is a bit sparse. I'd document at least the fact that our nzrun detection code in xbzrle_encode_buffer borrows long-word-at-a-time NUL-detection tricks from strcmp(), as it is not an intuitive trick known by all developers.

Quoted 4 lines

I think I touched this one heavily enough that it warrants adding:

Other than the commit message, I'm happy with this patch contents now. Still some nits, though:

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2417

Quoted 3 lines
savevm.c +3 -0
+
+         /* not aligned to sizeof(long) */
+        res = (slen - i) % sizeof(long);

Comment indentation is off.

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2424

Quoted 7 lines
savevm.c +7 -0
+        while (res && old_buf[i] == new_buf[i]) {
+            zrun_len++;
+            i++;
+            res--;
+        }
+
+        if (!res) {

A comment here might help:

/* word at a time for speed */

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2426

Quoted 2 lines
savevm.c +2 -0
+            while (i < slen &&
+                   (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) {

On re-reading this, I'm worried whether it violates strict C99 aliasing rules; I'm hoping the compiler doesn't mis-optimize it based on a loophole of us using questionable semantics. In practice, I'm confident that we are only doing aligned reads (otherwise I wouldn't have suggested this line in the first place), which is why I'm personally okay with it even if it technically violates C99. However, I'm open to suggestions from anyone else on the list on how to better express the notion of intentionally accessing a long at a time from an aligned offset into a byte array, if that will help us avoid even theoretical problems.

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2466

Quoted 6 lines
savevm.c +6 -0
+            nzrun_len++;
+            res--;
+        }
+
+        if (!res) {
+            /* truncation to 32-bit long okay */

Again, a longer comment might help:

/* word at a time for speed, use of 32-bit long okay */

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2469

Quoted 3 lines
savevm.c +3 -0
+            long mask = 0x0101010101010101ULL;
+            while (i < slen) {
+                xor = *(long *)(old_buf + i) ^ *(long *)(new_buf + i);

Same potential strict aliasing problems as for zrun detection.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw

Re: [Qemu-devel] [PATCH v15 6/9] Add xbzrle_encode_buffer and xbzrle_decode_buffer functions

Quoted 7 lines · Eric Blake

On 07/05/2012 06:51 AM, Orit Wasserman wrote:

This commit message is a bit sparse. I'd document at least the fact that our nzrun detection code in xbzrle_encode_buffer borrows long-word-at-a-time NUL-detection tricks from strcmp(), as it is not an intuitive trick known by all developers.

Quoted 9 lines
Quoted 4 lines

I think I touched this one heavily enough that it warrants adding:

Of course
Orit

Quoted 24 lines

Other than the commit message, I'm happy with this patch contents now. Still some nits, though:

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2417

Quoted 3 lines
savevm.c +3 -0
+
+         /* not aligned to sizeof(long) */
+        res = (slen - i) % sizeof(long);

Comment indentation is off.

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2424

Quoted 7 lines
savevm.c +7 -0
+        while (res && old_buf[i] == new_buf[i]) {
+            zrun_len++;
+            i++;
+            res--;
+        }
+
+        if (!res) {

A comment here might help:

/* word at a time for speed */

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2426

Quoted 2 lines
savevm.c +2 -0
+            while (i < slen &&
+                   (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) {
Quoted 10 lines

On re-reading this, I'm worried whether it violates strict C99 aliasing rules; I'm hoping the compiler doesn't mis-optimize it based on a loophole of us using questionable semantics. In practice, I'm confident that we are only doing aligned reads (otherwise I wouldn't have suggested this line in the first place), which is why I'm personally okay with it even if it technically violates C99. However, I'm open to suggestions from anyone else on the list on how to better express the notion of intentionally accessing a long at a time from an aligned offset into a byte array, if that will help us avoid even theoretical problems.

This is a very interesting question ....

Orit

Quoted 18 lines

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2466

Quoted 7 lines
savevm.c +6 -0
+            nzrun_len++;
+            res--;
+        }
+
+        if (!res) {
+            /* truncation to 32-bit long okay */

Again, a longer comment might help:

/* word at a time for speed, use of 32-bit long okay */

savevm.c void vmstate_register_ram_global(MemoryRegion *mr) · line 2469

Quoted 3 lines
savevm.c +3 -0
+            long mask = 0x0101010101010101ULL;
+            while (i < slen) {
+                xor = *(long *)(old_buf + i) ^ *(long *)(new_buf + i);

Same potential strict aliasing problems as for zrun detection.

#11 lore raw

PATCH v15 7/9 Add XBZRLE to ram_save_block and ram_save_live

In reply to Orit Wasserman

In the outgoing migration check to see if the page is cached and changed than send compressed page by using save_xbrle_page function. In the incoming migration check to see if RAM_SAVE_FLAG_XBRLE is set and decompress the page (by using load_xbrle function).

---
 arch_init.c |  185 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 migration.c |   24 ++++++++
 migration.h |    4 +
 3 files changed, 208 insertions(+), 5 deletions(-)
arch_init.c +180 -5
index e36899e..7b65551 100644
@@ -43,6 +43,7 @@
 #include "hw/smbios.h"
 #include "exec-memory.h"
 #include "hw/pcspk.h"
+#include "qemu/page_cache.h"
 
 #ifdef DEBUG_ARCH_INIT
 #define DPRINTF(fmt, ...) \
@@ -102,6 +103,7 @@ const uint32_t arch_type = QEMU_ARCH;
 #define RAM_SAVE_FLAG_PAGE     0x08
 #define RAM_SAVE_FLAG_EOS      0x10
 #define RAM_SAVE_FLAG_CONTINUE 0x20
+#define RAM_SAVE_FLAG_XBZRLE   0x40
 
 #ifdef __ALTIVEC__
 #include <altivec.h>
@@ -169,6 +171,27 @@ static int is_dup_page(uint8_t *page)
     return 1;
 }
 
+/* XBZRLE (Xor Based Zero Length Encoding */
+typedef struct XBZRLEHeader {
+    uint16_t xh_len;
+    uint8_t xh_flags;
+} XBZRLEHeader;
+
+/* struct contains XBZRLE cache and a static page
+   used by the compression */
+static struct {
+    /* buffer used for XBZRLE encoding */
+    uint8_t *encoded_buf;
+    /* buffer used for XBZRLE decoding */
+    uint8_t *decoded_buf;
+    /* Cache for XBZRLE */
+    PageCache *cache;
+} XBZRLE = {
+    .encoded_buf = NULL,
+    .decoded_buf = NULL,
+    .cache = NULL,
+};
+
 static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
         int cont, int flag)
 {
@@ -181,15 +204,74 @@ static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
 
 }
 
+#define ENCODING_FLAG_XBZRLE 0x1
+
+static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
+                            ram_addr_t current_addr, RAMBlock *block,
+                            ram_addr_t offset, int cont, int stage)
+{
+    int encoded_len = 0, bytes_sent = -1, ret = -1;
+    XBZRLEHeader hdr = {
+        .xh_len = 0,
+        .xh_flags = 0,
+    };
+    uint8_t *prev_cached_page;
+
+    /* Stage 1 cache the page and exit.
+       Stage 2 check to see if page is cached , if not cache the page.
+       Stage 3 check if the page is cached and if not exit.
+    */
+    if (stage == 1 || !cache_is_cached(XBZRLE.cache, current_addr)) {
+        cache_insert(XBZRLE.cache, current_addr,
+                     g_memdup(current_data, TARGET_PAGE_SIZE));
+        return -1;
+    }
+
+    prev_cached_page = get_cached_data(XBZRLE.cache, current_addr);
+
+    /* XBZRLE encoding (if there is no overflow) */
+    encoded_len = xbzrle_encode_buffer(prev_cached_page, current_data,
+                                       TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
+                                       TARGET_PAGE_SIZE);
+    if (encoded_len == 0) {
+        DPRINTF("Unmodifed page skipping\n");
+        return 0;
+    } else if (encoded_len == -1) {
+        DPRINTF("Overflow\n");
+        /* update data in the cache */
+        memcpy(prev_cached_page, current_data, TARGET_PAGE_SIZE);
+        return -1;
+    }
+
+    /* we need to update the data in the cache, in order to get the same data
+       we cached we decode the encoded page on the cached data */
+    ret = xbzrle_decode_buffer(XBZRLE.encoded_buf, encoded_len,
+                               prev_cached_page, TARGET_PAGE_SIZE);
+    g_assert(ret != -1);
+
+    hdr.xh_len = encoded_len;
+    hdr.xh_flags |= ENCODING_FLAG_XBZRLE;
+
+    /* Send XBZRLE based compressed page */
+    save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
+    qemu_put_byte(f, hdr.xh_flags);
+    qemu_put_be16(f, hdr.xh_len);
+    qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
+    bytes_sent = encoded_len + sizeof(hdr);
+
+    return bytes_sent;
+}
+
 static RAMBlock *last_block;
 static ram_addr_t last_offset;
 
-static int ram_save_block(QEMUFile *f)
+static int ram_save_block(QEMUFile *f, int stage)
 {
     RAMBlock *block = last_block;
     ram_addr_t offset = last_offset;
     int bytes_sent = -1;
     MemoryRegion *mr;
+    ram_addr_t current_addr;
 
     if (!block)
         block = QLIST_FIRST(&ram_list.blocks);
@@ -210,13 +292,31 @@ static int ram_save_block(QEMUFile *f)
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
                 qemu_put_byte(f, *p);
                 bytes_sent = 1;
-            } else {
+            } else if (migrate_use_xbzrle() && stage != 3) {
+                current_addr = block->offset + offset;
+                /* In stage 1 we only cache the pages before sending them
+                   from the cache (uncompressed).
+                   We doen't use compression for stage 3.
+                */
+                bytes_sent = save_xbzrle_page(f, p, current_addr, block,
+                                              offset, cont, stage);
+
+                /* send the cached page copy for consistency
+                   In stage 3 we send the host page */
+                p = get_cached_data(XBZRLE.cache, current_addr);
+            }
+
+            /* either we didn't send yet (we may got XBZRLE overflow) */
+            if (bytes_sent == -1) {
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
                 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
                 bytes_sent = TARGET_PAGE_SIZE;
             }
 
-            break;
+            /* if page is unmodified lets continue to the next */
+            if (bytes_sent != 0) {
+                break;
+            }
         }
 
         offset += TARGET_PAGE_SIZE;
@@ -294,6 +394,14 @@ static void sort_ram_list(void)
 static void migration_end(void)
 {
     memory_global_dirty_log_stop();
+
+    if (migrate_use_xbzrle()) {
+        cache_fini(XBZRLE.cache);
+        g_free(XBZRLE.cache);
+        g_free(XBZRLE.encoded_buf);
+        g_free(XBZRLE.decoded_buf);
+        XBZRLE.cache = NULL;
+    }
 }
 
 #define MAX_WAIT 50 /* ms, half buffered_file limit */
@@ -320,6 +428,17 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
         last_offset = 0;
         sort_ram_list();
 
+        if (migrate_use_xbzrle()) {
+            XBZRLE.cache = cache_init(migrate_xbzrle_cache_size() /
+                                      TARGET_PAGE_SIZE,
+                                      TARGET_PAGE_SIZE);
+            if (!XBZRLE.cache) {
+                DPRINTF("Error creating cache\n");
+                return -1;
+            }
+            XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
+        }
+
         /* Make sure all dirty bits are set */
         QLIST_FOREACH(block, &ram_list.blocks, next) {
             for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
@@ -348,7 +467,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
     while ((ret = qemu_file_rate_limit(f)) == 0) {
         int bytes_sent;
 
-        bytes_sent = ram_save_block(f);
+        bytes_sent = ram_save_block(f, stage);
         /* bytes_sent 0 represent unchanged page,
            bytes_sent -1 represent no more blocks*/
         if (bytes_sent > 0) {
@@ -390,7 +509,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
         int bytes_sent;
 
         /* flush all remaining blocks regardless of rate limiting */
-        while ((bytes_sent = ram_save_block(f)) != -1) {
+        while ((bytes_sent = ram_save_block(f, stage)) != -1) {
             bytes_transferred += bytes_sent;
         }
         migration_end();
@@ -410,6 +529,49 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
     return 0;
 }
 
+static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
+{
+    int ret, rc = 0;
+    XBZRLEHeader hdr = {
+        .xh_len = 0,
+        .xh_flags = 0,
+    };
+
+    if (!XBZRLE.decoded_buf) {
+        XBZRLE.decoded_buf = g_malloc(TARGET_PAGE_SIZE);
+    }
+
+    /* extract RLE header */
+    hdr.xh_flags = qemu_get_byte(f);
+    hdr.xh_len = qemu_get_be16(f);
+
+    if (!(hdr.xh_flags & ENCODING_FLAG_XBZRLE)) {
+        fprintf(stderr, "Failed to load XBZRLE page - wrong compression!\n");
+        return -1;
+    }
+
+    if (hdr.xh_len > TARGET_PAGE_SIZE) {
+        fprintf(stderr, "Failed to load XBZRLE page - len overflow!\n");
+        return -1;
+    }
+    /* load data and decode */
+    qemu_get_buffer(f, XBZRLE.decoded_buf, hdr.xh_len);
+
+    /* decode RLE */
+    ret = xbzrle_decode_buffer(XBZRLE.decoded_buf, hdr.xh_len, host,
+                               TARGET_PAGE_SIZE);
+    if (ret == -1) {
+        fprintf(stderr, "Failed to load XBZRLE page - decode error!\n");
+        rc = -1;
+    } else  if (ret > TARGET_PAGE_SIZE) {
+        fprintf(stderr, "Failed to load XBZRLE page - size %d exceeds %d!\n",
+                ret, TARGET_PAGE_SIZE);
+        rc = -1;
+    }
+
+    return rc;
+}
+
 static inline void *host_from_stream_offset(QEMUFile *f,
                                             ram_addr_t offset,
                                             int flags)
@@ -523,6 +685,19 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
 
             qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
+        } else if (flags & RAM_SAVE_FLAG_XBZRLE) {
+            if (!migrate_use_xbzrle()) {
+                return -EINVAL;
+            }
+            void *host = host_from_stream_offset(f, addr, flags);
+            if (!host) {
+                return -EINVAL;
+            }
+
+            if (load_xbzrle(f, addr, host) < 0) {
+                ret = -EINVAL;
+                goto done;
+            }
         }
         error = qemu_file_get_error(f);
         if (error) {
migration.c +24 -0
index fd004d7..2525b18 100644
@@ -43,6 +43,9 @@ enum {
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
 
+/* Migration XBZRLE cache size */
+#define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
+
 static NotifierList migration_state_notifiers =
     NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
 
@@ -55,6 +58,7 @@ static MigrationState *migrate_get_current(void)
     static MigrationState current_migration = {
         .state = MIG_STATE_SETUP,
         .bandwidth_limit = MAX_THROTTLE,
+        .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE,
     };
 
     return &current_migration;
@@ -439,6 +443,7 @@ static MigrationState *migrate_init(const MigrationParams *params)
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
     bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+    int64_t xbzrle_cache_size = s->xbzrle_cache_size;
 
     memcpy(enabled_capabilities, s->enabled_capabilities,
            sizeof(enabled_capabilities));
@@ -448,6 +453,7 @@ static MigrationState *migrate_init(const MigrationParams *params)
     s->params = *params;
     memcpy(s->enabled_capabilities, enabled_capabilities,
            sizeof(enabled_capabilities));
+    s->xbzrle_cache_size = xbzrle_cache_size;
 
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);
@@ -546,3 +552,21 @@ void qmp_migrate_set_downtime(double value, Error **errp)
     value = MAX(0, MIN(UINT64_MAX, value));
     max_downtime = (uint64_t)value;
 }
+
+int migrate_use_xbzrle(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE];
+}
+
+int64_t migrate_xbzrle_cache_size(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->xbzrle_cache_size;
+}
migration.h +4 -0
index c46af82..9b61e70 100644
@@ -40,6 +40,7 @@ struct MigrationState
     MigrationParams params;
     int64_t total_time;
     bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+    int64_t xbzrle_cache_size;
 };
 
 void process_incoming_migration(QEMUFile *f);
@@ -104,4 +105,7 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
                          uint8_t *dst, int dlen);
 int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);
 
+int migrate_use_xbzrle(void);
+int64_t migrate_xbzrle_cache_size(void);
+
 #endif
Signature · 1 line
1.7.7.6
#12 lore raw

Re: [Qemu-devel] [PATCH v15 7/9] Add XBZRLE to ram_save_block and ram_save_live

Quoted 14 lines · Orit Wasserman

In the outgoing migration check to see if the page is cached and changed than send compressed page by using save_xbrle_page function. In the incoming migration check to see if RAM_SAVE_FLAG_XBRLE is set and decompress the page (by using load_xbrle function).

---

arch_init.c +3 -0
+static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
+                            ram_addr_t current_addr, RAMBlock *block,
+                            ram_addr_t offset, int cont, int stage)

arch_init.c static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset, · line 221

Quoted 10 lines
arch_init.c +10 -0
+{
+    int encoded_len = 0, bytes_sent = -1, ret = -1;
+    XBZRLEHeader hdr = {
+        .xh_len = 0,
+        .xh_flags = 0,
+    };
+    uint8_t *prev_cached_page;
+
+    /* Stage 1 cache the page and exit.
+       Stage 2 check to see if page is cached , if not cache the page.

No space before comma in English comments:

s/ ,/,/

arch_init.c static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset, · line 237

Quoted 6 lines
arch_init.c +6 -0
+    /* XBZRLE encoding (if there is no overflow) */
+    encoded_len = xbzrle_encode_buffer(prev_cached_page, current_data,
+                                       TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
+                                       TARGET_PAGE_SIZE);
+    if (encoded_len == 0) {
+        DPRINTF("Unmodifed page skipping\n");

s/Unmodifed/Unmodified/

I mentioned in my v13 review changing this to:

s/Unmodifed page skipping/Skipping unmodified page/

it looks like you didn't pick up my v13 comments yet (and my fault for not complaining at v14). As a result, I stopped reviewing here.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#13 lore raw

Re: [Qemu-devel] [PATCH v15 7/9] Add XBZRLE to ram_save_block and ram_save_live

Quoted 37 lines · Eric Blake
Quoted 14 lines · Orit Wasserman

In the outgoing migration check to see if the page is cached and changed than send compressed page by using save_xbrle_page function. In the incoming migration check to see if RAM_SAVE_FLAG_XBRLE is set and decompress the page (by using load_xbrle function).

---

arch_init.c +3 -0
+static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
+                            ram_addr_t current_addr, RAMBlock *block,
+                            ram_addr_t offset, int cont, int stage)

arch_init.c static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset, · line 221

Quoted 10 lines
arch_init.c +10 -0
+{
+    int encoded_len = 0, bytes_sent = -1, ret = -1;
+    XBZRLEHeader hdr = {
+        .xh_len = 0,
+        .xh_flags = 0,
+    };
+    uint8_t *prev_cached_page;
+
+    /* Stage 1 cache the page and exit.
+       Stage 2 check to see if page is cached , if not cache the page.

No space before comma in English comments:

s/ ,/,/

arch_init.c static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset, · line 237

Quoted 6 lines
arch_init.c +6 -0
+    /* XBZRLE encoding (if there is no overflow) */
+    encoded_len = xbzrle_encode_buffer(prev_cached_page, current_data,
+                                       TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
+                                       TARGET_PAGE_SIZE);
+    if (encoded_len == 0) {
+        DPRINTF("Unmodifed page skipping\n");
Quoted 9 lines

s/Unmodifed/Unmodified/

I mentioned in my v13 review changing this to:

s/Unmodifed page skipping/Skipping unmodified page/

it looks like you didn't pick up my v13 comments yet (and my fault for not complaining at v14). As a result, I stopped reviewing here.

I'm really sorry I missed this, I will fix it for next version

Thanks,
Orit

#14 lore raw

PATCH v15 8/9 Add set_cachesize command

In reply to Orit Wasserman

Change XBZRLE cache size in bytes (the size should be a power of 2). If XBZRLE cache size is too small there will be many cache miss.

---
 arch_init.c      |   10 ++++++++++
 hmp-commands.hx  |   19 +++++++++++++++++++
 hmp.c            |   13 +++++++++++++
 hmp.h            |    1 +
 migration.c      |   17 ++++++++++++++++-
 migration.h      |    2 ++
 qapi-schema.json |   16 ++++++++++++++++
 qmp-commands.hx  |   23 +++++++++++++++++++++++
 8 files changed, 100 insertions(+), 1 deletions(-)
arch_init.c +10 -0
index 7b65551..da7a630 100644
@@ -192,6 +192,16 @@ static struct {
     .cache = NULL,
 };
 
+
+int64_t xbzrle_cache_resize(int64_t new_size)
+{
+    if (XBZRLE.cache != NULL) {
+        return cache_resize(XBZRLE.cache, new_size / TARGET_PAGE_SIZE) *
+            TARGET_PAGE_SIZE;
+    }
+    return pow2floor(new_size);
+}
+
 static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
         int cont, int flag)
 {
hmp-commands.hx +19 -0
index 9245bef..8864a15 100644
@@ -829,6 +829,25 @@ STEXI
 @item migrate_cancel
 @findex migrate_cancel
 Cancel the current VM migration.
+
+ETEXI
+
+    {
+        .name       = "migrate_set_cachesize",
+        .args_type  = "value:o",
+        .params     = "value",
+        .help       = "set cache size (in bytes) for XBZRLE migrations,"
+		      "the cache size will be rounded down to the nearest "
+                      "power of 2.\n"
+		      "The cache size effects the number of cache misses."
+		      "In case of a high cache miss ratio you need to increase the cache size",
+        .mhandler.cmd = hmp_migrate_set_cachesize,
+    },
+
+STEXI
+@item migrate_set_cachesize @var{value}
+@findex migrate_set_cache
+Set cache size to @var{value} (in bytes) for xbzrle migrations.
 ETEXI
 
     {
hmp.c +13 -0
index b0440e6..5833e1c 100644
@@ -758,6 +758,19 @@ void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_downtime(value, NULL);
 }
 
+void hmp_migrate_set_cachesize(Monitor *mon, const QDict *qdict)
+{
+    int64_t value = qdict_get_int(qdict, "value");
+    Error *err = NULL;
+
+    qmp_migrate_set_cachesize(value, &err);
+    if (err) {
+        monitor_printf(mon, "%s\n", error_get_pretty(err));
+        error_free(err);
+        return;
+    }
+}
+
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
 {
     int64_t value = qdict_get_int(qdict, "value");
hmp.h +1 -0
index 09ba198..7c5117d 100644
@@ -53,6 +53,7 @@ void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_cachesize(Monitor *mon, const QDict *qdict);
 void hmp_set_password(Monitor *mon, const QDict *qdict);
 void hmp_expire_password(Monitor *mon, const QDict *qdict);
 void hmp_eject(Monitor *mon, const QDict *qdict);
migration.c +16 -1
index 2525b18..9df6fc5 100644
@@ -22,6 +22,7 @@
 #include "qemu_socket.h"
 #include "block-migration.h"
 #include "qmp-commands.h"
+#include <math.h>
 
 //#define DEBUG_MIGRATION
 
@@ -43,7 +44,7 @@ enum {
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
 
-/* Migration XBZRLE cache size */
+/* Migration XBZRLE default cache size */
 #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
 
 static NotifierList migration_state_notifiers =
@@ -533,6 +534,20 @@ void qmp_migrate_cancel(Error **errp)
     migrate_fd_cancel(migrate_get_current());
 }
 
+void qmp_migrate_set_cachesize(int64_t value, Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+
+    /* Check for truncation */
+    if (value != (size_t)value) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
+                  "exceeding address space");
+        return;
+    }
+
+    s->xbzrle_cache_size = xbzrle_cache_resize(value);
+}
+
 void qmp_migrate_set_speed(int64_t value, Error **errp)
 {
     MigrationState *s;
migration.h +2 -0
index 9b61e70..a73a34a 100644
@@ -108,4 +108,6 @@ int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);
 int migrate_use_xbzrle(void);
 int64_t migrate_xbzrle_cache_size(void);
 
+int64_t xbzrle_cache_resize(int64_t new_size);
+
 #endif
qapi-schema.json +16 -0
index a8408fd..c13577d 100644
@@ -1390,6 +1390,22 @@
 { 'command': 'migrate_set_speed', 'data': {'value': 'int'} }
 
 ##
+# @migrate_set_cachesize
+#
+# Set XBZRLE cache size
+#
+# @value: cache size in bytes
+#
+# The size will be rounded down to the nearest power of 2.
+# The cache size can be modified before and during ongoing migration
+#
+# Returns: nothing on success
+#
+# Since: 1.2
+##
+{ 'command': 'migrate_set_cachesize', 'data': {'value': 'int'} }
+
+##
 # @ObjectPropertyInfo:
 #
 # @name: the name of the property
qmp-commands.hx +23 -0
index 3ee6e00..3ae46dc 100644
@@ -520,6 +520,29 @@ Example:
 <- { "return": {} }
 
 EQMP
+{
+        .name       = "migrate_set_cachesize",
+        .args_type  = "value:o",
+        .mhandler.cmd_new = qmp_marshal_input_migrate_set_cachesize,
+    },
+
+SQMP
+migrate_set_cachesize
+---------------------
+
+Set cache size to be used by XBZRLE migration, the cache size will be round down
+to the nearset power of 2
+
+Arguments:
+
+- "value": cache size in bytes (json-int)
+
+Example:
+
+-> { "execute": "migrate_set_cachesize", "arguments": { "value": 536870912 } }
+<- { "return": {} }
+
+EQMP
 
     {
         .name       = "migrate_set_speed",
Signature · 1 line
1.7.7.6
#15 lore raw

Re: [Qemu-devel] [PATCH v15 8/9] Add set_cachesize command

Quoted 9 lines · Orit Wasserman

Change XBZRLE cache size in bytes (the size should be a power of 2). If XBZRLE cache size is too small there will be many cache miss.

---

hmp-commands.hx STEXI · line 843

Quoted 9 lines
hmp-commands.hx +9 -0
+    {
+        .name       = "migrate_set_cachesize",
+        .args_type  = "value:o",
+        .params     = "value",
+        .help       = "set cache size (in bytes) for XBZRLE migrations,"
+		      "the cache size will be rounded down to the nearest "
+                      "power of 2.\n"
+		      "The cache size effects the number of cache misses."
+		      "In case of a high cache miss ratio you need to increase the cache size",

Inconsistent indentation. Kill those TABs.

migration.c line 25

Quoted 6 lines

+++ b/migration.c

migration.c +1 -0
@@ -22,6 +22,7 @@
 #include "qemu_socket.h"
 #include "block-migration.h"
 #include "qmp-commands.h"
+#include <math.h>

Urgh. You STILL haven't killed this bogus include, even though I've been mentioning it since my v12 review. I'm really getting frustrated with how long this series is being dragged out.

migration.c enum { · line 47

Quoted 9 lines
migration.c +1 -1
 //#define DEBUG_MIGRATION
 
@@ -43,7 +44,7 @@ enum {
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
 
-/* Migration XBZRLE cache size */
+/* Migration XBZRLE default cache size */

Again from my v12 review, this hunk should be squashed into the patch that first introduces the comment.

qmp-commands.hx Example: · line 534

Quoted 5 lines
qmp-commands.hx +5 -0
+migrate_set_cachesize
+---------------------
+
+Set cache size to be used by XBZRLE migration, the cache size will be round down
+to the nearset power of 2

Another v12 review leftover:

s/nearset/nearest/

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#16 lore raw

Re: [Qemu-devel] [PATCH v15 8/9] Add set_cachesize command

Quoted 22 lines · Eric Blake
Quoted 9 lines · Orit Wasserman

Change XBZRLE cache size in bytes (the size should be a power of 2). If XBZRLE cache size is too small there will be many cache miss.

---

hmp-commands.hx STEXI · line 843

Quoted 9 lines
hmp-commands.hx +9 -0
+    {
+        .name       = "migrate_set_cachesize",
+        .args_type  = "value:o",
+        .params     = "value",
+        .help       = "set cache size (in bytes) for XBZRLE migrations,"
+		      "the cache size will be rounded down to the nearest "
+                      "power of 2.\n"
+		      "The cache size effects the number of cache misses."
+		      "In case of a high cache miss ratio you need to increase the cache size",

Inconsistent indentation. Kill those TABs.

Quoted 10 lines

migration.c line 25

Quoted 6 lines

+++ b/migration.c

migration.c +1 -0
@@ -22,6 +22,7 @@
 #include "qemu_socket.h"
 #include "block-migration.h"
 #include "qmp-commands.h"
+#include <math.h>

Urgh. You STILL haven't killed this bogus include, even though I've been mentioning it since my v12 review. I'm really getting frustrated with how long this series is being dragged out.

Again I'm really sorry I will be more careful next time

Thanks,
Orit

Quoted 24 lines

migration.c enum { · line 47

Quoted 10 lines
migration.c +1 -1
 //#define DEBUG_MIGRATION
 
@@ -43,7 +44,7 @@ enum {
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
 
-/* Migration XBZRLE cache size */
+/* Migration XBZRLE default cache size */

Again from my v12 review, this hunk should be squashed into the patch that first introduces the comment.

qmp-commands.hx Example: · line 534

Quoted 5 lines
qmp-commands.hx +5 -0
+migrate_set_cachesize
+---------------------
+
+Set cache size to be used by XBZRLE migration, the cache size will be round down
+to the nearset power of 2

Another v12 review leftover:

s/nearset/nearest/

#17 lore raw

PATCH v15 9/9 Add XBZRLE statistics

In reply to Orit Wasserman
---
 arch_init.c      |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 hmp.c            |   13 ++++++++++
 migration.c      |   49 ++++++++++++++++++++++++++++++++++++++
 migration.h      |    9 +++++++
 qapi-schema.json |   37 +++++++++++++++++++++++++----
 qmp-commands.hx  |   35 +++++++++++++++++++++++++++-
 6 files changed, 204 insertions(+), 7 deletions(-)
arch_init.c +67 -1
index da7a630..51db360 100644
@@ -202,8 +202,66 @@ int64_t xbzrle_cache_resize(int64_t new_size)
     return pow2floor(new_size);
 }
 
+/* accounting */
+typedef struct AccountingInfo {
+    uint64_t dup_pages;
+    uint64_t norm_pages;
+    uint64_t xbzrle_bytes;
+    uint64_t xbzrle_pages;
+    uint64_t xbzrle_cache_miss;
+    uint64_t iterations;
+    uint64_t xbzrle_overflows;
+} AccountingInfo;
+
+static AccountingInfo acct_info;
+
+static void acct_clear(void)
+{
+    memset(&acct_info, 0, sizeof(acct_info));
+}
+
+uint64_t dup_mig_bytes_transferred(void)
+{
+    return acct_info.dup_pages * TARGET_PAGE_SIZE;
+}
+
+uint64_t dup_mig_pages_transferred(void)
+{
+    return acct_info.dup_pages;
+}
+
+uint64_t norm_mig_bytes_transferred(void)
+{
+    return acct_info.norm_pages * TARGET_PAGE_SIZE;
+}
+
+uint64_t norm_mig_pages_transferred(void)
+{
+    return acct_info.norm_pages;
+}
+
+uint64_t xbzrle_mig_bytes_transferred(void)
+{
+    return acct_info.xbzrle_bytes;
+}
+
+uint64_t xbzrle_mig_pages_transferred(void)
+{
+    return acct_info.xbzrle_pages;
+}
+
+uint64_t xbzrle_mig_pages_cache_miss(void)
+{
+    return acct_info.xbzrle_cache_miss;
+}
+
+uint64_t xbzrle_mig_pages_overflow(void)
+{
+    return acct_info.xbzrle_overflows;
+}
+
 static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
-        int cont, int flag)
+                           int cont, int flag)
 {
         qemu_put_be64(f, offset | cont | flag);
         if (!cont) {
@@ -234,6 +292,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
     if (stage == 1 || !cache_is_cached(XBZRLE.cache, current_addr)) {
         cache_insert(XBZRLE.cache, current_addr,
                      g_memdup(current_data, TARGET_PAGE_SIZE));
+        acct_info.xbzrle_cache_miss++;
         return -1;
     }
 
@@ -248,6 +307,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
         return 0;
     } else if (encoded_len == -1) {
         DPRINTF("Overflow\n");
+        acct_info.xbzrle_overflows++;
         /* update data in the cache */
         memcpy(prev_cached_page, current_data, TARGET_PAGE_SIZE);
         return -1;
@@ -267,7 +327,9 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
     qemu_put_byte(f, hdr.xh_flags);
     qemu_put_be16(f, hdr.xh_len);
     qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
+    acct_info.xbzrle_pages++;
     bytes_sent = encoded_len + sizeof(hdr);
+    acct_info.xbzrle_bytes += bytes_sent;
 
     return bytes_sent;
 }
@@ -299,6 +361,7 @@ static int ram_save_block(QEMUFile *f, int stage)
             p = memory_region_get_ram_ptr(mr) + offset;
 
             if (is_dup_page(p)) {
+                acct_info.dup_pages++;
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
                 qemu_put_byte(f, *p);
                 bytes_sent = 1;
@@ -321,6 +384,7 @@ static int ram_save_block(QEMUFile *f, int stage)
                 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
                 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
                 bytes_sent = TARGET_PAGE_SIZE;
+                acct_info.norm_pages++;
             }
 
             /* if page is unmodified lets continue to the next */
@@ -447,6 +511,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
                 return -1;
             }
             XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
+            acct_clear();
         }
 
         /* Make sure all dirty bits are set */
@@ -482,6 +547,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
            bytes_sent -1 represent no more blocks*/
         if (bytes_sent > 0) {
             bytes_transferred += bytes_sent;
+            acct_info.iterations++;
         } else if (bytes_sent == -1) { /* no more blocks */
             break;
         }
hmp.c +13 -0
index 5833e1c..5c56f4a 100644
@@ -168,6 +168,19 @@ void hmp_info_migrate(Monitor *mon)
                        info->disk->total >> 10);
     }
 
+    if (info->has_cache) {
+        monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
+                       info->cache->cache_size);
+        monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
+                       info->cache->xbzrle_bytes >> 10);
+        monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
+                       info->cache->xbzrle_pages);
+        monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
+                       info->cache->xbzrle_cache_miss);
+        monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
+                       info->cache->xbzrle_overflow);
+    }
+
     qapi_free_MigrationInfo(info);
 }
 
migration.c +49 -0

73 lines not on this page · raw message

migration.h +9 -0
index a73a34a..67f4462 100644
@@ -84,6 +84,15 @@ uint64_t ram_bytes_remaining(void);
 uint64_t ram_bytes_transferred(void);
 uint64_t ram_bytes_total(void);
 
+uint64_t dup_mig_bytes_transferred(void);
+uint64_t dup_mig_pages_transferred(void);
+uint64_t norm_mig_bytes_transferred(void);
+uint64_t norm_mig_pages_transferred(void);
+uint64_t xbzrle_mig_bytes_transferred(void);
+uint64_t xbzrle_mig_pages_transferred(void);
+uint64_t xbzrle_mig_pages_overflow(void);
+uint64_t xbzrle_mig_pages_cache_miss(void);
+
 int ram_save_live(QEMUFile *f, int stage, void *opaque);
 int ram_load(QEMUFile *f, void *opaque, int version_id);
 
qapi-schema.json +32 -5
index c13577d..71b8dda 100644
@@ -264,11 +264,35 @@
 #        migration has ended, it returns the total migration
 #        time. (since 1.2)
 #
-# Since: 0.14.0.
+# @duplicate: #optional, number of duplicate pages
+#
+# @normal : #optional, number of normal pages
+#
+# Since: 0.14.0, 'duplicate' and 'normal' since 1.2
 ##
 { 'type': 'MigrationStats',
   'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' ,
-           'total_time': 'int' } }
+           'total_time': 'int', '*duplicate': 'int', '*normal': 'int' } }
+##
+# @CacheStats
+#
+# Detailed XBZRLE migration cache statistics
+#
+# @cache_size: XBZRLE cache size
+#
+# @xbzrle_bytes: amount of bytes already transferred to the target VM
+#
+# @xbzrle_pages: amount of pages transferred to the target VM
+#
+# @xbzrle_cache_miss: number of cache miss
+#
+# @xbzrle_overflow: number of overflows
+#
+# Since: 1.2
+##
+{ 'type': 'CacheStats',
+  'data': {'cache-size': 'int', 'xbzrle-bytes': 'int', 'xbzrle-pages': 'int',
+           'xbzrle-cache-miss': 'int', 'xbzrle-overflow': 'int' } }
 
 ##
 # @MigrationInfo
@@ -291,13 +315,16 @@
 # @capabilities: #optional a list describing all the migration capabilities
 #                state
 #
-# Since: 0.14.0, 'capabilities' since 1.2
+# @cache: #optional @MigrationStats containing detailed XBZRLE migration
+#         statistics
+#
+# Since: 0.14.0, 'capabilities' and 'cache' since 1.
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
            '*disk': 'MigrationStats',
-           '*capabilities': ['MigrationCapabilityInfo']} }
-
+           '*capabilities': ['MigrationCapabilityInfo'],
+           '*cache': 'CacheStats'} }
 ##
 # @query-migrate
 #
qmp-commands.hx +34 -1
index 3ae46dc..3296f80 100644
@@ -2093,6 +2093,8 @@ The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
+	 - "duplicate": number of duplicated pages (json-int)
+	 - "normal" : number of normal pages transferred (json-int)
 - "disk": only present if "status" is "active" and it is a block migration,
   it is a json-object with the following disk information (in bytes):
          - "transferred": amount transferred (json-int)
@@ -2100,10 +2102,17 @@ The main json-object contains the following:
          - "total": total (json-int)
 - "capabilities": migration capabilities state
          - "xbzrle" : XBZRLE state (json-bool)
+- "cache": only present if "status" and XBZRLE is active.
+  It is a json-object with the following XBZRLE information:
+         - "cache-size": XBZRLE cache size
+         - "xbzrle-bytes": total XBZRLE bytes transferred
+         - "xbzrle-pages": number of XBZRLE compressed pages
+         - "cache-miss": number of cache misses
+         - "overflow": number of XBZRLE overflows
+
 Examples:
 
 1. Before the first migration
-
 -> { "execute": "query-migrate" }
 <- { "return": {
         "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
@@ -2164,6 +2173,30 @@ Examples:
       }
    }
 
+5. Migration is being performed and XBZRLE is active:
+
+-> { "execute": "query-migrate" }
+<- {
+      "return":{
+         "status":"active",
+         "capabilities" : [ { "capability": "xbzrle", "state" : true } ],
+         "ram":{
+            "total":1057024,
+            "remaining":1053304,
+            "transferred":3720
+            "duplicate": 10,
+            "normal" : 3333
+         },
+         "cache":{
+            "cache-size": 1024
+            "xbzrle-transferred":20971520,
+            "xbzrle-pages":2444343,
+            "xbzrle-cache-miss":2244,
+            "xbzrle-overflow":34434
+         }
+      }
+   }
+
 EQMP
 
     {
Signature · 1 line
1.7.7.6
#18 lore raw

Re: [Qemu-devel] [PATCH v15 9/9] Add XBZRLE statistics

arch_init.c int64_t xbzrle_cache_resize(int64_t new_size) · line 206

Quoted 12 lines · Orit Wasserman

+++ b/arch_init.c

arch_init.c +2 -0
@@ -202,8 +202,66 @@ int64_t xbzrle_cache_resize(int64_t new_size)
     return pow2floor(new_size);
 }
 
+/* accounting */
+typedef struct AccountingInfo {

The comment didn't add any information. Either drop it, or give a comment that describes what the accounting is for:

/* accounting for migration statistics */

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 148

Quoted 7 lines
migration.c +7 -0
+        /* display xbzrle cache size */
+        if (migrate_use_xbzrle()) {
+            info->has_cache = true;
+            info->cache = g_malloc0(sizeof(*info->cache));
+            info->cache->cache_size = migrate_xbzrle_cache_size();
+            info->cache->xbzrle_bytes  = xbzrle_mig_bytes_transferred();
+            info->cache->xbzrle_pages  = xbzrle_mig_pages_transferred();

Why the two lines with two spaces before '='?

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 177

Quoted 6 lines
migration.c +2 -0
@@ -162,6 +173,8 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         info->ram->total = ram_bytes_total();
         info->ram->total_time = qemu_get_clock_ms(rt_clock)
             - s->total_time;
+        info->ram->duplicate = dup_mig_pages_transferred();
+        info->ram->normal  = norm_mig_pages_transferred();

And another two spaces before '='

Quoted 4 lines
migration.c +0 -0
         if (blk_mig_active()) {
             info->has_disk = true;

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 192

Quoted 10 lines
migration.c +7 -0
@@ -170,6 +183,16 @@ MigrationInfo *qmp_query_migrate(Error **errp)
             info->disk->remaining = blk_mig_bytes_remaining();
             info->disk->total = blk_mig_bytes_total();
         }
+
+        if (migrate_use_xbzrle()) {
+            info->has_cache = true;
+            info->cache = g_malloc0(sizeof(*info->cache));
+            info->cache->cache_size = migrate_xbzrle_cache_size();
+            info->cache->xbzrle_bytes  = xbzrle_mig_bytes_transferred();
+            info->cache->xbzrle_pages  = xbzrle_mig_pages_transferred();

and again

migration.c MigrationInfo *qmp_query_migrate(Error **errp) · line 148

Quoted 6 lines
migration.c +6 -0
+        if (migrate_use_xbzrle()) {
+            info->has_cache = true;
+            info->cache = g_malloc0(sizeof(*info->cache));
+            info->cache->cache_size = migrate_xbzrle_cache_size();
+            info->cache->xbzrle_bytes  = xbzrle_mig_bytes_transferred();
+            info->cache->xbzrle_pages  = xbzrle_mig_pages_transferred();

and again

qapi-schema.json line 321

Quoted 9 lines
qapi-schema.json +4 -1
@@ -291,13 +315,16 @@
 # @capabilities: #optional a list describing all the migration capabilities
 #                state
 #
-# Since: 0.14.0, 'capabilities' since 1.2
+# @cache: #optional @MigrationStats containing detailed XBZRLE migration
+#         statistics
+#
+# Since: 0.14.0, 'capabilities' and 'cache' since 1.

s/1.$/1.2/

qmp-commands.hx Examples: · line 2186

Quoted 11 lines
qmp-commands.hx +11 -0
+5. Migration is being performed and XBZRLE is active:
+
+-> { "execute": "query-migrate" }
+<- {
+      "return":{
+         "status":"active",
+         "capabilities" : [ { "capability": "xbzrle", "state" : true } ],
+         "ram":{
+            "total":1057024,
+            "remaining":1053304,
+            "transferred":3720

s/$/,/

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org