All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Max Reitz <mreitz@redhat.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, eblake@redhat.com,
	jsnow@redhat.com, famz@redhat.com, den@openvz.org,
	stefanha@redhat.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH 12/22] qcow2-bitmap: add IN_USE flag
Date: Wed, 26 Oct 2016 16:02:56 +0300	[thread overview]
Message-ID: <12721412-2a42-ba02-d818-7dd2848a4703@virtuozzo.com> (raw)
In-Reply-To: <8ddea3bf-67b2-a468-d024-04fb714a472b@virtuozzo.com>

26.10.2016 15:13, Vladimir Sementsov-Ogievskiy wrote:
> 26.10.2016 12:21, Vladimir Sementsov-Ogievskiy wrote:
>> 26.10.2016 12:04, Vladimir Sementsov-Ogievskiy wrote:
>>> 25.10.2016 13:53, Vladimir Sementsov-Ogievskiy wrote:
>>>> 24.10.2016 20:18, Max Reitz wrote:
>>>>> On 24.10.2016 19:08, Max Reitz wrote:
>>>>>> On 24.10.2016 13:35, Vladimir Sementsov-Ogievskiy wrote:
>>>>>>> 24.10.2016 13:32, Vladimir Sementsov-Ogievskiy пишет:
>>>>>>>> 21.10.2016 22:58, Max Reitz пишет:
>>>>>>>>> On 21.10.2016 17:34, Vladimir Sementsov-Ogievskiy wrote:
>>>>>>>>>> 07.10.2016 22:44, Max Reitz пишет:
>>>>>>>>>>> On 30.09.2016 12:53, Vladimir Sementsov-Ogievskiy wrote:
>>>>>>>>>>>> This flag means that the bitmap is now in use by the 
>>>>>>>>>>>> software or
>>>>>>>>>>>> was not
>>>>>>>>>>>> successfully saved. In any way, with this flag set the 
>>>>>>>>>>>> bitmap data
>>>>>>>>>>>> must
>>>>>>>>>>>> be considered inconsistent and should not be loaded.
>>>>>>>>>>>>
>>>>>>>>>>>> With current implementation this flag is never set, as we 
>>>>>>>>>>>> just remove
>>>>>>>>>>>> bitmaps from the image after loading. But it defined in 
>>>>>>>>>>>> qcow2 spec
>>>>>>>>>>>> and
>>>>>>>>>>>> must be handled. Also, it can be used in future, if async 
>>>>>>>>>>>> schemes of
>>>>>>>>>>>> bitmap loading/saving are implemented.
>>>>>>>>>>>>
>>>>>>>>>>>> We also remove in-use bitmaps from the image on open.
>>>>>>>>>>>>
>>>>>>>>>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy
>>>>>>>>>>>> <vsementsov@virtuozzo.com>
>>>>>>>>>>>> ---
>>>>>>>>>>>>     block/qcow2-bitmap.c | 17 ++++++++++++++++-
>>>>>>>>>>>>     1 file changed, 16 insertions(+), 1 deletion(-)
>>>>>>>>>>> Don't you want to make use of this flag? It would appear 
>>>>>>>>>>> useful to
>>>>>>>>>>> me if
>>>>>>>>>>> you just marked autoload bitmaps as in_use instead of 
>>>>>>>>>>> deleting them
>>>>>>>>>>> from
>>>>>>>>>>> the image when it's opened and then overwrite them when the 
>>>>>>>>>>> image is
>>>>>>>>>>> closed.
>>>>>>>>>> And what is the use of it?
>>>>>>>>> You don't need to free any bitmaps when opening the file, and 
>>>>>>>>> you don't
>>>>>>>>> need to allocate any new bitmap space when closing it.
>>>>>>>> As bitmaps are sparce in file, I need to allocate new space when
>>>>>>>> closing. Or free it...
>>>>>>>
>>>>>>> Is it a real problem to reallocate space in qcow2? If so, to 
>>>>>>> minimaze
>>>>>>> allocations, I will have to make a list of clusters of in_use 
>>>>>>> bitmaps on
>>>>>>> close, and then save current bitmaps to these clusters (and 
>>>>>>> allocated
>>>>>>> some additional clusters, or free extra clusters).
>>>>>> It's not a real problem, but it does take time, and I maintain 
>>>>>> that it's
>>>>>> time it doesn't need to take because you can just use the in_use 
>>>>>> flag.
>>>>>>
>>>>>> I wouldn't worry about reusing clusters of other bitmaps. Of 
>>>>>> course we
>>>>>> can do that later on in some optimization but not now.
>>>>>>
>>>>>> I just mean the basic case of some auto-loaded bitmap that is not 
>>>>>> being
>>>>>> deleted while the VM is running and is just saved back to the 
>>>>>> image file
>>>>>> once it is closed. I don't expect that users will always consume 
>>>>>> all of
>>>>>> the auto-loaded bitmaps while the VM is active...
>>>>>>
>>>>>>> Also, if I don't free them on open, I'll have to free them on 
>>>>>>> remove of
>>>>>>> bdrv dirty bitmap..
>>>>>> Yes, so? That takes time, but that is something the user will 
>>>>>> probably
>>>>>> expect. I wouldn't expect opening of the file to take that time.
>>>>>>
>>>>>> Overall, it doesn't matter time-wise whether you free the bitmap 
>>>>>> data
>>>>>> when opening the image file or when the dirty bitmap is actually 
>>>>>> deleted
>>>>>> by the user or when the image file is closed. Just setting the 
>>>>>> single
>>>>>> in_use flag for all of the auto-loaded bitmaps will basically not 
>>>>>> take
>>>>>> any time.
>>>>>>
>>>>>> On the other hand, as soon as just a single auto-loaded bitmap 
>>>>>> survives
>>>>>> a VM (or qemu-img) invocation, you will very, very likely safe at 
>>>>>> least
>>>>>> some time because writing the bitmap to the disk can reuse at 
>>>>>> least some
>>>>>> of the existing clusters.
>>>>> By the way, dealing with removal of bitmaps when they are deleted 
>>>>> by the
>>>>> user is also positive when it comes to migration or read-only 
>>>>> disks that
>>>>> are later reopened R/W: Currently, as far as I can see, you just keep
>>>>> the auto-load bitmaps in the image if the image is part of an 
>>>>> incoming
>>>>> migration or opened read-only, but then you continue under the
>>>>> assumption that they are removed from the image. That's not very 
>>>>> good.
>>>>
>>>> You are right, I need to handle reopening more carefully. In my 
>>>> way, I need to delete bitmaps when reopening R/W and in yours - set 
>>>> in_use bit.
>>>>
>>>>>
>>>>> If you delete the bitmaps only when the user asks you to, then you 
>>>>> can
>>>>> just return an error that the bitmap cannot be removed at this time
>>>>> because the image file is read-only or used in migration (and I don't
>>>>> think the latter can even happen when it's the user who has requested
>>>>> removal of the bitmap).
>>>>>
>>>>> Max
>>>>>
>>>>
>>>> Ok, I'll rewrite this way, using 'in_use' bit and trying to avoid 
>>>> allocate/free overhead.
>>>>
>>>>
>>>
>>> Trying to reuse clusters of in_use bitmaps (including contiguous 
>>> allocations for bitmap tables) will complicate things a lot.. We can 
>>> use extra clusters of one in_use bitmap to save another one, the 
>>> same is for bitmap tables. Extra clusters of old bitmap table (in 
>>> case of resize) can be used for saving other bitmap data, etc..
>>>
>>>
>>
>> A compromise strategy of reusing:
>>
>> 1. accumulate all data clusters of in_use bitmaps, which was loaded 
>> by this qcow2 instance (we will not touch other old in_use bitmaps) 
>> to free_clusters list
>> 2. for each persistent BdrvDirtyBitmap:
>>        If there is corresponding in_use bitmap in the image, and its 
>> table size == needed table size (there was no resizes), then let's 
>> reuse bitmap table.
>>        else, move old bitmap table clusters to free_clusters and 
>> allocate new table.
>> 3. for each persistent BdrvDirtyBitmap:
>>        For bitmap data clusters, take them from free_clusters list, 
>> and if it is empty - allocate new clusters.
>> 4. free extra clusters from free_clusters list if any.
>>
>>
>> This strategy is not optimal, but not bad I thing. Is it ok for you? 
>> (I'm not sure that this all is not premature optimization, and may be 
>> true way is to just free all old staff and reallocate it, as I do.)
>>
>>
>
> With something like this it is not trivial to maintain consistency in 
> qcow2 image in case of fail on reusing (we can get double-linked 
> clusters, or dead links in the image on disk).. Simple solution will 
> be to remove all in_use bitmaps from header extension, or reallocate 
> for them bitmap tables with all zeroes. So, finally:
>
> target: we want to reuse clusters of in_use bitmaps, which was loaded 
> by current qcow2 driver (let's call them our in_use bitmaps.
>
> sequence:
> 1. save bitmap directory in memory
> 2. remove our in_use bitmaps from bitmap directory in disk. from this 
> point, in case of fail we will finish with some leaking clusters and 
> no corruptions.
> 3. free_clusters list = all data clusters of our in_use bitmaps
> 4. for each our in_use bitmap: If table size is not appropriate move 
> bitmap table clusters to free_clusters

better is to free it, to not deceiveqcow2 allocator.. Can I allocate 
several clusters by alloc(size), then assume that I have (size + 
cluster_size - 1)/cluster_size clusters and that I can free these 
clusters separately?

> 5. save bitmaps, using free_clusters list for data clusters, old 
> existing bitmap tables and allocating new space when needed.
> 6. free extra clusters from free_clusters list if any
>
>


-- 
Best regards,
Vladimir

  reply	other threads:[~2016-10-26 13:03 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-30 10:53 [Qemu-devel] [PATCH v7 00/22] qcow2: persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 01/22] hbitmap: improve dirty iter Vladimir Sementsov-Ogievskiy
2016-10-01 13:52   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 02/22] tests: add hbitmap iter test Vladimir Sementsov-Ogievskiy
2016-10-01 14:02   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 03/22] block: fix bdrv_dirty_bitmap_granularity signature Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 04/22] block/dirty-bitmap: add deserialize_ones func Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 05/22] qcow2-bitmap: structs and consts Vladimir Sementsov-Ogievskiy
2016-10-01 14:34   ` Max Reitz
2016-10-01 14:56     ` Max Reitz
2016-10-07 13:11     ` Vladimir Sementsov-Ogievskiy
2016-10-11 11:50     ` Vladimir Sementsov-Ogievskiy
2016-10-12 18:20       ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 06/22] qcow2: add dirty bitmaps extension Vladimir Sementsov-Ogievskiy
2016-10-01 14:46   ` Max Reitz
2016-10-11 12:09     ` Vladimir Sementsov-Ogievskiy
2016-10-12 18:21       ` Max Reitz
2016-10-13 12:18         ` Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 07/22] qcow2-bitmap: introduce auto-loading bitmaps Vladimir Sementsov-Ogievskiy
2016-10-01 16:26   ` Max Reitz
2016-10-14 18:44     ` Vladimir Sementsov-Ogievskiy
2016-10-15 17:03       ` Max Reitz
2016-10-15 17:22         ` Vladimir Sementsov-Ogievskiy
2016-10-20 12:22     ` Vladimir Sementsov-Ogievskiy
2016-10-21 19:49       ` Max Reitz
2016-10-07 19:25   ` Max Reitz
2016-10-21 11:59     ` Vladimir Sementsov-Ogievskiy
2016-10-21 19:56       ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 08/22] block/dirty-bitmap: add autoload field to BdrvDirtyBitmap Vladimir Sementsov-Ogievskiy
2016-10-07 17:05   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 09/22] block: introduce persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2016-10-07 17:54   ` Max Reitz
2016-10-11 13:11     ` Vladimir Sementsov-Ogievskiy
2016-10-12 18:24       ` Max Reitz
2016-10-07 19:28   ` Max Reitz
2016-10-12 11:38     ` Vladimir Sementsov-Ogievskiy
2016-10-12 12:30       ` Vladimir Sementsov-Ogievskiy
2016-10-12 18:25         ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 10/22] block/dirty-bitmap: add bdrv_dirty_bitmap_next() Vladimir Sementsov-Ogievskiy
2016-10-07 18:11   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 11/22] qcow2-bitmap: add qcow2_store_persistent_bitmaps() Vladimir Sementsov-Ogievskiy
2016-10-07 19:24   ` Max Reitz
2016-10-13 16:48     ` Vladimir Sementsov-Ogievskiy
2016-10-15 16:40       ` Max Reitz
2016-10-17 17:19     ` Vladimir Sementsov-Ogievskiy
2016-10-21 19:44       ` Max Reitz
2016-10-21 21:04         ` Eric Blake
2016-10-17 17:57   ` Vladimir Sementsov-Ogievskiy
2016-10-17 17:58     ` [Qemu-devel] DROP THIS " Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 12/22] qcow2-bitmap: add IN_USE flag Vladimir Sementsov-Ogievskiy
2016-10-07 19:44   ` Max Reitz
2016-10-21 15:34     ` Vladimir Sementsov-Ogievskiy
2016-10-21 19:58       ` Max Reitz
2016-10-24 10:32         ` Vladimir Sementsov-Ogievskiy
2016-10-24 11:35           ` Vladimir Sementsov-Ogievskiy
2016-10-24 17:08             ` Max Reitz
2016-10-24 17:18               ` Max Reitz
2016-10-25 10:53                 ` Vladimir Sementsov-Ogievskiy
2016-10-26  9:04                   ` Vladimir Sementsov-Ogievskiy
2016-10-26  9:21                     ` Vladimir Sementsov-Ogievskiy
2016-10-26 12:13                       ` Vladimir Sementsov-Ogievskiy
2016-10-26 13:02                         ` Vladimir Sementsov-Ogievskiy [this message]
2016-10-26 15:28                     ` Max Reitz
2016-11-07 16:12                   ` Vladimir Sementsov-Ogievskiy
2016-11-07 16:18                     ` Max Reitz
2016-10-24 16:54           ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 13/22] qcow2-bitmap: check constraints Vladimir Sementsov-Ogievskiy
2016-10-07 19:54   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 14/22] qcow2: delete bitmaps on truncate Vladimir Sementsov-Ogievskiy
2016-10-07 19:58   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 15/22] qcow2-bitmap: add autoclear bit Vladimir Sementsov-Ogievskiy
2016-10-07 20:11   ` Max Reitz
2016-10-24 14:25     ` Vladimir Sementsov-Ogievskiy
2016-10-24 17:21       ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 16/22] qmp: add persistent flag to block-dirty-bitmap-add Vladimir Sementsov-Ogievskiy
2016-10-07 19:52   ` Eric Blake
2016-10-24 14:44     ` Vladimir Sementsov-Ogievskiy
2016-10-10 16:08   ` Max Reitz
2016-10-24 15:12     ` Vladimir Sementsov-Ogievskiy
2016-10-24 17:30       ` Max Reitz
2016-10-25 11:05         ` Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 17/22] qmp: add autoload parameter " Vladimir Sementsov-Ogievskiy
2016-10-07 19:53   ` Eric Blake
2016-10-10 16:25   ` Max Reitz
2016-10-24 15:55     ` Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 18/22] qapi: add md5 checksum of last dirty bitmap level to query-block Vladimir Sementsov-Ogievskiy
2016-10-10 16:44   ` Max Reitz
2016-10-10 17:03     ` Max Reitz
2016-10-10 19:22       ` Eric Blake
2016-09-30 10:53 ` [Qemu-devel] [PATCH 19/22] iotests: test qcow2 persistent dirty bitmap Vladimir Sementsov-Ogievskiy
2016-10-10 17:04   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 20/22] qcow2-dirty-bitmap: refcounts Vladimir Sementsov-Ogievskiy
2016-10-10 17:59   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 21/22] specs/qcow2: fix bitmap granularity qemu-specific note Vladimir Sementsov-Ogievskiy
2016-10-07 20:18   ` Eric Blake
2016-11-09 16:43     ` Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 22/22] specs/qcow2: do not use wording 'bitmap header' Vladimir Sementsov-Ogievskiy
2016-10-07 20:20   ` Eric Blake
2016-10-01 13:37 ` [Qemu-devel] [PATCH v7 00/22] qcow2: persistent dirty bitmaps Max Reitz
2016-10-13 18:11   ` John Snow

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=12721412-2a42-ba02-d818-7dd2848a4703@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --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 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.