From: Max Reitz <mreitz@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, John Snow <jsnow@redhat.com>,
Nir Soffer <nsoffer@redhat.com>,
Maor Lipchuk <mlipchuk@redhat.com>,
Alberto Garcia <berto@igalia.com>
Subject: Re: [Qemu-devel] [PATCH v6 4/9] qcow2: make refcount size calculation conservative
Date: Mon, 8 May 2017 23:26:18 +0200 [thread overview]
Message-ID: <8b49e6e9-043d-e628-3c49-1433ba0b5d5e@redhat.com> (raw)
In-Reply-To: <20170508141536.20690-5-stefanha@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2898 bytes --]
On 08.05.2017 16:15, Stefan Hajnoczi wrote:
> The refcount metadata size calculation is inaccurate and can produce
> numbers that are too small. This is bad because we should calculate a
> conservative number - one that is guaranteed to be large enough.
>
> This patch switches the approach to a fixed point calculation because
> the existing equation is hard to solve when inaccuracies are taken care
> of.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> Reviewed-by: Alberto Garcia <berto@igalia.com>
> ---
> block/qcow2.c | 82 ++++++++++++++++++++++++++++++-----------------------------
> 1 file changed, 42 insertions(+), 40 deletions(-)
>
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 5569b63..ff0d825 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -2095,6 +2095,43 @@ static int preallocate(BlockDriverState *bs)
> return 0;
> }
>
> +/* qcow2_refcount_metadata_size:
> + * @clusters: number of clusters to refcount (including data and L1/L2 tables)
> + * @cluster_size: size of a cluster, in bytes
> + * @refcount_order: refcount bits power-of-2 exponent
> + *
> + * Returns: Number of bytes required for refcount blocks and table metadata.
> + */
> +static int64_t qcow2_refcount_metadata_size(int64_t clusters,
> + size_t cluster_size,
> + int refcount_order)
> +{
> + /*
> + * Every host cluster is reference-counted, including metadata (even
> + * refcount metadata is recursively included).
> + *
> + * An accurate formula for the size of refcount metadata size is difficult
> + * to derive.
Oh, by the way:
https://lists.nongnu.org/archive/html/qemu-devel/2014-04/msg04820.html
*cough* *cough*
(No, this is not the formula that was used for this preallocation.
Otherwise, it would have been correct. O:-))
Max
> An easier method of calculation is finding the fixed point
> + * where no further refcount blocks or table clusters are required to
> + * reference count every cluster.
> + */
> + int64_t blocks_per_table_cluster = cluster_size / sizeof(uint64_t);
> + int64_t refcounts_per_block = cluster_size * 8 / (1 << refcount_order);
> + int64_t table = 0; /* number of refcount table clusters */
> + int64_t blocks = 0; /* number of refcount block clusters */
> + int64_t last;
> + int64_t n = 0;
> +
> + do {
> + last = n;
> + blocks = DIV_ROUND_UP(clusters + table + blocks, refcounts_per_block);
> + table = DIV_ROUND_UP(blocks, blocks_per_table_cluster);
> + n = clusters + blocks + table;
> + } while (n != last);
> +
> + return (blocks + table) * cluster_size;
> +}
> +
> /**
> * qcow2_calc_prealloc_size:
> * @total_size: virtual disk size in bytes
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
next prev parent reply other threads:[~2017-05-08 21:26 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-08 14:15 [Qemu-devel] [PATCH v6 0/9] qemu-img: add measure sub-command Stefan Hajnoczi
2017-05-08 14:15 ` [Qemu-devel] [PATCH v6 1/9] block: add bdrv_measure() API Stefan Hajnoczi
2017-05-08 14:50 ` Eric Blake
2017-05-09 15:28 ` Stefan Hajnoczi
2017-05-08 14:15 ` [Qemu-devel] [PATCH v6 2/9] raw-format: add bdrv_measure() support Stefan Hajnoczi
2017-05-08 14:52 ` Eric Blake
2017-05-08 14:15 ` [Qemu-devel] [PATCH v6 3/9] qcow2: extract preallocation calculation function Stefan Hajnoczi
2017-05-08 14:15 ` [Qemu-devel] [PATCH v6 4/9] qcow2: make refcount size calculation conservative Stefan Hajnoczi
2017-05-08 15:00 ` Eric Blake
2017-05-08 19:06 ` Max Reitz
2017-05-08 21:26 ` Max Reitz [this message]
2017-05-09 15:32 ` Stefan Hajnoczi
2017-05-08 14:15 ` [Qemu-devel] [PATCH v6 5/9] qcow2: extract image creation option parsing Stefan Hajnoczi
2017-05-08 14:15 ` [Qemu-devel] [PATCH v6 6/9] qcow2: add bdrv_measure() support Stefan Hajnoczi
2017-05-08 14:15 ` [Qemu-devel] [PATCH v6 7/9] qemu-img: add measure subcommand Stefan Hajnoczi
2017-06-12 10:00 ` Alberto Garcia
2017-06-13 9:09 ` Stefan Hajnoczi
2017-05-08 14:15 ` [Qemu-devel] [PATCH v6 8/9] qemu-iotests: support per-format golden output files Stefan Hajnoczi
2017-05-08 14:15 ` [Qemu-devel] [PATCH v6 9/9] iotests: add test 178 for qemu-img measure Stefan Hajnoczi
2017-05-24 12:59 ` [Qemu-devel] [PATCH v6 0/9] qemu-img: add measure sub-command Stefan Hajnoczi
2017-06-12 9:29 ` Stefan Hajnoczi
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=8b49e6e9-043d-e628-3c49-1433ba0b5d5e@redhat.com \
--to=mreitz@redhat.com \
--cc=berto@igalia.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mlipchuk@redhat.com \
--cc=nsoffer@redhat.com \
--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 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).