qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, jsnow@redhat.com, jcody@redhat.com,
	qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Fam Zheng <famz@redhat.com>, Juan Quintela <quintela@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 19/21] block: Make bdrv_is_allocated() byte-based
Date: Fri, 7 Jul 2017 11:25:11 +0200	[thread overview]
Message-ID: <20170707092511.GA5027@noname.redhat.com> (raw)
In-Reply-To: <2ab0a0d0-5db0-8e5f-38ea-58b90bd92f41@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3323 bytes --]

Am 07.07.2017 um 04:55 hat Eric Blake geschrieben:
> On 07/06/2017 11:02 AM, Kevin Wolf wrote:
> 
> >> +++ b/qemu-img.c
> >> @@ -3229,6 +3229,7 @@ static int img_rebase(int argc, char **argv)
> >>          int64_t new_backing_num_sectors = 0;
> >>          uint64_t sector;
> >>          int n;
> >> +        int64_t count;
> >>          float local_progress = 0;
> >>
> >>          buf_old = blk_blockalign(blk, IO_BUF_SIZE);
> >> @@ -3276,12 +3277,14 @@ static int img_rebase(int argc, char **argv)
> >>              }
> >>
> >>              /* If the cluster is allocated, we don't need to take action */
> >> -            ret = bdrv_is_allocated(bs, sector, n, &n);
> >> +            ret = bdrv_is_allocated(bs, sector << BDRV_SECTOR_BITS,
> >> +                                    n << BDRV_SECTOR_BITS, &count);
> >>              if (ret < 0) {
> >>                  error_report("error while reading image metadata: %s",
> >>                               strerror(-ret));
> >>                  goto out;
> >>              }
> >> +            n = DIV_ROUND_UP(count, BDRV_SECTOR_SIZE);
> >>              if (ret) {
> >>                  continue;
> >>              }
> > 
> > Same thing. Sectors that are half allocated and half free must be
> > considered completely allocated if the caller can't do byte alignment.
> > Just rounding up without looking at ret isn't correct.
> 
> In reality, qemu-img rebase should probably be rewritten to exploit
> bdrv_get_block_status() instead of the weaker bdrv_is_allocated(). Right
> now, it is manually calling buffer_is_zero() on every sector to learn
> what sectors are candidates for optimizing, rather than being able to
> exploit BDRV_BLOCK_ZERO where possible

Yes, that's true, but also unrelated. As soon as you convert
bdrv_get_block_status() to byte granularity, you get the same thing
again.

Actually, having another look at this code, the solution for this
specific case is to convert the whole loop (or even function) to byte
granularity. The bdrv_is_allocated() call was the only thing that
required sectors.

> (yes, we may STILL want to call buffer_is_zero() on BDRV_BLOCK_DATA
> when we are trying to squeeze out all parts of an image that can be
> compressed, but maybe that should be an option, just as GNU dd has
> options for creating as much sparseness as possible (slow, because it
> reads data) vs. preserving existing sparseness (faster, because it
> relies on hole detection but leaves explicit written zeroes as
> non-sparse).

I'd expect that typically buffer_is_zero() is only slow if it's also
effective. Most data blocks start with non-zero data in the first few
bytes, so that's really quick. And I'm sure that checking whether a
buffer is zero is faster than doing disk I/O for the same buffer, so the
case of actual zero buffers should benefit, too. The only problem is
with cases where the buffer starts with many zeros and then ends in some
real data. I'm not sure how common this is.

> I guess there's still lots of ground for improving qemu-img, so for
> THIS series, I'll just leave it at an assertion that things are
> sector-aligned.

Sounds okay. If you want, you can add another patch to convert the
function to bytes, or we can do it later on top.

Kevin

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2017-07-07  9:25 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-05 21:08 [Qemu-devel] [PATCH v4 00/21] make bdrv_is_allocated[_above] byte-based Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 01/21] blockjob: Track job ratelimits via bytes, not sectors Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 02/21] trace: Show blockjob actions " Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 03/21] stream: Switch stream_populate() to byte-based Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 04/21] stream: Drop reached_end for stream_complete() Eric Blake
2017-07-06  0:05   ` John Snow
2017-07-06 10:38   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 05/21] stream: Switch stream_run() to byte-based Eric Blake
2017-07-06 10:39   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 06/21] commit: Switch commit_populate() " Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 07/21] commit: Switch commit_run() " Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 08/21] mirror: Switch MirrorBlockJob " Eric Blake
2017-07-06  0:14   ` John Snow
2017-07-06 10:42   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 09/21] mirror: Switch mirror_do_zero_or_discard() " Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 10/21] mirror: Update signature of mirror_clip_sectors() Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 11/21] mirror: Switch mirror_cow_align() to byte-based Eric Blake
2017-07-06 11:16   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 12/21] mirror: Switch mirror_do_read() " Eric Blake
2017-07-06 13:30   ` Kevin Wolf
2017-07-06 14:25     ` Eric Blake
2017-07-06 14:55       ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 13/21] mirror: Switch mirror_iteration() " Eric Blake
2017-07-06 13:47   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 14/21] block: Drop unused bdrv_round_sectors_to_clusters() Eric Blake
2017-07-06 13:49   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 15/21] backup: Switch BackupBlockJob to byte-based Eric Blake
2017-07-06 13:59   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 16/21] backup: Switch block_backup.h " Eric Blake
2017-07-06 14:11   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 17/21] backup: Switch backup_do_cow() " Eric Blake
2017-07-06 14:36   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 18/21] backup: Switch backup_run() " Eric Blake
2017-07-06 14:43   ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 19/21] block: Make bdrv_is_allocated() byte-based Eric Blake
2017-07-06 16:02   ` Kevin Wolf
2017-07-06 16:24     ` Eric Blake
2017-07-07  2:55     ` Eric Blake
2017-07-07  9:25       ` Kevin Wolf [this message]
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 20/21] block: Minimize raw use of bds->total_sectors Eric Blake
2017-07-06  0:23   ` John Snow
2017-07-06 16:48   ` Kevin Wolf
2017-07-06 17:03     ` Eric Blake
2017-07-06 17:27       ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 21/21] block: Make bdrv_is_allocated_above() byte-based Eric Blake
2017-07-06 17:13   ` Kevin Wolf

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=20170707092511.GA5027@noname.redhat.com \
    --to=kwolf@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.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).