From 3480e69ff5cde1c253beaf535bcdffc4596f672f Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 12 Nov 2021 10:38:51 +0000 Subject: [PATCH] vmm: Cache whether io_uring is supported in DeviceManager Probing for whether the io_uring is supported is time consuming so cache this value if it is known to reduce the cost for secondary block devices that are added. Before: cloud-hypervisor: 3.988896ms: INFO:vmm/src/device_manager.rs:1901 -- Creating virtio-block device: DiskConfig { path: Some("/home/rob/workloads/focal-server-cloudimg-amd64-custom-20210609-0.raw"), readonly: false, direct: false, iommu: false, num_queues: 1, queue_size: 128, vhost_user: false, vhost_socket: None, poll_queue: true, rate_limiter_config: None, id: Some("_disk0"), disable_io_uring: false, pci_segment: 0 } cloud-hypervisor: 14.129591ms: INFO:vmm/src/device_manager.rs:1983 -- Using asynchronous RAW disk file (io_uring) cloud-hypervisor: 14.159853ms: INFO:vmm/src/device_manager.rs:1901 -- Creating virtio-block device: DiskConfig { path: Some("/tmp/disk"), readonly: false, direct: false, iommu: false, num_queues: 1, queue_size: 128, vhost_user: false, vhost_socket: None, poll_queue: true, rate_limiter_config: None, id: Some("_disk1"), disable_io_uring: false, pci_segment: 0 } cloud-hypervisor: 22.110281ms: INFO:vmm/src/device_manager.rs:1983 -- Using asynchronous RAW disk file (io_uring) After: cloud-hypervisor: 4.880411ms: INFO:vmm/src/device_manager.rs:1916 -- Creating virtio-block device: DiskConfig { path: Some("/home/rob/workloads/focal-server-cloudimg-amd64-custom-20210609-0.raw"), readonly: false, direct: false, iommu: false, num_queues: 1, queue_size: 128, vhost_user: false, vhost_socket: None, poll_queue: true, rate_limiter_config: None, id: Some("_disk0"), disable_io_uring: false, pci_segment: 0 } cloud-hypervisor: 14.105123ms: INFO:vmm/src/device_manager.rs:1998 -- Using asynchronous RAW disk file (io_uring) cloud-hypervisor: 14.134837ms: INFO:vmm/src/device_manager.rs:1916 -- Creating virtio-block device: DiskConfig { path: Some("/tmp/disk"), readonly: false, direct: false, iommu: false, num_queues: 1, queue_size: 128, vhost_user: false, vhost_socket: None, poll_queue: true, rate_limiter_config: None, id: Some("_disk1"), disable_io_uring: false, pci_segment: 0 } cloud-hypervisor: 14.221869ms: INFO:vmm/src/device_manager.rs:1998 -- Using asynchronous RAW disk file (io_uring) Signed-off-by: Rob Bradford --- vmm/src/device_manager.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index a2149a617..b43ef71e8 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -906,6 +906,9 @@ pub struct DeviceManager { // Helps identify if the VM is currently being restored restoring: bool, + + // io_uring availability if detected + io_uring_supported: Option, } impl DeviceManager { @@ -1043,6 +1046,7 @@ impl DeviceManager { gpio_device: None, force_iommu, restoring, + io_uring_supported: None, }; let device_manager = Arc::new(Mutex::new(device_manager)); @@ -1886,6 +1890,17 @@ impl DeviceManager { Ok(devices) } + // Cache whether io_uring is supported to avoid probing for very block device + fn io_uring_is_supported(&mut self) -> bool { + if let Some(supported) = self.io_uring_supported { + return supported; + } + + let supported = block_io_uring_is_supported(); + self.io_uring_supported = Some(supported); + supported + } + fn make_virtio_block_device( &mut self, disk_cfg: &mut DiskConfig, @@ -1962,7 +1977,7 @@ impl DeviceManager { ImageType::FixedVhd => { // Use asynchronous backend relying on io_uring if the // syscalls are supported. - if block_io_uring_is_supported() && !disk_cfg.disable_io_uring { + if self.io_uring_is_supported() && !disk_cfg.disable_io_uring { info!("Using asynchronous fixed VHD disk file (io_uring)"); Box::new( FixedVhdDiskAsync::new(file) @@ -1979,7 +1994,7 @@ impl DeviceManager { ImageType::Raw => { // Use asynchronous backend relying on io_uring if the // syscalls are supported. - if block_io_uring_is_supported() && !disk_cfg.disable_io_uring { + if self.io_uring_is_supported() && !disk_cfg.disable_io_uring { info!("Using asynchronous RAW disk file (io_uring)"); Box::new(RawFileDisk::new(file)) as Box } else {