mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-28 07:33:09 +00:00
block_util: Avoid reallocation of Vec on push
When using DHAT[1] for analysis the amount heap allocations change from: dhat: Total: 3,186,536 bytes in 41,452 blocks to dhat: Total: 1,059,816 bytes in 34,747 blocks When running against virtio-block; this still more allocations than virtio-pmem but a significant improvement without any cost. [1] https://docs.rs/dhat/latest/dhat/ Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
9e8296b696
commit
eb87538100
@ -249,6 +249,7 @@ impl Request {
|
|||||||
return Err(Error::DescriptorChainTooShort);
|
return Err(Error::DescriptorChainTooShort);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
req.data_descriptors.reserve_exact(1);
|
||||||
while desc.has_next() {
|
while desc.has_next() {
|
||||||
if desc.is_write_only() && req.request_type == RequestType::Out {
|
if desc.is_write_only() && req.request_type == RequestType::Out {
|
||||||
return Err(Error::UnexpectedWriteOnlyDescriptor);
|
return Err(Error::UnexpectedWriteOnlyDescriptor);
|
||||||
@ -353,7 +354,7 @@ 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::new();
|
let mut iovecs = Vec::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;
|
||||||
|
@ -156,9 +156,8 @@ impl AsyncIo for RawFileAsync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn complete(&mut self) -> Vec<(u64, i32)> {
|
fn complete(&mut self) -> Vec<(u64, i32)> {
|
||||||
let mut completion_list = Vec::new();
|
|
||||||
|
|
||||||
let cq = self.io_uring.completion();
|
let cq = self.io_uring.completion();
|
||||||
|
let mut completion_list = Vec::with_capacity(cq.len());
|
||||||
for cq_entry in cq {
|
for cq_entry in cq {
|
||||||
completion_list.push((cq_entry.user_data(), cq_entry.result()));
|
completion_list.push((cq_entry.user_data(), cq_entry.result()));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user