From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 7836D8002A for ; Wed, 25 Nov 2026 11:17:50 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6APBGWvp012296; Wed, 25 Nov 2026 14:16:33 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6APBGWvp012296 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="QVqamGow" Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6APBGU9Z012292 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 25 Nov 2026 14:16:31 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6APBGU9Z012292 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-c49df8fe86eso449513366b.2 for ; Wed, 25 Nov 2026 03:16:30 -0800 (PST) X-Gm-Message-State: APuU4Z/vE/NZVK7GdJI1U8HaSGJzZezEMJeMinBDKd7aSi+CbfTM9dkB jdb/hCwEdwv+Nm0wsXqHOkWEfo3jq5uhD928rBaUkPE5IpDj15xxs/4XU86VuUl6vw2uOR8zwRX 6kCaFA6GbDM+PD5IY453ble2x5NUt8bWNLqBkCpg4NQgdxF+Jy/b5+w== X-Gm-Gg: AZFdTZeieXOr4bK5IDy4CTBYzUDC29+I95zy190ikCLb4SHV+M2DgNBqhAzcOwLaPjN qUbaPg+WiIqHyIz5QCztF75lXVz0StN1GJo0P6kmMU9LTY03ZfvpjDeyg86Fyp6vmjOMNy55OvS /1tzES5VACHMCwbRHs8d0K61tOvaqkzrYiLY5XPPTJqYsqbNTgWiwiZfkLIaX60FWPyUTI6tFrI fTLwYVJ94wrUkWUHzX3OctxwlI1fG/Ko+bypXml6icIKWinwVEB+IMYI+hzZ8nnj1az2lqr4q8l Z94cC8x4R/MHxgnIyVLsY5T2KmS3jI/xiAio9CUnqtoDRu11zjmkXH1kEt0x2SpmlVixSWQbH8o pOkgThqLaIqsThdd99BDAX3luYz2yv9KsAe7Xhw== X-Received: by 2002:a17:907:3d10:b0:c46:cf73:bdf9 with SMTP id a640c23a62f3a-c513aacef81mr1414841466b.21.1795605390613; Wed, 25 Nov 2026 03:16:30 -0800 (PST) X-Received: by 2002:a17:907:3d10:b0:c46:cf73:bdf9 with SMTP id a640c23a62f3a-c513aacef81mr1414837566b.21.1795605390118; Wed, 25 Nov 2026 03:16:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795605390; cv=none; d=google.com; s=arc-20260327; b=p8rrhrgqr+i2m1vDQQIc57K+7hteu6rGrtib2ItDmbRUFSnrd70UCxsZHzNYbtEcDq F9r9lAQl0RGeCWvfAQH0EJYDP2rFDijtJqcDKTK6iTLSHxkx6g/HQhoyKRLHHV6AVPN7 iEkqs6EK35KKiOyzfjK0z3ckWhGHXVKKZqd1CTPAG5+/e8DEkzAMW/dl6ASGDTL+9lcZ 8nZ9jQVX5lwceti6cMQyrLYOTm/UMTVfiPup7ZWRj/xM7B2a9loNuV2vsmVds54q4+od uREMh4Kefx+NvffEXi2Af7Bt71bA0IQa8Z0MiXlCleWvks6smDhujmQBTYELiV+ReTJm FTPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:dkim-signature; bh=6YhX4ZaZ84Hkae+0WpYx0p8KLQjcSpAvbRRSA43AZlM=; fh=zeBvfB7+ipsrI1qip0vSMF3oDCpDz4Y7vu/URm7U5Kw=; b=hFWgFMPytzuo168tyXHS3zwdTADJtYFfF2uzvpGOwrufNe0TDHy7Z/9CZuKW6Yt0r+ ZevUY2uURrus+ukkkZpLw+/iw9vuzFESyMMHT8BR9Uf13Shx/A+OCylwSKUeyJ2CievC vViSmn50PcVmDFEtJJPi9sliryDYmz9ZiQH2QKc2kGdtrJDNrlWdDNOXisHKjfRfIH2i TdZRatfHUYKebrnp62uWH0HdQYE/AV5ejhmC1UseHpIcqeN3rijUUL9Wvhv6oKQW7btG 1kyIyGJJTH0HT4uV/PC/Gj0Qyj+rhJVkqGJ0HBase/vPKvj/tKI1BJUZQmXSXBFAI+K7 TmxQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=QVqamGow; spf=pass (google.com: domain of vasileios.anagnostoulis@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vasileios.anagnostoulis@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id a640c23a62f3a-c513b0a1dedsi1110985266b.284.2026.11.25.03.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2026 03:16:30 -0800 (PST) Received-SPF: pass (google.com: domain of vasileios.anagnostoulis@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=QVqamGow; spf=pass (google.com: domain of vasileios.anagnostoulis@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vasileios.anagnostoulis@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=6YhX4ZaZ84Hkae+0WpYx0p8KLQjcSpAvbRRSA43AZlM=; b=QVqamGowZP6DEKvbNev mRq8mgzZlW8l7ZUPfPRB0C/SgHVFk1kUYEhB7AkMz5rbls/hlOurTf1J2B9oR21IOAMjqNPzHCyiX Z3AjUxEJJ1sNEr2EGgNJ/OaTVFuxVxwRg3A69nAi6kkanWYkSjm7MccHr4DK092gY+bHrhhFhj33+ 7au0i25m2jfXm0YVVuvVGblKZXFz0XnijupOSYffN7uX4PdviarXWlCFeMqd0DK39FfICc8ni8NY/ HaQ2B3ooA8mhmVLAfDCWtU7N8Zj9HdEiorM3lq4Pd7i8m+H81foOe4H0/00qOesYUIKqRYTwD564F oVm6arZGPI4njdg==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=[127.0.1.1]) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xWAz3-008IVQ-2H; Wed, 25 Nov 2026 12:16:28 +0100 From: Vasileios Anagnostoulis Date: Wed, 25 Nov 2026 13:16:15 +0200 MIME-Version: 1.0 Message-Id: <20261125-br-vstor-154496-v1-1-dd8d86661647@virtuozzo.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/x3MQQ5AMBBA0avIrI20k1ZwFbHQGswGmYpIxN01l m/x/wOJVThBVzygfEmSfcuwZQFxHbeFUaZsIEO1teQxKF7p3BWtd66t0ZFvTPAmzoEgV4fyLPd /7GGNgk1FMLzvB4CcZZhqAAAA X-Change-ID: 20261125-br-vstor-154496-42580b50cfb2 To: Konstantin Khorenko , "Denis V. Lunev" X-Mailer: b4 0.14.3 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2] dm-qcow2: report the unit L2 can unmap as discard granularity X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org qcow2_io_hints() reports the block size of the host file system as discard_granularity and one cluster as max_hw_discard_sectors. bio_split_discard() cuts a longer discard into pieces of max_discard_sectors and aligns each split point only to discard_granularity, i.e. to 4K. A discard that does not start on a cluster boundary is therefore cut at the same offset inside every cluster it spans. dm-qcow2 unmaps only a subcluster (with extended_l2) or a cluster (without it) that a single discard qio covers entirely. The unit under each split point is covered by two qios, each only in part, so neither unmaps it: its host blocks are punched, but it stays allocated in L2 and the cluster stays allocated in the refcount table. Every long discard leaves such a unit behind in each cluster it spans, whether it comes from the FITRIM of ploop-balloon discard or from fstrim inside a Container. On a 512M image with 1M clusters and extended_l2, one FITRIM after freeing half of ext4 left 83 clusters that ext4 no longer uses mapped, each with exactly one 32K subcluster still allocated. Report the unit L2 can unmap as discard_granularity: the subcluster with extended_l2, the cluster otherwise. bio_split_discard() then cuts discards on unit boundaries. dm-ploop already reports its cluster. https://virtuozzo.atlassian.net/browse/VSTOR-154496 Fixes: 2a728299abdb ("dm-qcow2: Introduce driver to create block devices over QCOW2 files") Feature: dm-qcow2: block device over QCOW2 files driver Signed-off-by: Vasileios Anagnostoulis --- Tested on 6.12.0-211.75.1.24.1.vz10, with dm-qcow2 rebuilt from the rh10-6.12.0-211.75.1.24.1.vz10 sources plus this patch and loaded in place of the stock module. qcow2_io_hints() and the discard path are the same there as on hci-8.2. Ploop test suite (ploop.ovz, test/): # python3 -m pytest tests/test_ploop_balloon.py -k shrunk_offline \ --format qcow2 --bug-id VSTOR-154496 test_ploop_balloon_discard_should_release_removed_data_when_image_shrunk_offline PASSED This is the reproducer from VSTOR-154496 (512M image, 1M clusters, extended_l2). Without the fix, 83 clusters that ext4 no longer used stayed mapped after the FITRIM. # python3 -m pytest tests/test_ploop_balloon.py --format qcow2 33 passed, 23 deselected The reproducer is among the deselected tests: the suite runs it only with --bug-id, as above. --- drivers/md/dm-qcow2-target.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c index d445bfe1232a..a343266fb1be 100644 --- a/drivers/md/dm-qcow2-target.c +++ b/drivers/md/dm-qcow2-target.c @@ -1117,10 +1117,15 @@ static void qcow2_io_hints(struct dm_target *ti, struct queue_limits *limits) if (sb->s_bdev) block_size = bdev_logical_block_size(sb->s_bdev); /* - * Even if this is less than discard_granularity of bdev, - * we can free a block on filesystem. + * Report the unit L2 can unmap: the subcluster with extended L2, + * the cluster otherwise. The block layer aligns discard split + * points to this granularity only; with a smaller one, a long + * discard that starts mid-cluster is split at the same offset + * inside every cluster, and the (sub)cluster under each split is + * covered only in part by both pieces, so neither unmaps it. */ - limits->discard_granularity = sb->s_blocksize; + limits->discard_granularity = qcow2->ext_l2 ? qcow2->subclu_size : + qcow2->clu_size; limits->max_hw_discard_sectors = to_sector(qcow2->clu_size); limits->max_discard_segments = 1; --- base-commit: aef96420256e57bf1291859a844800a462f2790e change-id: 20261125-br-vstor-154496-42580b50cfb2 Best regards, -- Vasileios Anagnostoulis _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel