virtio-devices: Use SmallVec for descriptor chains

Rather than instantiating a vector for parsing the descriptor chain in
advance instead use a SmallVec bounded by the expected length of the
descriptor chain. This removes vector allocations from those paths.

As smallvec was already a block dependency move it to a workspace
dependency and use it from there.

Fixes: #5079

Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
Rob Bradford
2026-07-07 09:14:23 +01:00
committed by Wei Liu
parent ba3cfd7d9d
commit ad3dbcd130
7 changed files with 12 additions and 6 deletions
+2 -1
View File
@@ -15,6 +15,7 @@ use event_monitor::event;
use log::{error, info, warn};
use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use thiserror::Error;
use virtio_queue::{Queue, QueueT};
use vm_memory::{Bytes, GuestAddressSpace, GuestMemoryAtomic};
@@ -66,7 +67,7 @@ impl RngEpollHandler {
// Validate the entire descriptor chain upfront so we never
// partially fill buffers for a chain that turns out to be
// invalid.
let descs: Vec<_> = desc_chain
let descs: SmallVec<[_; 4]> = desc_chain
.checked_iter(self.access_platform.as_deref())
.collect::<Result<_, _>>()
.unwrap_or_default();