From nobody Fri Nov 14 17:03:07 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1588701099; cv=none; d=zohomail.com; s=zohoarc; b=Dg6xbejBEVqJMVGEJU6jgAnjNXnJ4eHgfxUvW34Bheo+2G1GTUuCe8GI1WxDMVq4jomp4klRopRN9S+HHeE8oiZ1VA/rZ+T/2utHbczOdiEr+3Nx4/HtrY9xTQPh97FNSEjuVX2uZkjMmQeMXpOBonbK6BoiRO8Qg1Fkm4IuRRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588701099; 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; bh=mlp+Okpm66jwPYtCI6BnSwv6VTE4+27zCkowQ7HRCeY=; b=Xk6NppYG3E1ZPLwXuOq2Jb7Skdivh4QFVB2gtdI7ho37IAv409nTfHPZNEeUif7jKzhaWeL90YDpSyl+pyg5lGg0+Pj0MdznXlvWDZEg7W+3m5OW9HU4yIx6Y7CUarF6LCcqhqV9QWLjIkJIXJrJOT/aC0am+5xMSCKLAx3ZPaI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588701099435181.0687550584929; Tue, 5 May 2020 10:51:39 -0700 (PDT) Received: from localhost ([::1]:47774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jW1jG-0007eH-3d for importer@patchew.org; Tue, 05 May 2020 13:51:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jW1Xk-0006zL-5z; Tue, 05 May 2020 13:39:44 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:39070) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jW1Xd-0008R2-Pq; Tue, 05 May 2020 13:39:42 -0400 Received: from static.160.43.0.81.ibercom.com ([81.0.43.160] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jW1Ws-00025I-Er; Tue, 05 May 2020 19:38:50 +0200 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jW1Wc-00043l-LL; Tue, 05 May 2020 19:38:34 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=mlp+Okpm66jwPYtCI6BnSwv6VTE4+27zCkowQ7HRCeY=; b=mmmWG2Mwo5eEqxxTeAgIFG+ZgVhUizSuS17fZdWK4IWcZYIh60r1FJe99KzGNWuiKSsotX+dg+aVEj6syYDOnG179QndiEBHjBdTYe3DwtF+6nQvlVbWyAWRJp0e24AbdemFY1EzLkZxLVR3cBEoMB6gSGMRmB+kl+NpubD+aZRHvttaraNOzPsWSqrXgqUg2ZXgNftl4HNCGogiFsiKdYDVyXIU5u3vlD/mi6zCC28eohfdrI1oQcAxZDicmG8qh7AY1geOXrfJP7Nlm748Oz2qWqb/jXQ+cvVgTm+aO2//5uUWfPn/N/ImY22VSMHFKxY+RXDWiveGpwO8wj/2Vg==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v5 07/31] qcow2: Document the Extended L2 Entries feature Date: Tue, 5 May 2020 19:38:07 +0200 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=178.60.130.6; envelope-from=berto@igalia.com; helo=fanzine.igalia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/05 13:38:50 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Subcluster allocation in qcow2 is implemented by extending the existing L2 table entries and adding additional information to indicate the allocation status of each subcluster. This patch documents the changes to the qcow2 format and how they affect the calculation of the L2 cache size. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- docs/interop/qcow2.txt | 68 ++++++++++++++++++++++++++++++++++++++++-- docs/qcow2-cache.txt | 19 +++++++++++- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index 298a031310..f08e43f228 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -42,6 +42,9 @@ The first cluster of a qcow2 image contains the file head= er: as the maximum cluster size and won't be able to open = images with larger cluster sizes. =20 + Note: if the image has Extended L2 Entries then cluste= r_bits + must be at least 14 (i.e. 16384 byte clusters). + 24 - 31: size Virtual disk size in bytes. =20 @@ -117,7 +120,12 @@ the next fields through header_length. clusters. The compression_type field must = be present and not zero. =20 - Bits 4-63: Reserved (set to 0) + Bit 4: Extended L2 Entries. If this bit is set t= hen + L2 table entries use an extended format th= at + allows subcluster-based allocation. See the + Extended L2 Entries section for more detai= ls. + + Bits 5-63: Reserved (set to 0) =20 80 - 87: compatible_features Bitmask of compatible features. An implementation can @@ -497,7 +505,7 @@ cannot be relaxed without an incompatible layout change= ). Given an offset into the virtual disk, the offset into the image file can = be obtained as follows: =20 - l2_entries =3D (cluster_size / sizeof(uint64_t)) + l2_entries =3D (cluster_size / sizeof(uint64_t)) [*] =20 l2_index =3D (offset / cluster_size) % l2_entries l1_index =3D (offset / cluster_size) / l2_entries @@ -507,6 +515,8 @@ obtained as follows: =20 return cluster_offset + (offset % cluster_size) =20 + [*] this changes if Extended L2 Entries are enabled, see next section + L1 table entry: =20 Bit 0 - 8: Reserved (set to 0) @@ -547,7 +557,8 @@ Standard Cluster Descriptor: nor is data read from the backing file if the cluster = is unallocated. =20 - With version 2, this is always 0. + With version 2 or with extended L2 entries (see the ne= xt + section), this is always 0. =20 1 - 8: Reserved (set to 0) =20 @@ -584,6 +595,57 @@ file (except if bit 0 in the Standard Cluster Descript= or is set). If there is no backing file or the backing file is smaller than the image, they shall = read zeros for all parts that are not covered by the backing file. =20 +=3D=3D Extended L2 Entries =3D=3D + +An image uses Extended L2 Entries if bit 4 is set on the incompatible_feat= ures +field of the header. + +In these images standard data clusters are divided into 32 subclusters of = the +same size. They are contiguous and start from the beginning of the cluster. +Subclusters can be allocated independently and the L2 entry contains infor= mation +indicating the status of each one of them. Compressed data clusters don't = have +subclusters so they are treated the same as in images without this feature. + +The size of an extended L2 entry is 128 bits so the number of entries per = table +is calculated using this formula: + + l2_entries =3D (cluster_size / (2 * sizeof(uint64_t))) + +The first 64 bits have the same format as the standard L2 table entry desc= ribed +in the previous section, with the exception of bit 0 of the standard clust= er +descriptor. + +The last 64 bits contain a subcluster allocation bitmap with this format: + +Subcluster Allocation Bitmap (for standard clusters): + + Bit 0 - 31: Allocation status (one bit per subcluster) + + 1: the subcluster is allocated. In this case the + host cluster offset field must contain a valid + offset. + 0: the subcluster is not allocated. In this case + read requests shall go to the backing file or + return zeros if there is no backing file data. + + Bits are assigned starting from the least significant + one (i.e. bit x is used for subcluster x). + + 32 - 63 Subcluster reads as zeros (one bit per subcluster) + + 1: the subcluster reads as zeros. In this case the + allocation status bit must be unset. The host + cluster offset field may or may not be set. + 0: no effect. + + Bits are assigned starting from the least significant + one (i.e. bit x is used for subcluster x - 32). + +Subcluster Allocation Bitmap (for compressed clusters): + + Bit 0 - 63: Reserved (set to 0) + Compressed clusters don't have subclusters, + so this field is not used. =20 =3D=3D Snapshots =3D=3D =20 diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt index d57f409861..5f763aa6bb 100644 --- a/docs/qcow2-cache.txt +++ b/docs/qcow2-cache.txt @@ -1,6 +1,6 @@ qcow2 L2/refcount cache configuration =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -Copyright (C) 2015, 2018 Igalia, S.L. +Copyright (C) 2015, 2018-2020 Igalia, S.L. Author: Alberto Garcia =20 This work is licensed under the terms of the GNU GPL, version 2 or @@ -222,3 +222,20 @@ support this functionality, and is 0 (disabled) on oth= er platforms. This functionality currently relies on the MADV_DONTNEED argument for madvise() to actually free the memory. This is a Linux-specific feature, so cache-clean-interval is not supported on other systems. + + +Extended L2 Entries +------------------- +All numbers shown in this document are valid for qcow2 images with normal +64-bit L2 entries. + +Images with extended L2 entries need twice as much L2 metadata, so the L2 +cache size must be twice as large for the same disk space. + + disk_size =3D l2_cache_size * cluster_size / 16 + +i.e. + + l2_cache_size =3D disk_size * 16 / cluster_size + +Refcount blocks are not affected by this. --=20 2.20.1