Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vm/devices/virtio/virtiofs/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl TestHarness {

let fs = VirtioFs::new(tmpdir.path(), None).unwrap();
let driver_source = VmTaskDriverSource::new(SingleDriverBackend::new(driver.clone()));
let device = VirtioFsDevice::new(&driver_source, "testfs", fs, 0, None);
let device = VirtioFsDevice::new(&driver_source, "testfs", fs, 0, None, Some(1));

let queue_event = Event::new();
let interrupt_event = Event::new();
Expand Down
2 changes: 2 additions & 0 deletions vm/devices/virtio/virtiofs/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl ResolveResource<VirtioDeviceHandle, VirtioFsHandle> for VirtioFsResolver {
)?,
0,
None,
None,
),
Comment on lines 44 to 48
#[cfg(windows)]
VirtioFsBackend::SectionFs { root_path } => {
Expand All @@ -53,6 +54,7 @@ impl ResolveResource<VirtioDeviceHandle, VirtioFsHandle> for VirtioFsResolver {
crate::SectionFs::new(root_path)?,
8 * 1024 * 1024 * 1024, // 8GB of shared memory,
None,
None,
)
}
#[cfg(not(windows))]
Expand Down
20 changes: 18 additions & 2 deletions vm/devices/virtio/virtiofs/src/virtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ use zerocopy::Immutable;
use zerocopy::IntoBytes;
use zerocopy::KnownLayout;

/// Maximum number of request queues to advertise.
const MAX_REQUEST_QUEUES: u32 = 16;

/// PCI configuration space values for virtio-fs devices.
#[repr(C)]
#[derive(IntoBytes, Immutable, KnownLayout)]
Expand Down Expand Up @@ -58,19 +61,32 @@ pub struct VirtioFsDevice {

impl VirtioFsDevice {
/// Creates a new `VirtioFsDevice` with the specified mount tag.
///
/// `num_request_queues` controls how many virtio request queues the device
/// advertises. The Linux guest kernel (≥6.11) distributes I/O across
/// queues on a per-CPU basis. If `None`, defaults to the number of
/// available CPUs (capped at 16).
Comment on lines +67 to +68
pub fn new<Fs>(
driver_source: &VmTaskDriverSource,
tag: &str,
fs: Fs,
shmem_size: u64,
notify_corruption: Option<Arc<dyn Fn() + Sync + Send>>,
num_request_queues: Option<u32>,
) -> Self
where
Fs: 'static + fuse::Fuse + Send + Sync,
{
let num_request_queues = num_request_queues.unwrap_or_else(|| {
std::thread::available_parallelism()
.map(|n| n.get() as u32)
.unwrap_or(1)
.clamp(1, MAX_REQUEST_QUEUES)
});
Comment thread
benhillis marked this conversation as resolved.
Outdated
Comment thread
benhillis marked this conversation as resolved.
Outdated

let mut config = VirtioFsDeviceConfig {
tag: [0; 36],
num_request_queues: 1,
num_request_queues,
};

let notify_corruption = if let Some(notify) = notify_corruption {
Expand Down Expand Up @@ -104,7 +120,7 @@ impl VirtioDevice for VirtioFsDevice {
.with_ring_event_idx(true)
.with_ring_indirect_desc(true)
.with_ring_packed(true),
max_queues: 2,
max_queues: self.config.num_request_queues as u16 + 1,
device_register_length: self.config.as_bytes().len() as u32,
shared_memory: DeviceTraitsSharedMemory {
id: 0,
Expand Down
Loading