[blk-threaded - 5/5] block: add virtio-blk multiqueue - #6197
PierreBertholom wants to merge 9 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feature/virtio-blk-threaded #6197 +/- ##
===============================================================
+ Coverage 82.84% 82.86% +0.01%
===============================================================
Files 278 278
Lines 32028 32180 +152
===============================================================
+ Hits 26535 26665 +130
- Misses 5493 5515 +22
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
b8f2eff to
dbbe406
Compare
189c34d to
9b42f24
Compare
9b42f24 to
a3ada00
Compare
a3ada00 to
152320f
Compare
152320f to
31afecd
Compare
31afecd to
90dfb97
Compare
90dfb97 to
7859850
Compare
7859850 to
7937846
Compare
7937846 to
c69fe28
Compare
3123f2f to
1629165
Compare
1629165 to
47e3311
Compare
47e3311 to
c1ae0ce
Compare
c1ae0ce to
b51fb22
Compare
| resources.len(), | ||
| "one worker must be spawned for each block queue" | ||
| ); | ||
| let queue_config = resources.iter().map(|r| r.queue.config.clone()).collect(); |
There was a problem hiding this comment.
queue_configs to make it clear that this is an array
| for handle in active.worker_handles { | ||
| handle.finish(flush_mode); | ||
| } |
There was a problem hiding this comment.
All workers of the same block share the underlying file (they dupe the fd, but the file is same), so you only need to flush once and it can be done from the main thread (or just first worker thread)
There was a problem hiding this comment.
applied, now n-1 workers drain and the last one drains and flush, also applied to prepare_save()
| fn register_runtime_events(&self, ops: &mut EventOps) { | ||
| if let Err(err) = ops.add(Events::with_data( | ||
| &self.resources().queue_evt, | ||
| &self.resources()[0].queue_evt, |
There was a problem hiding this comment.
I think it is worth adding an assert here as well to ensure resources().len() == 1 (and in couple other places where [0] is used assuming a inline threaded version)
| if num_queues > 1 { | ||
| avail_features |= 1u64 << VIRTIO_BLK_F_MQ; | ||
| } |
There was a problem hiding this comment.
The spec says that VIRTIO_BLK_F_MQ just enables num_queues field and since it always exist now, we can enable this feature unconditionally
The block `ConfigSpace` already has a `num_queues` field, but it is always 0. Default it to 1 and make `num_queues()` report its value. Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
Store runtime resources and parked workers in vectors before activation. After activation, keep one worker handle and queue config per queue. Update reset, disk updates, rate-limit kicks, teardown, and persistence to iterate over every queue. All queues share the same backing file, so only the last worker flushes it on snapshot and teardown while the others only drain their pending I/O. Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
Virtio drivers can use fewer queues than the device exposes. Keep unused queues uninitialized while their workers remain available for renegotiation. Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
Replace the `threaded` drive option with an optional `num_queues`. When it is set, the drive is processed on dedicated worker threads. When it is unset, the drive keeps using the VMM thread. Use the same representation in the virtio-block configuration so threading is derived from `num_queues`, and reject `num_queues` for vhost-user block devices. The device keeps exposing a single queue until multiqueue is enabled. Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
Reject a queue count greater than the vCPU count when a drive is configured, loaded from the config file or hotplugged, and reject a vCPU count update below an existing drive's queue count. The check lives in `MachineConfig` so other multiqueue devices can reuse it. A queue count of zero is rejected when parsing the `NonZeroU16` field. Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
Create one queue with its own resources for each configured queue. Advertise VIRTIO_BLK_F_MQ unconditionally, since the config space always reports the queue count. Restore rebuilds one slot per saved queue and checks that multi-queue snapshots offer VIRTIO_BLK_F_MQ and that threaded mode matches the queue count. Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
Cover API validation, block hotplug, guest I/O, and snapshot restore. Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
Describe threaded processing, multiqueue limits, and worker resources. Document seccomp requirements and partial updates across queues. Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
Document the new `num_queues` virtio-block drive option. Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
b51fb22 to
4bdcf5c
Compare
[5/5] part of the PR stack starting with #6123
Extend threaded virtio-block from one queue to multiple queues.
Changes
num_queuesto the API configuration and virtio config space.VIRTIO_BLK_F_MQwhen the device has multiple queues.BlockResourcesvalue and one worker for each configured queue.