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
+3 -2
View File
@@ -25,6 +25,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_allocator::page_size::{align_page_size_down, get_page_size};
@@ -276,7 +277,7 @@ impl BalloonEpollHandler {
{
let data_chunk_size = size_of::<u32>();
let results: Vec<_> = desc_chain
let results: SmallVec<[_; 4]> = desc_chain
.checked_iter(self.access_platform.as_deref())
.collect();
for result in results {
@@ -366,7 +367,7 @@ impl BalloonEpollHandler {
self.queues[queue_index].pop_descriptor_chain(self.mem.memory())
{
let mut descs_len = 0;
let results: Vec<_> = desc_chain
let results: SmallVec<[_; 4]> = desc_chain
.checked_iter(self.access_platform.as_deref())
.collect();
for result in results {