[Devel] [PATCH hci-8.2 0/9] dm-qcow2: lockless fast path, direct completion, no I/O scheduler

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Thu Nov 26 16:58:52 MSK 2026


My few points:

1. I don't like rcu, smp_wb, etc. dances around md_pages validity. It is 
too complicated and also looks like reinventing the wheel. I had another 
idea in my mind for a while:
  - change md_pages container from rbtree to xarray. It is tailored to 
page-tables which md_pages essentially are. We get the access and store 
helpers with known guarantees out of the box, so we don't need to dance 
with synchronisation primitives. Also it is more efficient than rbtree.
  - add new 'staging' rbtree (or whatever) where pages lie when they are 
constructed. Only when the pages are ready they are published to main 
xarray.

2. I don't like MANUAL dances around md->gen. What you want here is 
seqcount_spinlock_t (write_seqcount_begin() + write_seqcount_end() for 
writer and raw_read_seqcount() + read_seqcount_retry() for reader). Your 
code more or less implements that instead of using existing primitives.

3. I really like new dm_complete_request_direct() because it helps us to 
get rid of dm_nr_hw_queues() and reduces qd1 latency. This is a real gain.

4. I don't like parse_metadata_lockless() as this just a duplicate of 
parse_metadata() with a few quirks. It potentially doubles any 
maintainer or submitter work while changing metadata parsing. It 
introduces complex synchronization steps with many edge cases.

4. I don't buy the speed measurements.
Here what I got:

fio with randwrite, 4K size, io_uring, iodepth=64. dm_mq_nr_hw_queues=8 
for patchset 1 and dm_mq_nr_hw_queues=1 for all other. Value is IOPS.
Baseline is raw file on ext4 formatted ramdisk. patchset1 is fastpath 
patchset, patchset 2 is this patchset, patchset 1+2-lockless does not 
include patches that turn fast read into lockless.

       baseline    patchset 1   patchset 1+2   patchset 1+2-lockless
1thr   388K         371K           428K                426K
2thr   781K         819K           811K                817K
4thr  1471K        1171K          1167K               1119K
8thr  2222K        1453K          1398K               1360K

randwrite, 4K size, io_uring, iodepth=1; IOPS/latency p99, us

       baseline    patchset 1   patchset 1+2   patchset 1+2-lockless
1thr  396K/2.27    113K/8.45     145K/6.57           140K/6.8

My machine is Xeon E-2136, 6 cores / 12 threads, so 4thread is the last 
point under 100% cpu for dm-based devices.


So my final opinion:
  - direct complete we should take anyway, this a big win
  - lockless part is a benchmaxxxing and we should consider our IOPS 
targets before taking it.
Introduced complexity is big (even if we use existing primitives instead 
of re-implementing them with barriers) but the win is negligible on any 
real scenarios. If you run this with 1000 submitters spinlock will 
perform even worse, but what's the point? 4threads have more or less the 
same 5GB/s performance with tiny-tiny 4K request size. What is real-case 
scenario? What is the values we want to achieve? As far as I remember 
our target was 1M IOPS.
This all also looks like premature optimization. I think the next steps 
should be parallelizing metadata changes to different md pages. For this 
we will potentially need per-md page lock which will also naturally 
reduce md_pages_lock contention even if we take this per-md page lock on 
fast path.

P.S. Also looks L1 page is mostly full of never-changing constants. If 
we set some index and it has LX_REFCOUNT_EXACTLY_ONE it never changes 
afterwards. So maybe we can fully skip any synchronization on L1 page if 
we have a bitmap of such indexes. Or we can probably just create a plain 
l2 array instead (32Kb per 1Tb disk with l2 and clu_size 1Mb) and never 
really use L1 page, only keep it coherent.

