Replace hashmap for io_uring pending ops with static array

This commit is contained in:
PThorpe92 2025-02-07 08:37:16 -05:00
parent 8787ed11e2
commit 575a524d04
No known key found for this signature in database
GPG key ID: 66DB3FBACBDD05CC
2 changed files with 14 additions and 7 deletions

2
Cargo.lock generated
View file

@ -1735,6 +1735,8 @@ dependencies = [
"notify",
"rand 0.8.5",
"rand_chacha 0.3.1",
"regex",
"regex-syntax",
"serde",
"serde_json",
"tempfile",

View file

@ -4,7 +4,6 @@ use log::{debug, trace};
use rustix::fs::{self, FlockOperation, OFlags};
use rustix::io_uring::iovec;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
use std::io::ErrorKind;
use std::os::fd::AsFd;
@ -40,7 +39,7 @@ pub struct UringIO {
struct WrappedIOUring {
ring: io_uring::IoUring,
pending_ops: usize,
pub pending: HashMap<u64, Rc<Completion>>,
pub pending: [Option<Rc<Completion>>; MAX_IOVECS as usize + 1],
key: u64,
}
@ -63,7 +62,7 @@ impl UringIO {
ring: WrappedIOUring {
ring,
pending_ops: 0,
pending: HashMap::new(),
pending: [const { None }; MAX_IOVECS as usize + 1],
key: 0,
},
iovecs: [iovec {
@ -92,7 +91,7 @@ impl InnerUringIO {
impl WrappedIOUring {
fn submit_entry(&mut self, entry: &io_uring::squeue::Entry, c: Rc<Completion>) {
trace!("submit_entry({:?})", entry);
self.pending.insert(entry.get_user_data(), c);
self.pending[entry.get_user_data() as usize] = Some(c);
unsafe {
self.ring
.submission()
@ -124,6 +123,11 @@ impl WrappedIOUring {
fn get_key(&mut self) -> u64 {
self.key += 1;
if self.key == MAX_IOVECS as u64 {
let key = self.key;
self.key = 0;
return key;
}
self.key
}
}
@ -175,10 +179,11 @@ impl IO for UringIO {
)));
}
{
let c = ring.pending.get(&cqe.user_data()).unwrap().clone();
c.complete(cqe.result());
if let Some(c) = ring.pending[cqe.user_data() as usize].as_ref() {
c.complete(cqe.result());
}
}
ring.pending.remove(&cqe.user_data());
ring.pending[cqe.user_data() as usize] = None;
}
Ok(())
}