From nobody Fri Dec 19 04:08:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568296175; cv=none; d=zoho.com; s=zohoarc; b=hbkCoWmFjxQSEkAgBddWPzGqMWa3p8Rj/Z19HpqngNk3M3oOpg+nXSCrc08KN8ygYPQulyae4bjdeKyWZvvMHA7wvpyhLNCL2jDvfL7nDLB1A3NTCRfZY8uS/X1OHDRm3BDUKnGlRZ6JVUtGt1EMoA4Fr2lJYhdWXMJlhfVMO0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568296175; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=8GGUSvTVeM1YeeuMZVY2NH+ORvj6DiMlpr12nFHdJmE=; b=kV6gXlgshTWyFWTNnSNmLVfWcT4iauIdWn3/F4o32kcyvOpC3ba2bnPCCjd4tZCTMu6c+wAzhlyzL8lMJWo6E4lf8jq/3bVO/jeKWiSQURgTVv51dXFRu9s2Cdfjakk7qwjdSDVVR6mqapNpV+0N1b19pz7q7LvVrRp5TgrDiQ8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568296175206241.55117478049988; Thu, 12 Sep 2019 06:49:35 -0700 (PDT) Received: from localhost ([::1]:34656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8PTQ-0004ZR-U6 for importer@patchew.org; Thu, 12 Sep 2019 09:49:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38980) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8PQY-0002YZ-6G for qemu-devel@nongnu.org; Thu, 12 Sep 2019 09:46:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8PQW-0001HK-Na for qemu-devel@nongnu.org; Thu, 12 Sep 2019 09:46:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60322) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8PQR-0001Dw-R2; Thu, 12 Sep 2019 09:46:21 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9EFE2308A9E2; Thu, 12 Sep 2019 13:46:16 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-116-179.ams2.redhat.com [10.36.116.179]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9393F600C4; Thu, 12 Sep 2019 13:46:15 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 12 Sep 2019 15:45:43 +0200 Message-Id: <20190912134604.22019-2-kwolf@redhat.com> In-Reply-To: <20190912134604.22019-1-kwolf@redhat.com> References: <20190912134604.22019-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 12 Sep 2019 13:46:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/22] qcow2: Fix the calculation of the maximum L2 cache size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia The size of the qcow2 L2 cache defaults to 32 MB, which can be easily larger than the maximum amount of L2 metadata that the image can have. For example: with 64 KB clusters the user would need a qcow2 image with a virtual size of 256 GB in order to have 32 MB of L2 metadata. Because of that, since commit b749562d9822d14ef69c9eaa5f85903010b86c30 we forbid the L2 cache to become larger than the maximum amount of L2 metadata for the image, calculated using this formula: uint64_t max_l2_cache =3D virtual_disk_size / (s->cluster_size / 8); The problem with this formula is that the result should be rounded up to the cluster size because an L2 table on disk always takes one full cluster. For example, a 1280 MB qcow2 image with 64 KB clusters needs exactly 160 KB of L2 metadata, but we need 192 KB on disk (3 clusters) even if the last 32 KB of those are not going to be used. However QEMU rounds the numbers down and only creates 2 cache tables (128 KB), which is not enough for the image. A quick test doing 4KB random writes on a 1280 MB image gives me around 500 IOPS, while with the correct cache size I get 16K IOPS. Cc: qemu-stable@nongnu.org Signed-off-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/qcow2.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 0882ff6e92..57734f20cf 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -828,7 +828,11 @@ static void read_cache_sizes(BlockDriverState *bs, Qem= uOpts *opts, bool l2_cache_entry_size_set; int min_refcount_cache =3D MIN_REFCOUNT_CACHE_SIZE * s->cluster_size; uint64_t virtual_disk_size =3D bs->total_sectors * BDRV_SECTOR_SIZE; - uint64_t max_l2_cache =3D virtual_disk_size / (s->cluster_size / 8); + uint64_t max_l2_entries =3D DIV_ROUND_UP(virtual_disk_size, s->cluster= _size); + /* An L2 table is always one cluster in size so the max cache size + * should be a multiple of the cluster size. */ + uint64_t max_l2_cache =3D ROUND_UP(max_l2_entries * sizeof(uint64_t), + s->cluster_size); =20 combined_cache_size_set =3D qemu_opt_get(opts, QCOW2_OPT_CACHE_SIZE); l2_cache_size_set =3D qemu_opt_get(opts, QCOW2_OPT_L2_CACHE_SIZE); --=20 2.20.1