Skip to content

Commit 891411a

Browse files
committed
io-uring: Fix check and reduce MAX_READ_SIZE to 64 blocks
Reading 64 MB chunks at a time and keeping the kernel busy surpases std::fs::read time with unoptimized io_uring one being 1.12% fast
1 parent 7dd0e1d commit 891411a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

tokio/src/fs/read_uring.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const PROBE_SIZE_U32: u32 = PROBE_SIZE as u32;
1313

1414
// Max bytes we can read using io uring submission at a time
1515
// SAFETY: cannot be higher than u32::MAX for safe cast
16-
const MAX_READ_SIZE: usize = u32::MAX as usize;
16+
// Set to read max 64 blocks at time
17+
const MAX_READ_SIZE: usize = 64 * 1024 * 1024;
1718

1819
pub(crate) async fn read_uring(path: &Path) -> io::Result<Vec<u8>> {
1920
let file = OpenOptions::new().read(true).open(path).await?;

tokio/src/io/uring/read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Op<Read> {
4848
// the caller in terms of size_read can be unsound.
4949
pub(crate) fn read(fd: OwnedFd, mut buf: Vec<u8>, len: u32, offset: u64) -> Self {
5050
// don't overwrite on already written part
51-
assert!(buf.spare_capacity_mut().len() <= len as usize);
51+
assert!(buf.spare_capacity_mut().len() >= len as usize);
5252
let buf_mut_ptr = buf.spare_capacity_mut().as_mut_ptr().cast();
5353

5454
let read_op = opcode::Read::new(types::Fd(fd.as_raw_fd()), buf_mut_ptr, len)

0 commit comments

Comments
 (0)