Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace hashmap for io_uring pending ops with static array #922

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions core/io/io_uring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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(())
}
Expand Down
Loading