On 11/25/26 02:25, Denis V. Lunev wrote:
> On top of Andrey's "dm-qcow2: per-qio fast path" v3 [1] the fast path still
> serializes on md_pages_lock and deferred_lock, every request completes
> through BLOCK_SOFTIRQ (usually in ksoftirqd), and the device runs under
> mq-deadline. This series maps fast path reads and overwrites without
> md_pages_lock (a per md page generation counter, md pages freed after an
> RCU grace period), submits without deferred_lock, completes dm-qcow2
> requests directly in the worker, and makes dm-qcow2 default to no I/O
> scheduler. dm-qcow2 and dm-ploop now requeue a request instead of
> failing it when the request pool is empty, since without mq-deadline
> the queue is deeper than the pools were sized for.
> 
> The series applies on top of v3 [1] rebased to hci-8.2.
> 
> The scheduler default is the largest single step. mq-deadline caps a
> device at 256 requests in flight (2 * min(depth, BLKDEV_DEFAULT_RQ)), so a
> guest disk with several virtqueues is throttled to that regardless of its
> queue sizes, and its dispatch lock serializes all submitters: v3 under
> mq-deadline does fewer IOPS with 24 jobs than with 8. dm-qcow2 does not
> reorder or merge anything the elevator could help with, the backing file's
> own queue still has its scheduler, and IO limits (blk-throttle) act on bios
> before the elevator. What is lost is I/O priority class arbitration on the
> dm device; mq-deadline can still be selected through sysfs.
> 
> 4K random I/O, iodepth 32 per job, brd-backed ext4, 1M clusters, fio jobs
> one per core across all NUMA nodes, the same patches on the hci-8.1
> kernel, kIOPS / p99 us:
> 
>                         v3              v3            this series
>                     (mq-deadline)     (none)          (none, default)
>    read,   8 jobs     550 /  848     1554 /  578       1836 /  191
>    read,  24 jobs     384 / 2040     1690 / 1401       4308 /  214
>    write,  8 jobs     547 /  971     1353 /  627       1663 /  177
> 
>    raw file on the same ext4: read 8 jobs 2162, 24 jobs 5377, write 8 jobs 1859
> 
> One job, same columns. QD1 as kIOPS / us per request (1 / IOPS) / p99 us,
> QD32 as kIOPS / p99 us:
> 
>    read,  QD1       80 / 12.5 / 11   87 / 11.5 / 11   105 /  9.5 /  8
>    write, QD1       78 / 12.8 / 11   83 / 12.0 / 11    99 / 10.1 /  9
>    read,  QD32         258 / 171        320 / 114         359 / 102
>    write, QD32         256 / 167        304 / 129         339 / 107
> 
>    raw file: QD1 read 3.5 us, write 3.8 us per request
> 
> Tested on hci-8.2 (26.4) in a VM: ploop-pytest for the qcow2 and ploop
> formats, data verification under concurrent read/write/discard. The
> same checks passed on hci-8.1.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-95494
> 
> [1] http://lore.virtuozzo.com/kernel/20261113111126.793039-1-andrey.zhadchenko@virtuozzo.com/
> 
> Denis V. Lunev (9):
>    dm-qcow2: move md_pages_lock off the deferred_lock cache line
>    dm-qcow2: free md pages after an RCU grace period
>    dm-qcow2: map fast path reads without md_pages_lock
>    dm-qcow2: map fast path writes without md_pages_lock
>    dm-qcow2: submit fast path qios without deferred_lock
>    dm-rq: complete dm-qcow2 requests directly in task context
>    dm-qcow2: requeue requests when the request pool is empty
>    dm-ploop: requeue requests when the request pool is empty
>    dm: default dm-qcow2 devices to no I/O scheduler
> 
>   drivers/md/dm-ploop-map.c     |   2 +-
>   drivers/md/dm-ploop.h         |   3 +-
>   drivers/md/dm-qcow2-cmd.c     |  10 +-
>   drivers/md/dm-qcow2-map.c     | 182 ++++++++++++++++++++++++++++------
>   drivers/md/dm-qcow2-target.c  |  43 ++++++--
>   drivers/md/dm-qcow2.h         |  33 +++++-
>   drivers/md/dm-rq.c            |  22 ++++
>   drivers/md/dm-rq.h            |   1 +
>   drivers/md/dm-zero-rq.c       |   2 +-
>   include/linux/device-mapper.h |   5 +
>   10 files changed, 260 insertions(+), 43 deletions(-)
> 



More information about the Devel mailing list