block_util: Preserve ordering of sync file backend completions

For the synchronous backends efficiently preserve the order for
completion requests through the use of VecDequeue. Preserving the order
is not required but is beneficial as it matches the existing
optimisation that looks to match completions and requests.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2023-01-10 14:39:28 +00:00
parent ce51755109
commit db5582f7d1
4 changed files with 22 additions and 18 deletions

View File

@ -25,6 +25,7 @@ use io_uring::{opcode, IoUring, Probe};
use smallvec::SmallVec;
use std::alloc::{alloc_zeroed, dealloc, Layout};
use std::cmp;
use std::collections::VecDeque;
use std::convert::TryInto;
use std::fs::File;
use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
@ -595,7 +596,7 @@ where
iovecs: &[libc::iovec],
user_data: u64,
eventfd: &EventFd,
completion_list: &mut Vec<(u64, i32)>,
completion_list: &mut VecDeque<(u64, i32)>,
) -> AsyncIoResult<()> {
// Convert libc::iovec into IoSliceMut
let mut slices = Vec::new();
@ -616,7 +617,7 @@ where
.map_err(AsyncIoError::ReadVectored)?
};
completion_list.push((user_data, result as i32));
completion_list.push_back((user_data, result as i32));
eventfd.write(1).unwrap();
Ok(())
@ -628,7 +629,7 @@ where
iovecs: &[libc::iovec],
user_data: u64,
eventfd: &EventFd,
completion_list: &mut Vec<(u64, i32)>,
completion_list: &mut VecDeque<(u64, i32)>,
) -> AsyncIoResult<()> {
// Convert libc::iovec into IoSlice
let mut slices = Vec::new();
@ -649,7 +650,7 @@ where
.map_err(AsyncIoError::WriteVectored)?
};
completion_list.push((user_data, result as i32));
completion_list.push_back((user_data, result as i32));
eventfd.write(1).unwrap();
Ok(())
@ -659,7 +660,7 @@ where
&mut self,
user_data: Option<u64>,
eventfd: &EventFd,
completion_list: &mut Vec<(u64, i32)>,
completion_list: &mut VecDeque<(u64, i32)>,
) -> AsyncIoResult<()> {
let result: i32 = {
let mut file = self.file();
@ -671,7 +672,7 @@ where
};
if let Some(user_data) = user_data {
completion_list.push((user_data, result));
completion_list.push_back((user_data, result));
eventfd.write(1).unwrap();
}

View File

@ -5,6 +5,7 @@
use crate::async_io::{AsyncIo, AsyncIoResult, DiskFile, DiskFileError, DiskFileResult};
use crate::AsyncAdaptor;
use qcow::{QcowFile, RawFile, Result as QcowResult};
use std::collections::VecDeque;
use std::fs::File;
use std::io::{Seek, SeekFrom};
use std::sync::{Arc, Mutex, MutexGuard};
@ -37,7 +38,7 @@ impl DiskFile for QcowDiskSync {
pub struct QcowSync {
qcow_file: Arc<Mutex<QcowFile>>,
eventfd: EventFd,
completion_list: Vec<(u64, i32)>,
completion_list: VecDeque<(u64, i32)>,
}
impl QcowSync {
@ -46,7 +47,7 @@ impl QcowSync {
qcow_file,
eventfd: EventFd::new(libc::EFD_NONBLOCK)
.expect("Failed creating EventFd for QcowSync"),
completion_list: Vec::new(),
completion_list: VecDeque::new(),
}
}
}
@ -98,6 +99,6 @@ impl AsyncIo for QcowSync {
}
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
self.completion_list.pop()
self.completion_list.pop_front()
}
}

View File

@ -5,6 +5,7 @@
use crate::async_io::{
AsyncIo, AsyncIoError, AsyncIoResult, DiskFile, DiskFileError, DiskFileResult, DiskTopology,
};
use std::collections::VecDeque;
use std::fs::File;
use std::io::{Seek, SeekFrom};
use std::os::unix::io::{AsRawFd, RawFd};
@ -44,7 +45,7 @@ impl DiskFile for RawFileDiskSync {
pub struct RawFileSync {
fd: RawFd,
eventfd: EventFd,
completion_list: Vec<(u64, i32)>,
completion_list: VecDeque<(u64, i32)>,
}
impl RawFileSync {
@ -52,7 +53,7 @@ impl RawFileSync {
RawFileSync {
fd,
eventfd: EventFd::new(libc::EFD_NONBLOCK).expect("Failed creating EventFd for RawFile"),
completion_list: Vec::new(),
completion_list: VecDeque::new(),
}
}
}
@ -81,7 +82,7 @@ impl AsyncIo for RawFileSync {
return Err(AsyncIoError::ReadVectored(std::io::Error::last_os_error()));
}
self.completion_list.push((user_data, result as i32));
self.completion_list.push_back((user_data, result as i32));
self.eventfd.write(1).unwrap();
Ok(())
@ -106,7 +107,7 @@ impl AsyncIo for RawFileSync {
return Err(AsyncIoError::WriteVectored(std::io::Error::last_os_error()));
}
self.completion_list.push((user_data, result as i32));
self.completion_list.push_back((user_data, result as i32));
self.eventfd.write(1).unwrap();
Ok(())
@ -120,7 +121,7 @@ impl AsyncIo for RawFileSync {
}
if let Some(user_data) = user_data {
self.completion_list.push((user_data, result));
self.completion_list.push_back((user_data, result));
self.eventfd.write(1).unwrap();
}
@ -128,6 +129,6 @@ impl AsyncIo for RawFileSync {
}
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
self.completion_list.pop()
self.completion_list.pop_front()
}
}

View File

@ -4,6 +4,7 @@
use crate::async_io::{AsyncIo, AsyncIoResult, DiskFile, DiskFileError, DiskFileResult};
use crate::AsyncAdaptor;
use std::collections::VecDeque;
use std::fs::File;
use std::sync::{Arc, Mutex, MutexGuard};
use vhdx::vhdx::{Result as VhdxResult, Vhdx};
@ -37,7 +38,7 @@ impl DiskFile for VhdxDiskSync {
pub struct VhdxSync {
vhdx_file: Arc<Mutex<Vhdx>>,
eventfd: EventFd,
completion_list: Vec<(u64, i32)>,
completion_list: VecDeque<(u64, i32)>,
}
impl VhdxSync {
@ -45,7 +46,7 @@ impl VhdxSync {
Ok(VhdxSync {
vhdx_file,
eventfd: EventFd::new(libc::EFD_NONBLOCK)?,
completion_list: Vec::new(),
completion_list: VecDeque::new(),
})
}
}
@ -97,6 +98,6 @@ impl AsyncIo for VhdxSync {
}
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
self.completion_list.pop()
self.completion_list.pop_front()
}
}