From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Lieven <pl@kamp.de>
Cc: Kevin Wolf <kwolf@redhat.com>,
ronniesahlberg@gmail.com, qemu-devel@nongnu.org,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 8/8] block-migration: efficiently encode zero blocks
Date: Mon, 24 Jun 2013 16:32:19 +0200 [thread overview]
Message-ID: <51C85873.2020205@redhat.com> (raw)
In-Reply-To: <1371934712-11714-9-git-send-email-pl@kamp.de>
Il 22/06/2013 22:58, Peter Lieven ha scritto:
> this patch adds a efficient encoding for zero blocks by
> adding a new flag indiciating a block is completly zero.
>
> additionally bdrv_write_zeros() is used at the destination
> to efficiently write these zeroes. if the driver supports
> it this avoids blindly allocating all sectors consumed by
> zero blocks effectively re-thinning the device.
>
> Signed-off-by: Peter Lieven <pl@kamp.de>
This is a bit ugly because it doesn't work with drive-mirror. Perhaps
we can add a write-zeroes opcode to NBD, too.
Paolo
> ---
> block-migration.c | 29 +++++++++++++++++++++++------
> include/migration/qemu-file.h | 1 +
> savevm.c | 2 +-
> 3 files changed, 25 insertions(+), 7 deletions(-)
>
> diff --git a/block-migration.c b/block-migration.c
> index 2fd7699..99b3757 100644
> --- a/block-migration.c
> +++ b/block-migration.c
> @@ -29,6 +29,7 @@
> #define BLK_MIG_FLAG_DEVICE_BLOCK 0x01
> #define BLK_MIG_FLAG_EOS 0x02
> #define BLK_MIG_FLAG_PROGRESS 0x04
> +#define BLK_MIG_FLAG_ZERO_BLOCK 0x08
>
> #define MAX_IS_ALLOCATED_SEARCH 65536
>
> @@ -114,16 +115,29 @@ static void blk_mig_unlock(void)
> static void blk_send(QEMUFile *f, BlkMigBlock * blk)
> {
> int len;
> + int flags = BLK_MIG_FLAG_DEVICE_BLOCK;
> +
> + if (buffer_is_zero(blk->buf, BLOCK_SIZE)) {
> + flags |= BLK_MIG_FLAG_ZERO_BLOCK;
> + }
>
> /* sector number and flags */
> qemu_put_be64(f, (blk->sector << BDRV_SECTOR_BITS)
> - | BLK_MIG_FLAG_DEVICE_BLOCK);
> + | flags);
>
> /* device name */
> len = strlen(blk->bmds->bs->device_name);
> qemu_put_byte(f, len);
> qemu_put_buffer(f, (uint8_t *)blk->bmds->bs->device_name, len);
>
> + /* if a block is zero we need to flush here since the network
> + * bandwidth is now a lot higher than the storage device bandwidth.
> + * thus if we queue zero blocks we slow down the migration */
> + if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
> + qemu_fflush(f);
> + return;
> + }
> +
> qemu_put_buffer(f, blk->buf, BLOCK_SIZE);
> }
>
> @@ -762,12 +776,15 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
> nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
> }
>
> - buf = g_malloc(BLOCK_SIZE);
> -
> - qemu_get_buffer(f, buf, BLOCK_SIZE);
> - ret = bdrv_write(bs, addr, buf, nr_sectors);
> + if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
> + ret = bdrv_write_zeroes(bs, addr, nr_sectors);
> + } else {
> + buf = g_malloc(BLOCK_SIZE);
> + qemu_get_buffer(f, buf, BLOCK_SIZE);
> + ret = bdrv_write(bs, addr, buf, nr_sectors);
> + g_free(buf);
> + }
>
> - g_free(buf);
> if (ret < 0) {
> return ret;
> }
> diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
> index 7519464..b73298d 100644
> --- a/include/migration/qemu-file.h
> +++ b/include/migration/qemu-file.h
> @@ -71,6 +71,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode);
> QEMUFile *qemu_fopen_socket(int fd, const char *mode);
> QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
> int qemu_get_fd(QEMUFile *f);
> +void qemu_fflush(QEMUFile *f);
> int qemu_fclose(QEMUFile *f);
> int64_t qemu_ftell(QEMUFile *f);
> void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
> diff --git a/savevm.c b/savevm.c
> index ff5ece6..4d12d92 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -610,7 +610,7 @@ static inline bool qemu_file_is_writable(QEMUFile *f)
> * If there is writev_buffer QEMUFileOps it uses it otherwise uses
> * put_buffer ops.
> */
> -static void qemu_fflush(QEMUFile *f)
> +void qemu_fflush(QEMUFile *f)
> {
> ssize_t ret = 0;
>
>
next prev parent reply other threads:[~2013-06-24 14:32 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-22 20:58 [Qemu-devel] [PATCH 0/8] iscsi/qemu-img/block-migration enhancements Peter Lieven
2013-06-22 20:58 ` [Qemu-devel] [PATCH 1/8] iscsi: add logical block provisioning information to iscsilun Peter Lieven
2013-06-24 14:35 ` Paolo Bonzini
2013-06-22 20:58 ` [Qemu-devel] [PATCH 2/8] iscsi: add bdrv_co_is_allocated Peter Lieven
2013-06-24 14:36 ` Paolo Bonzini
2013-06-22 20:58 ` [Qemu-devel] [PATCH 3/8] iscsi: add bdrv_co_write_zeroes Peter Lieven
2013-06-24 14:34 ` Paolo Bonzini
2013-06-24 16:31 ` Peter Lieven
2013-06-22 20:58 ` [Qemu-devel] [PATCH 4/8] block: add bdrv_write_zeroes() Peter Lieven
2013-06-22 20:58 ` [Qemu-devel] [PATCH 5/8] block/raw: add bdrv_co_write_zeroes Peter Lieven
2013-06-22 20:58 ` [Qemu-devel] [PATCH 6/8] qemu-img: use bdrv_write_zeroes to write zeroes Peter Lieven
2013-06-24 14:33 ` Paolo Bonzini
2013-06-24 16:17 ` Peter Lieven
2013-06-24 16:25 ` Paolo Bonzini
2013-06-24 16:33 ` Peter Lieven
2013-06-24 18:46 ` Peter Lieven
2013-06-22 20:58 ` [Qemu-devel] [PATCH 7/8] iscsi: assert that sectors are aligned to LUN blocksize Peter Lieven
2013-06-24 14:30 ` Paolo Bonzini
2013-06-24 16:10 ` Peter Lieven
2013-06-24 16:13 ` Paolo Bonzini
2013-06-24 16:24 ` Peter Lieven
2013-06-24 16:27 ` Paolo Bonzini
2013-06-24 16:36 ` Peter Lieven
2013-06-22 20:58 ` [Qemu-devel] [PATCH 8/8] block-migration: efficiently encode zero blocks Peter Lieven
2013-06-24 14:32 ` Paolo Bonzini [this message]
2013-06-24 16:14 ` Peter Lieven
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=51C85873.2020205@redhat.com \
--to=pbonzini@redhat.com \
--cc=kwolf@redhat.com \
--cc=pl@kamp.de \
--cc=qemu-devel@nongnu.org \
--cc=ronniesahlberg@gmail.com \
--cc=stefanha@redhat.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).