mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block_util: Use SmallVec for I/O requests
The number of buffers in the request is usually one so by using SmallVec the number of heap allocations can be significantly reduced. DHAT reports: Before: dhat: Total: 1,166,412 bytes in 40,383 blocks After: dhat: Total: 623,852 bytes in 8,157 blocks Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Generated
+1
@@ -88,6 +88,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"qcow",
|
"qcow",
|
||||||
|
"smallvec",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"versionize",
|
"versionize",
|
||||||
"versionize_derive",
|
"versionize_derive",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ io-uring = "0.5.9"
|
|||||||
libc = "0.2.139"
|
libc = "0.2.139"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
qcow = { path = "../qcow" }
|
qcow = { path = "../qcow" }
|
||||||
|
smallvec = "1.10.0"
|
||||||
thiserror = "1.0.37"
|
thiserror = "1.0.37"
|
||||||
versionize = "0.1.9"
|
versionize = "0.1.9"
|
||||||
versionize_derive = "0.1.4"
|
versionize_derive = "0.1.4"
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ pub mod vhdx_sync;
|
|||||||
|
|
||||||
use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult};
|
use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult};
|
||||||
use io_uring::{opcode, IoUring, Probe};
|
use io_uring::{opcode, IoUring, Probe};
|
||||||
|
use smallvec::SmallVec;
|
||||||
use std::alloc::{alloc_zeroed, dealloc, Layout};
|
use std::alloc::{alloc_zeroed, dealloc, Layout};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
@@ -195,7 +196,7 @@ pub struct AlignedOperation {
|
|||||||
pub struct Request {
|
pub struct Request {
|
||||||
pub request_type: RequestType,
|
pub request_type: RequestType,
|
||||||
pub sector: u64,
|
pub sector: u64,
|
||||||
pub data_descriptors: Vec<(GuestAddress, u32)>,
|
pub data_descriptors: SmallVec<[(GuestAddress, u32); 1]>,
|
||||||
pub status_addr: GuestAddress,
|
pub status_addr: GuestAddress,
|
||||||
pub writeback: bool,
|
pub writeback: bool,
|
||||||
pub aligned_operations: Vec<AlignedOperation>,
|
pub aligned_operations: Vec<AlignedOperation>,
|
||||||
@@ -226,7 +227,7 @@ impl Request {
|
|||||||
let mut req = Request {
|
let mut req = Request {
|
||||||
request_type: request_type(desc_chain.memory(), hdr_desc_addr)?,
|
request_type: request_type(desc_chain.memory(), hdr_desc_addr)?,
|
||||||
sector: sector(desc_chain.memory(), hdr_desc_addr)?,
|
sector: sector(desc_chain.memory(), hdr_desc_addr)?,
|
||||||
data_descriptors: Vec::new(),
|
data_descriptors: SmallVec::with_capacity(1),
|
||||||
status_addr: GuestAddress(0),
|
status_addr: GuestAddress(0),
|
||||||
writeback: true,
|
writeback: true,
|
||||||
aligned_operations: Vec::new(),
|
aligned_operations: Vec::new(),
|
||||||
@@ -354,7 +355,8 @@ impl Request {
|
|||||||
let request_type = self.request_type;
|
let request_type = self.request_type;
|
||||||
let offset = (sector << SECTOR_SHIFT) as libc::off_t;
|
let offset = (sector << SECTOR_SHIFT) as libc::off_t;
|
||||||
|
|
||||||
let mut iovecs = Vec::with_capacity(self.data_descriptors.len());
|
let mut iovecs: SmallVec<[libc::iovec; 1]> =
|
||||||
|
SmallVec::with_capacity(self.data_descriptors.len());
|
||||||
for (data_addr, data_len) in &self.data_descriptors {
|
for (data_addr, data_len) in &self.data_descriptors {
|
||||||
if *data_len == 0 {
|
if *data_len == 0 {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user