All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Alberto Garcia <berto@igalia.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/6] qcow2: use one single memory block for the L2/refcount cache tables
Date: Thu, 30 Apr 2015 09:08:05 -0600	[thread overview]
Message-ID: <55424555.5050703@redhat.com> (raw)
In-Reply-To: <9b9c36f8c567da1f9561828380e8aa42c08b7efd.1430388393.git.berto@igalia.com>

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

On 04/30/2015 04:11 AM, Alberto Garcia wrote:
> The qcow2 L2/refcount cache contains one separate table for each cache
> entry. Doing one allocation per table adds unnecessary overhead and it
> also requires us to store the address of each table separately.
> 
> Since the size of the cache is constant during its lifetime, it's
> better to have an array that contains all the tables using one single
> allocation.
> 
> In my tests measuring freshly created caches with sizes 128MB (L2) and
> 32MB (refcount) this uses around 10MB of RAM less.
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  block/qcow2-cache.c | 48 +++++++++++++++++++++---------------------------
>  1 file changed, 21 insertions(+), 27 deletions(-)
> 

>  
>  typedef struct Qcow2CachedTable {
> -    void*   table;
>      int64_t offset;
>      bool    dirty;
>      int     cache_hits;
> @@ -40,39 +39,34 @@ struct Qcow2Cache {
>      struct Qcow2Cache*      depends;
>      int                     size;
>      bool                    depends_on_flush;
> +    void                   *table_array;
> +    int                     table_size;

Should this be size_t? [1]

>  };
>  
> +static inline void *table_addr(Qcow2Cache *c, int table)
> +{
> +    return c->table_array + table * c->table_size;

Addition on void* is not portable.

> +}
> +
>  Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables)
>  {
>      BDRVQcowState *s = bs->opaque;
>      Qcow2Cache *c;
> -    int i;
>  
>      c = g_new0(Qcow2Cache, 1);
>      c->size = num_tables;
> +    c->table_size = s->cluster_size;

[1] Oh, maybe not, since BDRVQcowState declares cluster_size as int.

>      c->entries = g_try_new0(Qcow2CachedTable, num_tables);
> -    if (!c->entries) {
> -        goto fail;
> -    }
> +    c->table_array = qemu_try_blockalign(bs->file, num_tables * c->table_size);

Are we sure this won't overflow?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-04-30 15:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30 10:11 [Qemu-devel] [PATCH 0/6] qcow2 L2/refcount cache improvements Alberto Garcia
2015-04-30 10:11 ` [Qemu-devel] [PATCH 1/6] qcow2: use one single memory block for the L2/refcount cache tables Alberto Garcia
2015-04-30 15:08   ` Eric Blake [this message]
2015-05-05 13:00     ` Alberto Garcia
2015-05-01 14:23   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-05-04 10:58     ` Kevin Wolf
2015-05-05 10:28       ` Stefan Hajnoczi
2015-05-05 11:20         ` Kevin Wolf
2015-05-05 15:09           ` Alberto Garcia
2015-05-06 14:57           ` Stefan Hajnoczi
2015-04-30 10:11 ` [Qemu-devel] [PATCH 2/6] qcow2: simplify qcow2_cache_put() and qcow2_cache_entry_mark_dirty() Alberto Garcia
2015-05-01 14:31   ` Stefan Hajnoczi
2015-05-05 13:06     ` Alberto Garcia
2015-05-06 15:00       ` Stefan Hajnoczi
2015-05-06 15:32         ` Alberto Garcia
2015-05-05 15:21   ` Eric Blake
2015-04-30 10:11 ` [Qemu-devel] [PATCH 3/6] qcow2: use an LRU algorithm to replace entries from the L2 cache Alberto Garcia
2015-04-30 10:11 ` [Qemu-devel] [PATCH 4/6] qcow2: remove qcow2_cache_find_entry_to_replace() Alberto Garcia
2015-04-30 10:11 ` [Qemu-devel] [PATCH 5/6] qcow2: use a hash to look for entries in the L2 cache Alberto Garcia
2015-05-06 16:42   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-05-07  8:23     ` Alberto Garcia
2015-04-30 10:11 ` [Qemu-devel] [PATCH 6/6] qcow2: style fixes in qcow2-cache.c Alberto Garcia
2015-05-06 16:42   ` Stefan Hajnoczi
2015-05-06 16:43 ` [Qemu-devel] [Qemu-block] [PATCH 0/6] qcow2 L2/refcount cache improvements 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=55424555.5050703@redhat.com \
    --to=eblake@redhat.com \
    --cc=berto@igalia.com \
    --cc=kwolf@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.