From: Kevin Wolf <kwolf@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Qemu-block <qemu-block@nongnu.org>,
QEMU Developers <qemu-devel@nongnu.org>,
berto@igalia.com
Subject: Re: [Qemu-devel] [PULL 20/37] qcow2: Give the refcount cache the minimum possible size by default
Date: Mon, 28 May 2018 10:38:55 +0200 [thread overview]
Message-ID: <20180528083855.GB4580@localhost.localdomain> (raw)
In-Reply-To: <CAFEAcA-FhMC0LqkYcRh3fV864wNSAJnHbT3657Y55MN9=RO72Q@mail.gmail.com>
Am 25.05.2018 um 19:10 hat Peter Maydell geschrieben:
> On 15 May 2018 at 16:40, Kevin Wolf <kwolf@redhat.com> wrote:
> > From: Alberto Garcia <berto@igalia.com>
> >
> > The L2 and refcount caches have default sizes that can be overridden
> > using the l2-cache-size and refcount-cache-size (an additional
> > parameter named cache-size sets the combined size of both caches).
>
> Hi; Coverity raises a nit about this patch (CID 1391229):
CCing Berto as the patch author.
> > diff --git a/block/qcow2.c b/block/qcow2.c
> > index 2f36e632f9..6d532470a8 100644
> > --- a/block/qcow2.c
> > +++ b/block/qcow2.c
> > @@ -802,23 +802,30 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
> > } else if (refcount_cache_size_set) {
> > *l2_cache_size = combined_cache_size - *refcount_cache_size;
> > } else {
> > - *refcount_cache_size = combined_cache_size
> > - / (DEFAULT_L2_REFCOUNT_SIZE_RATIO + 1);
> > - *l2_cache_size = combined_cache_size - *refcount_cache_size;
> > + uint64_t virtual_disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
> > + uint64_t max_l2_cache = virtual_disk_size / (s->cluster_size / 8);
> > + uint64_t min_refcount_cache =
> > + (uint64_t) MIN_REFCOUNT_CACHE_SIZE * s->cluster_size;
>
> Here we have a (uint64_t) cast that ensures we're doing a 64x64 multiply
> rather than a 32x32 one...
>
> > +
> > + /* Assign as much memory as possible to the L2 cache, and
> > + * use the remainder for the refcount cache */
> > + if (combined_cache_size >= max_l2_cache + min_refcount_cache) {
> > + *l2_cache_size = max_l2_cache;
> > + *refcount_cache_size = combined_cache_size - *l2_cache_size;
> > + } else {
> > + *refcount_cache_size =
> > + MIN(combined_cache_size, min_refcount_cache);
> > + *l2_cache_size = combined_cache_size - *refcount_cache_size;
> > + }
> > }
> > } else {
> > - if (!l2_cache_size_set && !refcount_cache_size_set) {
> > + if (!l2_cache_size_set) {
> > *l2_cache_size = MAX(DEFAULT_L2_CACHE_BYTE_SIZE,
> > (uint64_t)DEFAULT_L2_CACHE_CLUSTERS
> > * s->cluster_size);
> > - *refcount_cache_size = *l2_cache_size
> > - / DEFAULT_L2_REFCOUNT_SIZE_RATIO;
> > - } else if (!l2_cache_size_set) {
> > - *l2_cache_size = *refcount_cache_size
> > - * DEFAULT_L2_REFCOUNT_SIZE_RATIO;
> > - } else if (!refcount_cache_size_set) {
> > - *refcount_cache_size = *l2_cache_size
> > - / DEFAULT_L2_REFCOUNT_SIZE_RATIO;
> > + }
> > + if (!refcount_cache_size_set) {
> > + *refcount_cache_size = MIN_REFCOUNT_CACHE_SIZE * s->cluster_size;
>
> ...but in the else clause down here, we don't have the cast, and
> Coverity complains that we evaluate a 32-bit result and then
> put it in a 64-bit variable. Should this have the (uint64_t)
> cast as well ?
It's a false positive, MIN_REFCOUNT_CACHE_SIZE is 4 and s->cluster_size
is at most 2 MB, so this will never overflow.
I guess we can change the code anyway to silence it?
Kevin
next prev parent reply other threads:[~2018-05-28 8:39 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-15 15:39 [Qemu-devel] [PULL 00/37] Block layer patches Kevin Wolf
2018-05-15 15:39 ` [Qemu-devel] [PULL 01/37] block-backend: simplify blk_get_aio_context Kevin Wolf
2018-05-15 15:39 ` [Qemu-devel] [PULL 02/37] block: Support byte-based aio callbacks Kevin Wolf
2018-05-15 15:39 ` [Qemu-devel] [PULL 03/37] file-win32: Switch to byte-based callbacks Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 04/37] null: Switch to byte-based read/write Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 05/37] rbd: Switch to byte-based callbacks Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 06/37] vxhs: " Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 07/37] block: Drop last of the sector-based aio callbacks Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 08/37] block: Merge .bdrv_co_writev{, _flags} in drivers Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 09/37] hmp: Allow using a qdev id in block_set_io_throttle Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 10/37] blockjob: expose error string via query Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 11/37] blockjob: Fix assertion in block_job_finalize() Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 12/37] blockjob: Wrappers for progress counter access Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 13/37] blockjob: Move RateLimit to BlockJob Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 14/37] blockjob: Implement block_job_set_speed() centrally Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 15/37] blockjob: Introduce block_job_ratelimit_get_delay() Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 16/37] blockjob: Add block_job_driver() Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 17/37] iotests: Split 214 off of 122 Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 18/37] Fix error message about compressed clusters with OFLAG_COPIED Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 19/37] specs/qcow2: Clarify that compressed clusters have the COPIED bit reset Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 20/37] qcow2: Give the refcount cache the minimum possible size by default Kevin Wolf
2018-05-25 17:10 ` Peter Maydell
2018-05-28 8:38 ` Kevin Wolf [this message]
2018-05-28 8:58 ` Alberto Garcia
2018-05-28 13:49 ` Peter Maydell
2018-05-28 13:58 ` Alberto Garcia
2018-05-15 15:40 ` [Qemu-devel] [PULL 21/37] docs: Document the new default sizes of the qcow2 caches Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 22/37] iotests: Add failure matching to common.qemu Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 23/37] iotests: Skip 181 and 201 without userfaultfd Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 24/37] block: Add COR filter driver Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 25/37] block: BLK_PERM_WRITE includes ..._UNCHANGED Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 26/37] block: Add BDRV_REQ_WRITE_UNCHANGED flag Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 27/37] block: Set BDRV_REQ_WRITE_UNCHANGED for COR writes Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 28/37] block/quorum: Support BDRV_REQ_WRITE_UNCHANGED Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 29/37] block: Support BDRV_REQ_WRITE_UNCHANGED in filters Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 30/37] iotests: Clean up wrap image in 197 Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 31/37] iotests: Copy 197 for COR filter driver Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 32/37] iotests: Add test for COR across nodes Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 33/37] qemu-img: Check post-truncation size Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 34/37] block: Document BDRV_REQ_WRITE_UNCHANGED support Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 35/37] qemu-io: Use purely string blockdev options Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 36/37] qemu-img: Use only string options in img_open_opts Kevin Wolf
2018-05-15 15:40 ` [Qemu-devel] [PULL 37/37] iotests: Add test for -U/force-share conflicts Kevin Wolf
2018-05-15 16:59 ` [Qemu-devel] [PULL 00/37] Block layer patches Peter Maydell
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=20180528083855.GB4580@localhost.localdomain \
--to=kwolf@redhat.com \
--cc=berto@igalia.com \
--cc=peter.maydell@linaro.org \
--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).