Skip to content

Commit edafc70

Browse files
committed
qemu-img convert: Don't pre-zero images
Since commit 5a37b60, qemu-img create will pre-zero the target image if it isn't already zero-initialised (most importantly, for host block devices, but also iscsi etc.), so that writing explicit zeros wouldn't be necessary later. This could speed up the operation significantly, in particular when the source image file was only sparsely populated. However, it also means that some block are written twice: Once when pre-zeroing them, and then when they are overwritten with actual data. On a full image, the pre-zeroing is wasted work because everything will be overwritten. In practice, write_zeroes typically turns out faster than writing explicit zero buffers, but slow enough that first zeroing everything and then overwriting parts can be a significant net loss. Meanwhile, qemu-img convert was rewritten in 690c730 and zero blocks are now written to the target using bdrv_co_pwrite_zeroes() if the target could be pre-zeroed. This way we already make use of the faster write_zeroes operation, but avoid writing any blocks twice. Remove the pre-zeroing because these days this former optimisation has actually turned into a pessimisation in the common case. Reported-by: Nir Soffer <[email protected]> Signed-off-by: Kevin Wolf <[email protected]> Message-Id: <[email protected]> Tested-by: Nir Soffer <[email protected]> Reviewed-by: Eric Blake <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 64f0ad8 commit edafc70

File tree

1 file changed

+0
-9
lines changed

1 file changed

+0
-9
lines changed

qemu-img.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,15 +2084,6 @@ static int convert_do_copy(ImgConvertState *s)
20842084
s->has_zero_init = bdrv_has_zero_init(blk_bs(s->target));
20852085
}
20862086

2087-
if (!s->has_zero_init && !s->target_has_backing &&
2088-
bdrv_can_write_zeroes_with_unmap(blk_bs(s->target)))
2089-
{
2090-
ret = blk_make_zero(s->target, BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK);
2091-
if (ret == 0) {
2092-
s->has_zero_init = true;
2093-
}
2094-
}
2095-
20962087
/* Allocate buffer for copied data. For compressed images, only one cluster
20972088
* can be copied at a time. */
20982089
if (s->compressed) {

0 commit comments

Comments
 (0)