[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 31/34] qemu-img: use blk_co_pwrite_zeroes for zero se
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 31/34] qemu-img: use blk_co_pwrite_zeroes for zero sectors when compressed |
Date: |
Fri, 28 Apr 2017 22:33:39 +0200 |
From: Lidong Chen <address@hidden>
When the buffer is zero, blk_co_pwrite_zeroes is more effective than
blk_co_pwritev with BDRV_REQ_WRITE_COMPRESSED. This patch can reduce
the time for converting qcow2 images with lots of zero data.
Signed-off-by: Lidong Chen <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
qemu-img.c | 44 ++++++++++++++------------------------------
1 file changed, 14 insertions(+), 30 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 9b6e728..c719636 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1649,6 +1649,8 @@ static int coroutine_fn convert_co_write(ImgConvertState
*s, int64_t sector_num,
while (nb_sectors > 0) {
int n = nb_sectors;
+ BdrvRequestFlags flags = s->compressed ? BDRV_REQ_WRITE_COMPRESSED : 0;
+
switch (status) {
case BLK_BACKING_FILE:
/* If we have a backing file, leave clusters unallocated that are
@@ -1658,43 +1660,24 @@ static int coroutine_fn
convert_co_write(ImgConvertState *s, int64_t sector_num,
break;
case BLK_DATA:
- /* We must always write compressed clusters as a whole, so don't
- * try to find zeroed parts in the buffer. We can only save the
- * write if the buffer is completely zeroed and we're allowed to
- * keep the target sparse. */
- if (s->compressed) {
- if (s->has_zero_init && s->min_sparse &&
- buffer_is_zero(buf, n * BDRV_SECTOR_SIZE))
- {
- assert(!s->target_has_backing);
- break;
- }
-
- iov.iov_base = buf;
- iov.iov_len = n << BDRV_SECTOR_BITS;
- qemu_iovec_init_external(&qiov, &iov, 1);
-
- ret = blk_co_pwritev(s->target, sector_num << BDRV_SECTOR_BITS,
- n << BDRV_SECTOR_BITS, &qiov,
- BDRV_REQ_WRITE_COMPRESSED);
- if (ret < 0) {
- return ret;
- }
- break;
- }
-
- /* If there is real non-zero data or we're told to keep the target
- * fully allocated (-S 0), we must write it. Otherwise we can treat
- * it as zero sectors. */
+ /* If we're told to keep the target fully allocated (-S 0) or there
+ * is real non-zero data, we must write it. Otherwise we can treat
+ * it as zero sectors.
+ * Compressed clusters need to be written as a whole, so in that
+ * case we can only save the write if the buffer is completely
+ * zeroed. */
if (!s->min_sparse ||
- is_allocated_sectors_min(buf, n, &n, s->min_sparse))
+ (!s->compressed &&
+ is_allocated_sectors_min(buf, n, &n, s->min_sparse)) ||
+ (s->compressed &&
+ !buffer_is_zero(buf, n * BDRV_SECTOR_SIZE)))
{
iov.iov_base = buf;
iov.iov_len = n << BDRV_SECTOR_BITS;
qemu_iovec_init_external(&qiov, &iov, 1);
ret = blk_co_pwritev(s->target, sector_num << BDRV_SECTOR_BITS,
- n << BDRV_SECTOR_BITS, &qiov, 0);
+ n << BDRV_SECTOR_BITS, &qiov, flags);
if (ret < 0) {
return ret;
}
@@ -1704,6 +1687,7 @@ static int coroutine_fn convert_co_write(ImgConvertState
*s, int64_t sector_num,
case BLK_ZERO:
if (s->has_zero_init) {
+ assert(!s->target_has_backing);
break;
}
ret = blk_co_pwrite_zeroes(s->target,
--
1.8.3.1
- [Qemu-devel] [PULL 21/34] qemu-img/convert: Move bs_n > 1 && -B check down, (continued)
- [Qemu-devel] [PULL 21/34] qemu-img/convert: Move bs_n > 1 && -B check down, Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 23/34] block/vhdx: Make vhdx_create() always set errp, Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 07/34] qemu-iotests: Filter HMP readline escape characters, Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 27/34] qcow2: Allow discard of final unaligned cluster, Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 26/34] block: Add .bdrv_truncate() error messages, Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 28/34] block: fix obvious coding style mistakes in block_int.h, Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 25/34] block: Add errp to BD.bdrv_truncate(), Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 24/34] block: Add errp to b{lk,drv}_truncate(), Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 29/34] block: assert no image modification under BDRV_O_INACTIVE, Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 30/34] qemu-img: improve convert_iteration_sectors(), Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 31/34] qemu-img: use blk_co_pwrite_zeroes for zero sectors when compressed,
Kevin Wolf <=
- [Qemu-devel] [PULL 32/34] iotests: clarify help text, Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 33/34] iotests: fix exclusion option, Kevin Wolf, 2017/04/28
- [Qemu-devel] [PULL 34/34] progress: Show current progress on SIGINFO, Kevin Wolf, 2017/04/28