From nobody Sun Feb 8 22:35:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517845154712367.91030779833204; Mon, 5 Feb 2018 07:39:14 -0800 (PST) Received: from localhost ([::1]:54132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eiirP-00085s-JV for importer@patchew.org; Mon, 05 Feb 2018 10:39:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eii5B-0007Vy-7J for qemu-devel@nongnu.org; Mon, 05 Feb 2018 09:49:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eii57-0000Uw-KB for qemu-devel@nongnu.org; Mon, 05 Feb 2018 09:49:21 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:49513) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eii57-0000TE-BC; Mon, 05 Feb 2018 09:49:17 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1eihqZ-0001ry-FI; Mon, 05 Feb 2018 15:34:15 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1eihqJ-0008Ns-09; Mon, 05 Feb 2018 16:33:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WRfTsCjcs/CnJo88TFa0AYiIE7TUWNPK1Mt0psI4QRw=; b=f/Qv+vy2IKnNS95aLKCYV1xwdMGRwOecN2ySzVqG//nUe+BQAr0qvDg6c82zpcrr6MVGj12Xs3ySa5TxLkmIA0awqDtzOAu7diAuW8BkkraOLdcj21301fcco2GXLdwqx27yxVcU9deYJNLzGUL8e+m0c6aDxX2EKYmFZ//EtKcyn/xziQPkr4+EwzhTCTABzFFhyCGWNrHhjNtK6yyMdEDYUPN59AqPJ2bwyjpl/CDT1LgmA/deS+z6xe4SHKNhCXSkz94S6JDCUb1kpa5jSDZWTQ0GFDGZrHXX6cw4NiYCv1XyrY7pG5VPmGc+5ClJU6Y0BLixRHIPa4squN18kw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 16:33:02 +0200 Message-Id: <67a1bf9e55f417005c567bead95a018dc34bc687.1517840876.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v4 02/39] qcow2: Add table size field to Qcow2Cache X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The table size in the qcow2 cache is currently equal to the cluster size. This doesn't allow us to use the cache memory efficiently, particularly with large cluster sizes, so we need to be able to have smaller cache tables that are independent from the cluster size. This patch adds a new field to Qcow2Cache that we can use instead of the cluster size. The current table size is still being initialized to the cluster size, so there are no semantic changes yet, but this patch will allow us to prepare the rest of the code and simplify a few function calls. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-cache.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c index c48ffebd8f..38c03770b4 100644 --- a/block/qcow2-cache.c +++ b/block/qcow2-cache.c @@ -39,6 +39,7 @@ struct Qcow2Cache { Qcow2CachedTable *entries; struct Qcow2Cache *depends; int size; + int table_size; bool depends_on_flush; void *table_array; uint64_t lru_counter; @@ -48,17 +49,15 @@ struct Qcow2Cache { static inline void *qcow2_cache_get_table_addr(BlockDriverState *bs, Qcow2Cache *c, int table) { - BDRVQcow2State *s =3D bs->opaque; - return (uint8_t *) c->table_array + (size_t) table * s->cluster_size; + return (uint8_t *) c->table_array + (size_t) table * c->table_size; } =20 static inline int qcow2_cache_get_table_idx(BlockDriverState *bs, Qcow2Cache *c, void *table) { - BDRVQcow2State *s =3D bs->opaque; ptrdiff_t table_offset =3D (uint8_t *) table - (uint8_t *) c->table_ar= ray; - int idx =3D table_offset / s->cluster_size; - assert(idx >=3D 0 && idx < c->size && table_offset % s->cluster_size = =3D=3D 0); + int idx =3D table_offset / c->table_size; + assert(idx >=3D 0 && idx < c->size && table_offset % c->table_size =3D= =3D 0); return idx; } =20 @@ -79,10 +78,9 @@ static void qcow2_cache_table_release(BlockDriverState *= bs, Qcow2Cache *c, { /* Using MADV_DONTNEED to discard memory is a Linux-specific feature */ #ifdef CONFIG_LINUX - BDRVQcow2State *s =3D bs->opaque; void *t =3D qcow2_cache_get_table_addr(bs, c, i); int align =3D getpagesize(); - size_t mem_size =3D (size_t) s->cluster_size * num_tables; + size_t mem_size =3D (size_t) c->table_size * num_tables; size_t offset =3D QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t; size_t length =3D QEMU_ALIGN_DOWN(mem_size - offset, align); if (mem_size > offset && length > 0) { @@ -132,9 +130,10 @@ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, i= nt num_tables) =20 c =3D g_new0(Qcow2Cache, 1); c->size =3D num_tables; + c->table_size =3D s->cluster_size; c->entries =3D g_try_new0(Qcow2CachedTable, num_tables); c->table_array =3D qemu_try_blockalign(bs->file->bs, - (size_t) num_tables * s->cluster_= size); + (size_t) num_tables * c->table_si= ze); =20 if (!c->entries || !c->table_array) { qemu_vfree(c->table_array); @@ -203,13 +202,13 @@ static int qcow2_cache_entry_flush(BlockDriverState *= bs, Qcow2Cache *c, int i) =20 if (c =3D=3D s->refcount_block_cache) { ret =3D qcow2_pre_write_overlap_check(bs, QCOW2_OL_REFCOUNT_BLOCK, - c->entries[i].offset, s->cluster_size); + c->entries[i].offset, c->table_size); } else if (c =3D=3D s->l2_table_cache) { ret =3D qcow2_pre_write_overlap_check(bs, QCOW2_OL_ACTIVE_L2, - c->entries[i].offset, s->cluster_size); + c->entries[i].offset, c->table_size); } else { ret =3D qcow2_pre_write_overlap_check(bs, 0, - c->entries[i].offset, s->cluster_size); + c->entries[i].offset, c->table_size); } =20 if (ret < 0) { @@ -223,7 +222,7 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs= , Qcow2Cache *c, int i) } =20 ret =3D bdrv_pwrite(bs->file, c->entries[i].offset, - qcow2_cache_get_table_addr(bs, c, i), s->cluster_siz= e); + qcow2_cache_get_table_addr(bs, c, i), c->table_size); if (ret < 0) { return ret; } @@ -331,7 +330,7 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qco= w2Cache *c, trace_qcow2_cache_get(qemu_coroutine_self(), c =3D=3D s->l2_table_cach= e, offset, read_from_disk); =20 - if (offset_into_cluster(s, offset)) { + if (!QEMU_IS_ALIGNED(offset, c->table_size)) { qcow2_signal_corruption(bs, true, -1, -1, "Cannot get entry from %= s " "cache: Offset %#" PRIx64 " is unaligned", qcow2_cache_get_name(s, c), offset); @@ -339,7 +338,7 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qco= w2Cache *c, } =20 /* Check if the table is already cached */ - i =3D lookup_index =3D (offset / s->cluster_size * 4) % c->size; + i =3D lookup_index =3D (offset / c->table_size * 4) % c->size; do { const Qcow2CachedTable *t =3D &c->entries[i]; if (t->offset =3D=3D offset) { @@ -380,7 +379,7 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qco= w2Cache *c, =20 ret =3D bdrv_pread(bs->file, offset, qcow2_cache_get_table_addr(bs, c, i), - s->cluster_size); + c->table_size); if (ret < 0) { return ret; } --=20 2.11.0