* [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps
@ 2026-11-09 15:36 Andrey Zhadchenko
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 1/2] dm-qcow2: set max discard segments to one Andrey Zhadchenko
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Andrey Zhadchenko @ 2026-11-09 15:36 UTC (permalink / raw)
To: khorenko, alexander.ivanov; +Cc: devel
The block layer may merge non-contiguous discard bios into a single
request when the queue allows more than one discard segment, and the
stacking default for dm is max_discard_segments = USHRT_MAX.
Both dm-qcow2 and dm-ploop handle a discard request as one contiguous
range taken from blk_rq_pos() and blk_rq_bytes(). For a request built
from bios [0, 512) and [1024, 1536) they discard [0, 1024), which hits
sectors that were never asked to be discarded and misses part of the
range that was.
Set max_discard_segments to 1 in both targets so each discard request
always describes a single contiguous range.
https://virtuozzo.atlassian.net/browse/VSTOR-154159
Andrey Zhadchenko (2):
dm-qcow2: set max discard segments to one
dm-ploop: set max discard segments to one
drivers/md/dm-ploop-target.c | 1 +
drivers/md/dm-qcow2-target.c | 1 +
2 files changed, 2 insertions(+)
--
2.43.5
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Devel] [PATCH hci-8.1 1/2] dm-qcow2: set max discard segments to one
2026-11-09 15:36 [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps Andrey Zhadchenko
@ 2026-11-09 15:36 ` Andrey Zhadchenko
2026-11-09 15:44 ` no-reply
2026-11-10 17:46 ` Konstantin Khorenko
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 2/2] dm-ploop: " Andrey Zhadchenko
` (3 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Andrey Zhadchenko @ 2026-11-09 15:36 UTC (permalink / raw)
To: khorenko, alexander.ivanov; +Cc: devel
Discard is a special type of request that can have non-contiguous
bios.
Imagine we have a request with starting sector 0 and length 1024,
so read or write means [0, 1024) range in the file. For discard this
request can have 2 bios [0, 512) and [1024, 1536), but we always
discarded [0, 1024).
Set max_discard_segments to 1 to avoid such merges.
https://virtuozzo.atlassian.net/browse/VSTOR-154159
Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
drivers/md/dm-qcow2-target.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 7c572bd66e1ca..8337efc5c6238 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -1053,6 +1053,7 @@ static void qcow2_io_hints(struct dm_target *ti, struct queue_limits *limits)
*/
limits->discard_granularity = sb->s_blocksize;
limits->max_hw_discard_sectors = to_sector(qcow2->clu_size);
+ limits->max_discard_segments = 1;
limits->logical_block_size = block_size;
limits->physical_block_size = block_size;
--
2.43.5
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Devel] [PATCH hci-8.1 2/2] dm-ploop: set max discard segments to one
2026-11-09 15:36 [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps Andrey Zhadchenko
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 1/2] dm-qcow2: set max discard segments to one Andrey Zhadchenko
@ 2026-11-09 15:36 ` Andrey Zhadchenko
2026-11-09 15:44 ` no-reply
2026-11-10 17:46 ` Konstantin Khorenko
2026-11-10 10:03 ` [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps Alexander Ivanov
` (2 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Andrey Zhadchenko @ 2026-11-09 15:36 UTC (permalink / raw)
To: khorenko, alexander.ivanov; +Cc: devel
Discard is a special type of request that can have non-contiguous
bios.
Imagine we have a request with starting sector 0 and length 1024,
so read or write means [0, 1024) range in the file. For discard this
request can have 2 bios [0, 512) and [1024, 1536), but we always
discarded [0, 1024).
Set max_discard_segments to 1 to avoid such merges.
https://virtuozzo.atlassian.net/browse/VSTOR-154159
Fixes: 6ddad5a4d226 ("dm-ploop: Add ploop target driver")
Feature: dm-ploop: ploop target driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
drivers/md/dm-ploop-target.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index d8279c79ef56d..b1f502d664447 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -661,6 +661,7 @@ static void ploop_io_hints(struct dm_target *ti, struct queue_limits *limits)
limits->max_hw_discard_sectors = CLU_TO_SEC(ploop, 1);
limits->discard_granularity = CLU_SIZE(ploop);
limits->discard_alignment = 0;
+ limits->max_discard_segments = 1;
limits->fua = BLK_NO_FUA;
}
--
2.43.5
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.1 1/2] dm-qcow2: set max discard segments to one
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 1/2] dm-qcow2: set max discard segments to one Andrey Zhadchenko
@ 2026-11-09 15:44 ` no-reply
2026-11-10 17:46 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: no-reply @ 2026-11-09 15:44 UTC (permalink / raw)
To: khorenko, alexander.ivanov, Andrey Zhadchenko; +Cc: devel
> Discard is a special type of request that can have non-contiguous
> bios.
> Imagine we have a request with starting sector 0 and length 1024,
> so read or write means [0, 1024) range in the file. For discard this
> request can have 2 bios [0, 512) and [1024, 1536), but we always
> discarded [0, 1024).
> Set max_discard_segments to 1 to avoid such merges.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-154159
> Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
> Feature: dm-qcow2: block device over QCOW2 files driver
> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261109153619.277888-1-andrey.zhadchenko@virtuozzo.com?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.1 2/2] dm-ploop: set max discard segments to one
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 2/2] dm-ploop: " Andrey Zhadchenko
@ 2026-11-09 15:44 ` no-reply
2026-11-10 17:46 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: no-reply @ 2026-11-09 15:44 UTC (permalink / raw)
To: alexander.ivanov, Andrey Zhadchenko, khorenko; +Cc: devel
> Discard is a special type of request that can have non-contiguous
> bios.
> Imagine we have a request with starting sector 0 and length 1024,
> so read or write means [0, 1024) range in the file. For discard this
> request can have 2 bios [0, 512) and [1024, 1536), but we always
> discarded [0, 1024).
> Set max_discard_segments to 1 to avoid such merges.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-154159
> Fixes: 6ddad5a4d226 ("dm-ploop: Add ploop target driver")
> Feature: dm-ploop: ploop target driver
> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261109153619.277888-1-andrey.zhadchenko@virtuozzo.com?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps
2026-11-09 15:36 [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps Andrey Zhadchenko
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 1/2] dm-qcow2: set max discard segments to one Andrey Zhadchenko
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 2/2] dm-ploop: " Andrey Zhadchenko
@ 2026-11-10 10:03 ` Alexander Ivanov
2026-11-10 17:46 ` Konstantin Khorenko
2026-11-10 17:47 ` Konstantin Khorenko
4 siblings, 0 replies; 10+ messages in thread
From: Alexander Ivanov @ 2026-11-10 10:03 UTC (permalink / raw)
To: Andrey Zhadchenko, khorenko; +Cc: devel
LGTM
On 11/9/26 16:36, Andrey Zhadchenko wrote:
> The block layer may merge non-contiguous discard bios into a single
> request when the queue allows more than one discard segment, and the
> stacking default for dm is max_discard_segments = USHRT_MAX.
>
> Both dm-qcow2 and dm-ploop handle a discard request as one contiguous
> range taken from blk_rq_pos() and blk_rq_bytes(). For a request built
> from bios [0, 512) and [1024, 1536) they discard [0, 1024), which hits
> sectors that were never asked to be discarded and misses part of the
> range that was.
>
> Set max_discard_segments to 1 in both targets so each discard request
> always describes a single contiguous range.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-154159
>
> Andrey Zhadchenko (2):
> dm-qcow2: set max discard segments to one
> dm-ploop: set max discard segments to one
>
> drivers/md/dm-ploop-target.c | 1 +
> drivers/md/dm-qcow2-target.c | 1 +
> 2 files changed, 2 insertions(+)
>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps
2026-11-09 15:36 [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps Andrey Zhadchenko
` (2 preceding siblings ...)
2026-11-10 10:03 ` [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps Alexander Ivanov
@ 2026-11-10 17:46 ` Konstantin Khorenko
2026-11-10 17:47 ` Konstantin Khorenko
4 siblings, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-10 17:46 UTC (permalink / raw)
To: Andrey Zhadchenko; +Cc: devel
Applying with these fixes on my side:
- 1/2: the example replaced with one that can happen on dm-qcow2,
with units, plus what the user sees
- 2/2: the example replaced with one that loses data on dm-ploop,
plus what the user sees
- both: "range in the file" -> "range of the device", "always"
dropped, why the limit is USHRT_MAX, paragraphs
On Mon, 09 Nov 2026 18:36:17 +0300, Andrey Zhadchenko wrote:
> Both dm-qcow2 and dm-ploop handle a discard request as one contiguous
> range taken from blk_rq_pos() and blk_rq_bytes(). For a request built
> from bios [0, 512) and [1024, 1536) they discard [0, 1024), which hits
> sectors that were never asked to be discarded and misses part of the
> range that was.
Read in sectors, a 1024-sector discard request cannot be built on
dm-qcow2 with the default 64K cluster: max_hw_discard_sectors is one
cluster, and the merge is refused past it. On dm-ploop the example is
half a cluster, and ploop ignores discards that do not cover a whole
cluster, so nothing is lost there. The patch messages now carry an
example per target.
dm-tracking and dm-push-backup need the same limit, I filed a bug for
that:
https://virtuozzo.atlassian.net/browse/VSTOR-154423
Both take a discard request as one blk_rq_pos()/blk_rq_bytes() range,
and they inherit max_discard_segments from the origin. Over a patched
ploop or qcow2 that is 1, but over an origin with multi-range discard
(nvme, virtio-blk) they track the wrong clusters. Please send a
separate patch that gives both targets .io_hints with
max_discard_segments = 1.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.1 1/2] dm-qcow2: set max discard segments to one
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 1/2] dm-qcow2: set max discard segments to one Andrey Zhadchenko
2026-11-09 15:44 ` no-reply
@ 2026-11-10 17:46 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-10 17:46 UTC (permalink / raw)
To: Andrey Zhadchenko; +Cc: devel
Applying with these fixes on my side:
- the example: bios [0, 8) and [16, 24) in sectors instead of
[0, 512) and [1024, 1536) with no unit
- "range in the file" -> "range of the device", "always" dropped
- added why the limit is USHRT_MAX and what the user sees, split into
paragraphs
On Mon, 09 Nov 2026 18:36:18 +0300, Andrey Zhadchenko wrote:
> Imagine we have a request with starting sector 0 and length 1024,
> so read or write means [0, 1024) range in the file. For discard this
> request can have 2 bios [0, 512) and [1024, 1536), but we always
> discarded [0, 1024).
qcow2_io_hints() caps max_hw_discard_sectors at one cluster, so with
the default 64K cluster a 1024-sector request is never built.
blk_rq_pos() is an offset on the device, the file offset comes from the
L2 table. The message now reads:
Discard is a special type of request that can have non-contiguous
bios: dm-qcow2 keeps the dm stacking default max_discard_segments =
USHRT_MAX, so the block layer merges discard bios with gaps.
Imagine we have a request with starting sector 0 and length 16
sectors, so read or write means the [0, 16) range of the device. For
discard this request can have 2 bios [0, 8) and [16, 24), but we
discarded [0, 16).
Data in sectors 8-15 reads back as zeroes, and sectors 16-23 are not
discarded.
Set max_discard_segments to 1 to avoid such merges.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.1 2/2] dm-ploop: set max discard segments to one
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 2/2] dm-ploop: " Andrey Zhadchenko
2026-11-09 15:44 ` no-reply
@ 2026-11-10 17:46 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-10 17:46 UTC (permalink / raw)
To: Andrey Zhadchenko; +Cc: devel
Applying with these fixes on my side:
- the example: a whole 1M cluster [0, 2048) built from bios [0, 1024)
and [2048, 3072), instead of [0, 512) and [1024, 1536)
- "range in the file" -> "range of the device", "always" dropped
- added why the limit is USHRT_MAX and what the user sees, split into
paragraphs
On Mon, 09 Nov 2026 18:36:19 +0300, Andrey Zhadchenko wrote:
> Imagine we have a request with starting sector 0 and length 1024,
> so read or write means [0, 1024) range in the file. For discard this
> request can have 2 bios [0, 512) and [1024, 1536), but we always
> discarded [0, 1024).
ploop_handle_discard_pio() ignores a discard that is not a whole
cluster, so with the default 1M cluster this request discards nothing.
Data is lost only when a gapped request adds up to a whole cluster. The
message now reads:
Discard is a special type of request that can have non-contiguous
bios: dm-ploop keeps the dm stacking default max_discard_segments =
USHRT_MAX, so the block layer merges discard bios with gaps.
Imagine we have 1M clusters and a request with starting sector 0 and
length 2048 sectors, so read or write means the [0, 2048) range of
the device. For discard this request can have 2 bios [0, 1024) and
[2048, 3072), but we discarded the whole cluster [0, 2048).
Data in sectors 1024-2047 reads back as zeroes.
Set max_discard_segments to 1 to avoid such merges.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps
2026-11-09 15:36 [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps Andrey Zhadchenko
` (3 preceding siblings ...)
2026-11-10 17:46 ` Konstantin Khorenko
@ 2026-11-10 17:47 ` Konstantin Khorenko
4 siblings, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-10 17:47 UTC (permalink / raw)
To: alexander.ivanov, Andrey Zhadchenko; +Cc: devel
On Mon, 09 Nov 2026 18:36:17 +0300, Andrey Zhadchenko wrote:
> dm-qcow2, dm-ploop: do not merge discards with gaps
>
> The block layer may merge non-contiguous discard bios into a single
> request when the queue allows more than one discard segment, and the
> stacking default for dm is max_discard_segments = USHRT_MAX.
>
> Both dm-qcow2 and dm-ploop handle a discard request as one contiguous
> range taken from blk_rq_pos() and blk_rq_bytes(). For a request built
> from bios [0, 512) and [1024, 1536) they discard [0, 1024), which hits
> sectors that were never asked to be discarded and misses part of the
> range that was.
>
> [...]
Applied to branch-rh10-6.12.0-211.52.1.22.x.vz10-ovz, will be released in rh10-6.12.0-211.52.1.22.20.vz10, thanks!
[1/2] dm-qcow2: set max discard segments to one
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/1a8f0cbc0978
[2/2] dm-ploop: set max discard segments to one
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/1d5a66073e68
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-10 17:48 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 15:36 [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps Andrey Zhadchenko
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 1/2] dm-qcow2: set max discard segments to one Andrey Zhadchenko
2026-11-09 15:44 ` no-reply
2026-11-10 17:46 ` Konstantin Khorenko
2026-11-09 15:36 ` [Devel] [PATCH hci-8.1 2/2] dm-ploop: " Andrey Zhadchenko
2026-11-09 15:44 ` no-reply
2026-11-10 17:46 ` Konstantin Khorenko
2026-11-10 10:03 ` [Devel] [PATCH hci-8.1 0/2] dm-qcow2, dm-ploop: do not merge discards with gaps Alexander Ivanov
2026-11-10 17:46 ` Konstantin Khorenko
2026-11-10 17:47 ` Konstantin Khorenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.