From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54878) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ynq5J-0006X4-D3 for qemu-devel@nongnu.org; Thu, 30 Apr 2015 11:09:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ynq5E-0001eI-38 for qemu-devel@nongnu.org; Thu, 30 Apr 2015 11:09:05 -0400 Message-ID: <55424555.5050703@redhat.com> Date: Thu, 30 Apr 2015 09:08:05 -0600 From: Eric Blake MIME-Version: 1.0 References: <9b9c36f8c567da1f9561828380e8aa42c08b7efd.1430388393.git.berto@igalia.com> In-Reply-To: <9b9c36f8c567da1f9561828380e8aa42c08b7efd.1430388393.git.berto@igalia.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="dt6bEuuTMLQgxtsrG5AFwTmj7mcv558p4" Subject: Re: [Qemu-devel] [PATCH 1/6] qcow2: use one single memory block for the L2/refcount cache tables List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alberto Garcia , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --dt6bEuuTMLQgxtsrG5AFwTmj7mcv558p4 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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. >=20 > 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. >=20 > In my tests measuring freshly created caches with sizes 128MB (L2) and > 32MB (refcount) this uses around 10MB of RAM less. >=20 > Signed-off-by: Alberto Garcia > --- > block/qcow2-cache.c | 48 +++++++++++++++++++++------------------------= --- > 1 file changed, 21 insertions(+), 27 deletions(-) >=20 > =20 > 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] > }; > =20 > +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 =3D bs->opaque; > Qcow2Cache *c; > - int i; > =20 > c =3D g_new0(Qcow2Cache, 1); > c->size =3D num_tables; > + c->table_size =3D s->cluster_size; [1] Oh, maybe not, since BDRVQcowState declares cluster_size as int. > c->entries =3D g_try_new0(Qcow2CachedTable, num_tables); > - if (!c->entries) { > - goto fail; > - } > + c->table_array =3D qemu_try_blockalign(bs->file, num_tables * c->t= able_size); Are we sure this won't overflow? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --dt6bEuuTMLQgxtsrG5AFwTmj7mcv558p4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVQkVVAAoJEKeha0olJ0NqZ4IH+wTkUAQd17e+/jM5xmUxHtfr ZE8pDUgQeVoHQaUf2Ga0qIenoPY2EKSioqiAUPw4KTR0q28C7qiiv5z45s5xYM2W sKTVvMvkie+is4LpZ2KVqAcIumqTztrKVugNl8hGs/lclZ7qrx+z8f2OO6esnLOY RAvnK2NHnWmQQhdFNc1PFhyuixS2rZwYyPr5UUQNtSE8pHzrYKS59CdObt6Cdtnr erKDJkZTKX63wHfuT+a2BKnk7lwDUtHWf7NgoVh/IKtKF0sj5QfvyQJJCihoochs Ap8ybz/fNgRuoVYWFWfYjRO0+vGSOiyk3swa0zUvGrVhGY7I/0LgxPABKLcRi40= =3p/3 -----END PGP SIGNATURE----- --dt6bEuuTMLQgxtsrG5AFwTmj7mcv558p4--