All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: david.edmondson@oracle.com, Kevin Wolf <kwolf@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	qemu-block@nongnu.org, mreitz@redhat.com
Subject: Re: [PATCH 13/17] qcow2: Add new autoclear feature for all zero image
Date: Tue, 4 Feb 2020 16:29:57 +0300	[thread overview]
Message-ID: <9adc0ad8-8bb8-37f7-e35b-8f69bfafbfd8@virtuozzo.com> (raw)
In-Reply-To: <10684ac8-2d01-86f1-d383-3ea83e6450eb@redhat.com>

04.02.2020 16:12, Eric Blake wrote:
> On 2/3/20 11:45 AM, Vladimir Sementsov-Ogievskiy wrote:
>> 31.01.2020 20:44, Eric Blake wrote:
>>> With the recent introduction of BDRV_ZERO_OPEN, we can optimize
>>> various qemu-img operations if we know the destination starts life
>>> with all zero content.  For an image with no cluster allocations and
>>> no backing file, this was already trivial with BDRV_ZERO_CREATE; but
>>> for a fully preallocated image, it does not scale to crawl through the
>>> entire L1/L2 tree to see if every cluster is currently marked as a
>>> zero cluster.  But it is quite easy to add an autoclear bit to the
>>> qcow2 file itself: the bit will be set after newly creating an image
>>> or after qcow2_make_empty, and cleared on any other modification
>>> (including by an older qemu that doesn't recognize the bit).
>>>
>>> This patch documents the new bit, independently of implementing the
>>> places in code that should set it (which means that for bisection
>>> purposes, it is safer to still mask the bit out when opening an image
>>> with the bit set).
>>>
>>> A few iotests have updated output due to the larger number of named
>>> header features.
>>>
>>> Signed-off-by: Eric Blake <eblake@redhat.com>
>>>
>>> ---
>>> RFC: As defined in this patch, I defined the bit to be clear if any
>>> cluster defers to a backing file. But the block layer would handle
>>> things just fine if we instead allowed the bit to be set if all
>>> clusters allocated in this image are zero, even if there are other
>>> clusters not allocated.  Or maybe we want TWO bits: one if all
>>> clusters allocated here are known zero, and a second if we know that
>>> there are any clusters that defer to a backing image.
> 
>>> -                    Bits 2-63:  Reserved (set to 0)
>>> +                    Bit 2:      All zero image bit
>>> +                                If this bit is set, the entire image reads
>>> +                                as all zeroes. This can be useful for
>>> +                                detecting just-created images even when
>>> +                                clusters are preallocated, which in turn
>>> +                                can be used to optimize image copying.
>>> +
>>> +                                This bit should not be set if any cluster
>>> +                                in the image defers to a backing file.
>>
>> Hmm. The term "defers to a backing file" not defined in the spec. And, as I
>> understand, can't be defined by design. Backing file may be added/removed/changed
>> dynamically, and qcow2 driver will not know about it. So, the only way to
>> be sure that clusters are not defer to backing file is to make them
>> ZERO clusters (not UNALLOCATED). But this is inefficient, as we'll have to
>> allocated all L2 tables.
>>
>> So, I think better to define this flag as "all allocated clusters are zero".
> 
> That was precisely the topic of my RFC question.

Yes, and this is what I'm thinking about it :)  Looks like I worded it in
manner that I didn't see the RFC and just consider it as final patch,
sorry for that.

> 
> I _do_ think it is simpler to report that 'all clusters where content comes from _this_ image read as zero', leaving unallocated clusters as zero only if 1. there is no backing image, or 2. the backing image also reads as all zero (recursing as needed).  I'll spin v2 of these patches along those lines, although I'm hoping for more review on the rest of the series, first.

Still, I'm not sure that it make sense to consider backing at all. In my POV,
backing is up to the user. User may load backing file which is specified in
qcow2 header, but on the same time, user may chose some other backing file.
Backing file is "external" thing, so, may be better not rely on it.

> 
>>
>> Hmm interesting, in qcow2 spec "allocated" means allocated on disk and has
>> offset. So, ZERO cluster is actually unallocated cluster, with bit 0 of
>> L2 entry set to 1. On the other hand, qemu block layer considers ZERO
>> clusters as "allocated" (in POV of backing-chain).
> 
> I really want the definition to be 'any cluster whose contents come from this layer' (the qemu-io definition of allocated, not necessarily the qcow2 definition of allocated), which picks up BOTH types of qcow2 zero clusters (those preallocated but marked 0, where the contents of the allocated area are indeterminate but never read, and those unallocated but marked 0 which do not defer to the backing layer).  Whether or not the cluster is allocated is less important than whether the image reads as 0 at that cluster.
> 
> But I think that you are right that an alternative definition of 'all allocated clusters are zero' will give the same results when crawling through the backing chain to learn if the overall image reads as zero, and that's all the more that we can expect out of this bit.

Yes, it's equal, because unallocated clusters marked as ZERO are zero anyway.

> 
>>
>> So, if we define it as "all allocated clusters are zero", we are done:
>> other clusters are either unallocated and MAY refer to backing, so we
>> can say nothing about their read-as-zero status at the level of qcow2
>> spec, or unallocated with zero-bit set, which are normal ZERO clusters.
>>
>> So, on the level of qcow2 driver I think it's better consider only this
>> image. Still, we can implement generic bdrv_is_all_zeros, which will
>> check or layers (or at least, check that bs->backing is NULL).
> 
> The earlier parts of this series which renamed bdrv_has_zero_init() into bdrv_known_zeroes() does just that - it already handles recursion through the backing chain, and insists that an image is all zeroes with respect to BDRV_ZERO_OPEN only if all layers of the backing chain agree.
> 

Great. I'll look at other patches soon.


-- 
Best regards,
Vladimir


  reply	other threads:[~2020-02-04 13:31 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31 17:44 [PATCH 00/17] Improve qcow2 all-zero detection Eric Blake
2020-01-31 17:44 ` [PATCH 01/17] qcow2: Comment typo fixes Eric Blake
2020-02-04 14:12   ` Vladimir Sementsov-Ogievskiy
2020-02-09 19:34   ` Alberto Garcia
2020-01-31 17:44 ` [PATCH 02/17] qcow2: List autoclear bit names in header Eric Blake
2020-02-04 14:26   ` Vladimir Sementsov-Ogievskiy
2020-01-31 17:44 ` [PATCH 03/17] qcow2: Avoid feature name extension on small cluster size Eric Blake
2020-02-04 14:39   ` Vladimir Sementsov-Ogievskiy
2020-02-09 19:28   ` Alberto Garcia
2020-01-31 17:44 ` [PATCH 04/17] block: Improve documentation of .bdrv_has_zero_init Eric Blake
2020-02-04 15:03   ` Vladimir Sementsov-Ogievskiy
2020-02-04 15:16     ` Eric Blake
2020-01-31 17:44 ` [PATCH 05/17] block: Don't advertise zero_init_truncate with encryption Eric Blake
2020-02-10 18:12   ` Alberto Garcia
2020-01-31 17:44 ` [PATCH 06/17] block: Improve bdrv_has_zero_init_truncate with backing file Eric Blake
2020-02-10 18:13   ` Alberto Garcia
2020-01-31 17:44 ` [PATCH 07/17] gluster: Drop useless has_zero_init callback Eric Blake
2020-02-04 15:06   ` Vladimir Sementsov-Ogievskiy
2020-02-10 18:21   ` Alberto Garcia
2020-02-17  8:06   ` [GEDI] " Niels de Vos
2020-02-17 12:03     ` Eric Blake
2020-02-17 12:22       ` Eric Blake
2020-02-17 14:01       ` Niels de Vos
2020-01-31 17:44 ` [PATCH 08/17] sheepdog: Consistently set bdrv_has_zero_init_truncate Eric Blake
2020-02-04 15:09   ` Vladimir Sementsov-Ogievskiy
2020-01-31 17:44 ` [PATCH 09/17] block: Refactor bdrv_has_zero_init{,_truncate} Eric Blake
2020-02-04 15:35   ` Vladimir Sementsov-Ogievskiy
2020-02-04 15:49     ` Eric Blake
2020-02-04 16:07       ` Vladimir Sementsov-Ogievskiy
2020-02-04 17:42     ` Max Reitz
2020-02-04 17:51       ` Eric Blake
2020-02-05 16:43         ` Max Reitz
2020-02-05  7:51       ` Vladimir Sementsov-Ogievskiy
2020-02-05 14:07         ` Eric Blake
2020-02-05 14:25           ` Vladimir Sementsov-Ogievskiy
2020-02-05 14:36             ` Eric Blake
2020-02-05 17:55           ` Max Reitz
2020-02-04 17:53   ` Max Reitz
2020-02-04 19:03     ` Eric Blake
2020-02-05 17:22       ` Max Reitz
2020-02-05 18:39         ` Eric Blake
2020-02-06  9:18           ` Max Reitz
2020-01-31 17:44 ` [PATCH 10/17] block: Add new BDRV_ZERO_OPEN flag Eric Blake
2020-01-31 18:03   ` Eric Blake
2020-02-04 17:34   ` Max Reitz
2020-02-04 17:50     ` Eric Blake
2020-02-05  8:39       ` Vladimir Sementsov-Ogievskiy
2020-02-05 17:26       ` Max Reitz
2020-01-31 17:44 ` [PATCH 11/17] file-posix: Support BDRV_ZERO_OPEN Eric Blake
2020-01-31 17:44 ` [PATCH 12/17] gluster: " Eric Blake
2020-02-17  8:16   ` [GEDI] " Niels de Vos
2020-01-31 17:44 ` [PATCH 13/17] qcow2: Add new autoclear feature for all zero image Eric Blake
2020-02-03 17:45   ` Vladimir Sementsov-Ogievskiy
2020-02-04 13:12     ` Eric Blake
2020-02-04 13:29       ` Vladimir Sementsov-Ogievskiy [this message]
2020-01-31 17:44 ` [PATCH 14/17] qcow2: Expose all zero bit through .bdrv_known_zeroes Eric Blake
2020-01-31 17:44 ` [PATCH 15/17] qcow2: Implement all-zero autoclear bit Eric Blake
2020-01-31 17:44 ` [PATCH 16/17] iotests: Add new test for qcow2 all-zero bit Eric Blake
2020-01-31 17:44 ` [PATCH 17/17] qcow2: Let qemu-img check cover " Eric Blake
2020-02-04 17:32 ` [PATCH 00/17] Improve qcow2 all-zero detection Max Reitz
2020-02-04 18:53   ` Eric Blake
2020-02-05 17:04     ` Max Reitz
2020-02-05 19:21       ` Eric Blake
2020-02-06  9:12         ` Max Reitz
2020-02-05  9:04 ` Vladimir Sementsov-Ogievskiy
2020-02-05  9:25   ` Vladimir Sementsov-Ogievskiy
2020-02-05 14:26     ` Eric Blake
2020-02-05 14:47       ` Vladimir Sementsov-Ogievskiy
2020-02-05 15:14         ` Vladimir Sementsov-Ogievskiy
2020-02-05 17:58           ` Max Reitz
2020-02-05 14:22   ` Eric Blake
2020-02-05 14:43     ` Vladimir Sementsov-Ogievskiy
2020-02-05 14:58       ` Vladimir Sementsov-Ogievskiy

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=9adc0ad8-8bb8-37f7-e35b-8f69bfafbfd8@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=david.edmondson@oracle.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.