OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@virtuozzo.com>
To: Vasileios Anagnostoulis <vasileios.anagnostoulis@virtuozzo.com>,
	Konstantin Khorenko <khorenko@virtuozzo.com>,
	"Denis V. Lunev" <den@openvz.org>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.2] dm-qcow2: report the unit L2 can unmap as discard granularity
Date: Wed, 25 Nov 2026 19:17:04 +0100	[thread overview]
Message-ID: <3837291d-019b-438e-8d4d-020fb1281e5b@virtuozzo.com> (raw)
In-Reply-To: <20261125-br-vstor-154496-v1-1-dd8d86661647@virtuozzo.com>

On 11/25/26 12:16, Vasileios Anagnostoulis wrote:
> This is the first email you've received from this external sender.
> Do not click links or open attachments unless it is an email you expected to receive.
> 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 <vasileios.anagnostoulis@virtuozzo.com>
> ---
> 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,
run /kslop over this please :-)
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-11-25 18:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 11:16 Vasileios Anagnostoulis
2026-11-25 18:17 ` Denis V. Lunev [this message]
2026-12-01  0:13 ` no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3837291d-019b-438e-8d4d-020fb1281e5b@virtuozzo.com \
    --to=den@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=vasileios.anagnostoulis@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox