virtio: reduce guest memory accesses on queue hot path#3151
Open
jstarks wants to merge 2 commits intomicrosoft:mainfrom
Open
virtio: reduce guest memory accesses on queue hot path#3151jstarks wants to merge 2 commits intomicrosoft:mainfrom
jstarks wants to merge 2 commits intomicrosoft:mainfrom
Conversation
The virtio queue implementation was doing expensive guest memory writes (kick arming/suppression) on every call to is_available(), even when the device was just draining a batch and had no intention of sleeping. This added unnecessary overhead on the hot path, particularly for high-throughput devices like virtio-net. Restructure notification handling so that is_available() is a lightweight read-only check, kick arming is deferred to the actual sleep boundary (poll_kick), and suppression happens lazily when work is found while armed. The split queue caches avail_index to drain batches with a single read, and the packed queue reads only the 2-byte flags field instead of the full 16-byte descriptor for availability checks. Burette TCP tx throughput improves by 31% on nested KVM, UDP tx by 48%. TCP rx is unchanged.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes virtio queue hot-path performance by restructuring notification (kick) arming/suppression so that availability checks avoid unnecessary guest-memory writes, reducing overhead for high-throughput virtio devices.
Changes:
- Refactors split-queue availability checks to cache
avail_indexand defer kick arming to the sleep boundary. - Refactors packed-queue availability checks to read only the descriptor flags (instead of the full descriptor) and adds explicit kick arm/suppress APIs.
- Introduces core-level tracking of whether kicks are currently armed, and updates
poll_kick()to arm only when actually sleeping.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vm/devices/virtio/virtio_spec/src/lib.rs | Adds/clarifies documentation for packed-queue event suppression flags. |
| vm/devices/virtio/virtio/src/queue/split.rs | Caches avail_index and splits “availability” from “arm/suppress kicks”. |
| vm/devices/virtio/virtio/src/queue/packed.rs | Makes is_available() a lightweight flags-only read; adds arm/suppress kick methods. |
| vm/devices/virtio/virtio/src/queue.rs | Tracks armed state in QueueCoreGetWork and suppresses kicks lazily when work is found. |
| vm/devices/virtio/virtio/src/common.rs | Changes poll_kick() to arm for kick only at the sleep boundary. |
chris-oo
reviewed
Mar 30, 2026
| /// `None` is returned, the caller must call [`arm_kick`](Self::arm_kick) | ||
| /// before sleeping to ensure the guest will send a kick when new work | ||
| /// arrives. | ||
| pub fn is_available(&mut self) -> Result<Option<u16>, QueueError> { |
Member
There was a problem hiding this comment.
Is there value in returning something other than an option to make this behavior more explicit? This sounds like a bug waiting to happen, IE caller forgot to call arm_kick.
Member
There was a problem hiding this comment.
Or is the intention that most callers should not call this directly, and use the poll wrappers in common.rs?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The virtio queue implementation was doing expensive guest memory writes (kick arming/suppression) on every call to is_available(), even when the device was just draining a batch and had no intention of sleeping. This added unnecessary overhead on the hot path, particularly for high-throughput devices like virtio-net.
Restructure notification handling so that is_available() is a lightweight read-only check, kick arming is deferred to the actual sleep boundary (poll_kick), and suppression happens lazily when work is found while armed. The split queue caches avail_index to drain batches with a single read, and the packed queue reads only the 2-byte flags field instead of the full 16-byte descriptor for availability checks.
Burette TCP tx throughput improves by 31% on nested KVM, UDP tx by 48%. TCP rx is unchanged.