net: remove unnecessary locking from RX buffer pools#3152
Merged
jstarks merged 2 commits intomicrosoft:mainfrom Mar 30, 2026
Merged
net: remove unnecessary locking from RX buffer pools#3152jstarks merged 2 commits intomicrosoft:mainfrom
jstarks merged 2 commits intomicrosoft:mainfrom
Conversation
The RX buffer pools in virtio-net and GDMA/BNIC were wrapped in Arc<Mutex<>> (or Arc<Vec<Mutex<>>>), but they are only ever accessed from the single task that runs the queue. The locking was vestigial from an earlier design where the pool was shared. Removing it simplifies the code--no more Arc cloning, scratch buffers, or lock() calls on every buffer operation. Only TX throughput improved measurably with this change, and only by a couple percent, but the code is simpler and easier to reason about, so we'll take it.
Contributor
There was a problem hiding this comment.
Pull request overview
Removes vestigial locking/Arc indirection around RX buffer pools in virtio-net and GDMA/BNIC by making the pools task-local, simplifying buffer management and reducing per-packet overhead.
Changes:
virtio-net: removesActiveState.memand uses the RX pool’sGuestMemory; replaces “collect ready IDs” allocation with an in-placefill_readycall.virtio-netbuffers: replacesArc<Vec<Mutex<...>>>withVec<Option<...>>and adjusts APIs to require&mut selfwhere mutation occurs.- GDMA/BNIC: replaces
Arc<Mutex<Slab<_>>>+ scratch cloning with a task-localSlab<_>stored inGuestBuffers.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| vm/devices/virtio/virtio_net/src/lib.rs | Switches queue restart + TX header reads to use the RX pool as the single owner of GuestMemory and removes clone/lock-based ready collection. |
| vm/devices/virtio/virtio_net/src/buffers.rs | Makes the virtio RX work pool single-owner (no Arc<Mutex<...>>), adds fill_ready and exposes mem() accessor. |
| vm/devices/net/gdma/src/bnic.rs | Makes BNIC RX packet storage task-local (no Arc<Mutex<_>>) and removes scratch segment cloning. |
benhillis
previously approved these changes
Mar 30, 2026
benhillis
approved these changes
Mar 30, 2026
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 RX buffer pools in virtio-net and GDMA/BNIC were wrapped in Arc<Mutex<>> (or Arc<Vec<Mutex<>>>), but they are only ever accessed from the single task that runs the queue. The locking was vestigial from an earlier design where the pool was shared. Removing it simplifies the code--no more Arc cloning, scratch buffers, or lock() calls on every buffer operation.
Performance is basically unchanged by this, which is not too surprising since the locks are uncontended and there is so much other lower-hanging fruit. But this change simplifies the code, so we should go ahead and take it anyway.