|
|
9ae3a8 |
From eb7381f07b22955557a2b7ea469c5bf5aa39281e Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Orit Wasserman <owasserm@redhat.com>
|
|
|
9ae3a8 |
Date: Wed, 9 Oct 2013 10:09:09 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 14/25] block-migration: efficiently encode zero blocks
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Orit Wasserman <owasserm@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1381313355-15641-5-git-send-email-owasserm@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 54800
|
|
|
9ae3a8 |
O-Subject: [RHEL7.0 qemu-kvm v2 04/10] block-migration: efficiently encode zero blocks
|
|
|
9ae3a8 |
Bugzilla: 921465
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Juan Quintela <quintela@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Peter Lieven <pl@kamp.de>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
this patch adds a efficient encoding for zero blocks by
|
|
|
9ae3a8 |
adding a new flag indicating a block is completely zero.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
additionally bdrv_write_zeros() is used at the destination
|
|
|
9ae3a8 |
to efficiently write these zeroes. depending on the implementation
|
|
|
9ae3a8 |
this avoids that the destination target gets fully provisioned.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Peter Lieven <pl@kamp.de>
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 323004a39d4d8d33c744a5b108f80bfe6402fca3)
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
include/migration/migration.h
|
|
|
9ae3a8 |
qapi-schema.json
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block-migration.c | 32 ++++++++++++++++++++++++++------
|
|
|
9ae3a8 |
include/migration/migration.h | 2 ++
|
|
|
9ae3a8 |
migration.c | 9 +++++++++
|
|
|
9ae3a8 |
qapi-schema.json | 8 +++++++-
|
|
|
9ae3a8 |
4 files changed, 44 insertions(+), 7 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block-migration.c | 32 ++++++++++++++++++++++++++------
|
|
|
9ae3a8 |
include/migration/migration.h | 2 ++
|
|
|
9ae3a8 |
migration.c | 9 +++++++++
|
|
|
9ae3a8 |
qapi-schema.json | 8 +++++++-
|
|
|
9ae3a8 |
4 files changed, 44 insertions(+), 7 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block-migration.c b/block-migration.c
|
|
|
9ae3a8 |
index 2fd7699..f803f20 100644
|
|
|
9ae3a8 |
--- a/block-migration.c
|
|
|
9ae3a8 |
+++ b/block-migration.c
|
|
|
9ae3a8 |
@@ -29,6 +29,7 @@
|
|
|
9ae3a8 |
#define BLK_MIG_FLAG_DEVICE_BLOCK 0x01
|
|
|
9ae3a8 |
#define BLK_MIG_FLAG_EOS 0x02
|
|
|
9ae3a8 |
#define BLK_MIG_FLAG_PROGRESS 0x04
|
|
|
9ae3a8 |
+#define BLK_MIG_FLAG_ZERO_BLOCK 0x08
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#define MAX_IS_ALLOCATED_SEARCH 65536
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -80,6 +81,7 @@ typedef struct BlkMigState {
|
|
|
9ae3a8 |
int shared_base;
|
|
|
9ae3a8 |
QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list;
|
|
|
9ae3a8 |
int64_t total_sector_sum;
|
|
|
9ae3a8 |
+ bool zero_blocks;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Protected by lock. */
|
|
|
9ae3a8 |
QSIMPLEQ_HEAD(blk_list, BlkMigBlock) blk_list;
|
|
|
9ae3a8 |
@@ -114,16 +116,30 @@ static void blk_mig_unlock(void)
|
|
|
9ae3a8 |
static void blk_send(QEMUFile *f, BlkMigBlock * blk)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int len;
|
|
|
9ae3a8 |
+ uint64_t flags = BLK_MIG_FLAG_DEVICE_BLOCK;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (block_mig_state.zero_blocks &&
|
|
|
9ae3a8 |
+ buffer_is_zero(blk->buf, BLOCK_SIZE)) {
|
|
|
9ae3a8 |
+ flags |= BLK_MIG_FLAG_ZERO_BLOCK;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* sector number and flags */
|
|
|
9ae3a8 |
qemu_put_be64(f, (blk->sector << BDRV_SECTOR_BITS)
|
|
|
9ae3a8 |
- | BLK_MIG_FLAG_DEVICE_BLOCK);
|
|
|
9ae3a8 |
+ | flags);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* device name */
|
|
|
9ae3a8 |
len = strlen(blk->bmds->bs->device_name);
|
|
|
9ae3a8 |
qemu_put_byte(f, len);
|
|
|
9ae3a8 |
qemu_put_buffer(f, (uint8_t *)blk->bmds->bs->device_name, len);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ /* if a block is zero we need to flush here since the network
|
|
|
9ae3a8 |
+ * bandwidth is now a lot higher than the storage device bandwidth.
|
|
|
9ae3a8 |
+ * thus if we queue zero blocks we slow down the migration */
|
|
|
9ae3a8 |
+ if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
|
|
|
9ae3a8 |
+ qemu_fflush(f);
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
qemu_put_buffer(f, blk->buf, BLOCK_SIZE);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -344,6 +360,7 @@ static void init_blk_migration(QEMUFile *f)
|
|
|
9ae3a8 |
block_mig_state.total_sector_sum = 0;
|
|
|
9ae3a8 |
block_mig_state.prev_progress = -1;
|
|
|
9ae3a8 |
block_mig_state.bulk_completed = 0;
|
|
|
9ae3a8 |
+ block_mig_state.zero_blocks = migrate_zero_blocks();
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
bdrv_iterate(init_blk_migration_it, NULL);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -762,12 +779,15 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
|
|
|
9ae3a8 |
nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- buf = g_malloc(BLOCK_SIZE);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- qemu_get_buffer(f, buf, BLOCK_SIZE);
|
|
|
9ae3a8 |
- ret = bdrv_write(bs, addr, buf, nr_sectors);
|
|
|
9ae3a8 |
+ if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
|
|
|
9ae3a8 |
+ ret = bdrv_write_zeroes(bs, addr, nr_sectors);
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ buf = g_malloc(BLOCK_SIZE);
|
|
|
9ae3a8 |
+ qemu_get_buffer(f, buf, BLOCK_SIZE);
|
|
|
9ae3a8 |
+ ret = bdrv_write(bs, addr, buf, nr_sectors);
|
|
|
9ae3a8 |
+ g_free(buf);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- g_free(buf);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/include/migration/migration.h b/include/migration/migration.h
|
|
|
9ae3a8 |
index 1fc2666..f1519dd 100644
|
|
|
9ae3a8 |
--- a/include/migration/migration.h
|
|
|
9ae3a8 |
+++ b/include/migration/migration.h
|
|
|
9ae3a8 |
@@ -119,6 +119,8 @@ void migrate_add_blocker(Error *reason);
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
void migrate_del_blocker(Error *reason);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+bool migrate_zero_blocks(void);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
bool migrate_auto_converge(void);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
|
|
|
9ae3a8 |
diff --git a/migration.c b/migration.c
|
|
|
9ae3a8 |
index 177fc22..cc0e649 100644
|
|
|
9ae3a8 |
--- a/migration.c
|
|
|
9ae3a8 |
+++ b/migration.c
|
|
|
9ae3a8 |
@@ -483,6 +483,15 @@ bool migrate_auto_converge(void)
|
|
|
9ae3a8 |
return s->enabled_capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE];
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+bool migrate_zero_blocks(void)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ MigrationState *s;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ s = migrate_get_current();
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return s->enabled_capabilities[MIGRATION_CAPABILITY_ZERO_BLOCKS];
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
int migrate_use_xbzrle(void)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
MigrationState *s;
|
|
|
9ae3a8 |
diff --git a/qapi-schema.json b/qapi-schema.json
|
|
|
9ae3a8 |
index 3936337..a717fbf 100644
|
|
|
9ae3a8 |
--- a/qapi-schema.json
|
|
|
9ae3a8 |
+++ b/qapi-schema.json
|
|
|
9ae3a8 |
@@ -605,10 +605,16 @@
|
|
|
9ae3a8 |
# @auto-converge: If enabled, QEMU will automatically throttle down the guest
|
|
|
9ae3a8 |
# to speed up convergence of RAM migration. (since 1.6)
|
|
|
9ae3a8 |
#
|
|
|
9ae3a8 |
+# @zero-blocks: During storage migration encode blocks of zeroes efficiently. This
|
|
|
9ae3a8 |
+# essentially saves 1MB of zeroes per block on the wire. Enabling requires
|
|
|
9ae3a8 |
+# source and target VM to support this feature. To enable it is sufficient
|
|
|
9ae3a8 |
+# to enable the capability on the source VM. The feature is disabled by
|
|
|
9ae3a8 |
+# default. (since 1.6)
|
|
|
9ae3a8 |
+#
|
|
|
9ae3a8 |
# Since: 1.2
|
|
|
9ae3a8 |
##
|
|
|
9ae3a8 |
{ 'enum': 'MigrationCapability',
|
|
|
9ae3a8 |
- 'data': ['xbzrle', 'auto-converge'] }
|
|
|
9ae3a8 |
+ 'data': ['xbzrle', 'auto-converge', 'zero-blocks'] }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
##
|
|
|
9ae3a8 |
# @MigrationCapabilityStatus
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|