6e7d01
From eea45924903f03dc6d8f20576be0a4a84d5acce4 Mon Sep 17 00:00:00 2001
6e7d01
From: Kevin Wolf <kwolf@redhat.com>
6e7d01
Date: Wed, 10 Feb 2021 10:16:11 -0500
6e7d01
Subject: [PATCH 4/5] qemu-img convert: Don't pre-zero images
6e7d01
6e7d01
RH-Author: Kevin Wolf <kwolf@redhat.com>
6e7d01
Message-id: <20210210101611.137928-2-kwolf@redhat.com>
6e7d01
Patchwork-id: 101030
6e7d01
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 1/1] qemu-img convert: Don't pre-zero images
6e7d01
Bugzilla: 1855250
6e7d01
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
6e7d01
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
6e7d01
RH-Acked-by: Max Reitz <mreitz@redhat.com>
6e7d01
6e7d01
Since commit 5a37b60a61c, qemu-img create will pre-zero the target image
6e7d01
if it isn't already zero-initialised (most importantly, for host block
6e7d01
devices, but also iscsi etc.), so that writing explicit zeros wouldn't
6e7d01
be necessary later.
6e7d01
6e7d01
This could speed up the operation significantly, in particular when the
6e7d01
source image file was only sparsely populated. However, it also means
6e7d01
that some block are written twice: Once when pre-zeroing them, and then
6e7d01
when they are overwritten with actual data. On a full image, the
6e7d01
pre-zeroing is wasted work because everything will be overwritten.
6e7d01
6e7d01
In practice, write_zeroes typically turns out faster than writing
6e7d01
explicit zero buffers, but slow enough that first zeroing everything and
6e7d01
then overwriting parts can be a significant net loss.
6e7d01
6e7d01
Meanwhile, qemu-img convert was rewritten in 690c7301600 and zero blocks
6e7d01
are now written to the target using bdrv_co_pwrite_zeroes() if the
6e7d01
target could be pre-zeroed. This way we already make use of the faster
6e7d01
write_zeroes operation, but avoid writing any blocks twice.
6e7d01
6e7d01
Remove the pre-zeroing because these days this former optimisation has
6e7d01
actually turned into a pessimisation in the common case.
6e7d01
6e7d01
Reported-by: Nir Soffer <nsoffer@redhat.com>
6e7d01
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6e7d01
Message-Id: <20200622151203.35624-1-kwolf@redhat.com>
6e7d01
Tested-by:  Nir Soffer <nsoffer@redhat.com>
6e7d01
Reviewed-by: Eric Blake <eblake@redhat.com>
6e7d01
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6e7d01
(cherry picked from commit edafc70c0c8510862f2f213a3acf7067113bcd08)
6e7d01
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6e7d01
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
6e7d01
---
6e7d01
 qemu-img.c | 9 ---------
6e7d01
 1 file changed, 9 deletions(-)
6e7d01
6e7d01
diff --git a/qemu-img.c b/qemu-img.c
6e7d01
index a27ad70851..b10dc5129b 100644
6e7d01
--- a/qemu-img.c
6e7d01
+++ b/qemu-img.c
6e7d01
@@ -2029,15 +2029,6 @@ static int convert_do_copy(ImgConvertState *s)
6e7d01
         s->has_zero_init = false;
6e7d01
     }
6e7d01
 
6e7d01
-    if (!s->has_zero_init && !s->target_has_backing &&
6e7d01
-        bdrv_can_write_zeroes_with_unmap(blk_bs(s->target)))
6e7d01
-    {
6e7d01
-        ret = blk_make_zero(s->target, BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK);
6e7d01
-        if (ret == 0) {
6e7d01
-            s->has_zero_init = true;
6e7d01
-        }
6e7d01
-    }
6e7d01
-
6e7d01
     /* Allocate buffer for copied data. For compressed images, only one cluster
6e7d01
      * can be copied at a time. */
6e7d01
     if (s->compressed) {
6e7d01
-- 
6e7d01
2.27.0
6e7d01