From: Kevin Wolf <kwolf@redhat.com>
To: jemmy858585@gmail.com
Cc: qemu-devel@nongnu.org, mreitz@redhat.com, qemu-block@nongnu.org,
Lidong Chen <lidongchen@tencent.com>
Subject: Re: [Qemu-devel] [PATCH] qemu-img: use blk_co_pwrite_zeroes for zero sectors when compressed
Date: Thu, 20 Apr 2017 12:00:45 +0200 [thread overview]
Message-ID: <20170420100045.GB4747@noname.redhat.com> (raw)
In-Reply-To: <1492677526-4739-1-git-send-email-lidongchen@tencent.com>
Am 20.04.2017 um 10:38 hat jemmy858585@gmail.com geschrieben:
> From: Lidong Chen <lidongchen@tencent.com>
>
> when the buffer is zero, blk_co_pwrite_zeroes is more effectively than
> blk_co_pwritev with BDRV_REQ_WRITE_COMPRESSED. this patch can reduces
> the time when converts the qcow2 image with lots of zero.
>
> Signed-off-by: Lidong Chen <lidongchen@tencent.com>
Good catch, using blk_co_pwrite_zeroes() makes sense even for compressed
images.
> diff --git a/qemu-img.c b/qemu-img.c
> index b220cf7..0256539 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -1675,13 +1675,20 @@ static int coroutine_fn convert_co_write(ImgConvertState *s, int64_t sector_num,
> * 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;
> + if (buffer_is_zero(buf, n * BDRV_SECTOR_SIZE)) {
> + if (s->has_zero_init && s->min_sparse) {
> + assert(!s->target_has_backing);
> + break;
> + } else {
> + ret = blk_co_pwrite_zeroes(s->target,
> + sector_num << BDRV_SECTOR_BITS,
> + n << BDRV_SECTOR_BITS, 0);
> + if (ret < 0) {
> + return ret;
> + }
> + break;
> + }
> }
If s->min_sparse == 0, we may neither skip the write not use
blk_co_pwrite_zeroes(), because this requires actual full allocation
with explicit zero sectors.
Of course, if you fix this, what you end up with here is a duplicate of
the code path for non-compressed images. The remaining difference seems
to be the BDRV_REQ_WRITE_COMPRESSED flag and buffer_is_zero() vs.
is_allocated_sectors_min() (because uncompressed clusters can be written
partially, but compressed clusters can't).
So I suppose that instead of just fixing the above bug, we could actually
mostly unify the two code paths, if you want to have a try at it.
Kevin
next prev parent reply other threads:[~2017-04-20 10:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-20 8:38 [Qemu-devel] [PATCH] qemu-img: use blk_co_pwrite_zeroes for zero sectors when compressed jemmy858585
2017-04-20 8:52 ` 858585 jemmy
2017-04-20 10:00 ` Kevin Wolf [this message]
2017-04-21 2:58 ` 858585 jemmy
2017-04-21 5:37 ` 858585 jemmy
2017-04-23 12:53 ` 858585 jemmy
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=20170420100045.GB4747@noname.redhat.com \
--to=kwolf@redhat.com \
--cc=jemmy858585@gmail.com \
--cc=lidongchen@tencent.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).