#low-level #io #userspace #uring #opcode #queue #fd

io-uring

The low-level io_uring userspace interface for Rust

35 releases

0.6.4 Apr 21, 2024
0.6.3 Jan 31, 2024
0.6.2 Sep 17, 2023
0.6.0 Apr 9, 2023
0.2.0 Jun 5, 2019

#28 in Asynchronous

Download history 17017/week @ 2024-02-05 15164/week @ 2024-02-12 14683/week @ 2024-02-19 16479/week @ 2024-02-26 16639/week @ 2024-03-04 15934/week @ 2024-03-11 16739/week @ 2024-03-18 17511/week @ 2024-03-25 15631/week @ 2024-04-01 14274/week @ 2024-04-08 13626/week @ 2024-04-15 16074/week @ 2024-04-22 15742/week @ 2024-04-29 14255/week @ 2024-05-06 14587/week @ 2024-05-13 15043/week @ 2024-05-20

60,196 downloads per month
Used in 87 crates (34 directly)

MIT/Apache

250KB
6K SLoC

Linux IO Uring

github actions crates license license docs.rs

The low-level io_uring userspace interface for Rust.

Usage

To use io-uring crate, first add this to your Cargo.toml:

[dependencies]
io-uring = "0.6"

Next we can start using io-uring crate. The following is quick introduction using Read for file.

use io_uring::{opcode, types, IoUring};
use std::os::unix::io::AsRawFd;
use std::{fs, io};

fn main() -> io::Result<()> {
    let mut ring = IoUring::new(8)?;

    let fd = fs::File::open("README.md")?;
    let mut buf = vec![0; 1024];

    let read_e = opcode::Read::new(types::Fd(fd.as_raw_fd()), buf.as_mut_ptr(), buf.len() as _)
        .build()
        .user_data(0x42);

    // Note that the developer needs to ensure
    // that the entry pushed into submission queue is valid (e.g. fd, buffer).
    unsafe {
        ring.submission()
            .push(&read_e)
            .expect("submission queue is full");
    }

    ring.submit_and_wait(1)?;

    let cqe = ring.completion().next().expect("completion queue is empty");

    assert_eq!(cqe.user_data(), 0x42);
    assert!(cqe.result() >= 0, "read error: {}", cqe.result());

    Ok(())
}

Note that opcode Read is only available after kernel 5.6. If you use a kernel lower than 5.6, this example will fail.

Test and Benchmarks

You can run the test and benchmark of the library with the following commands.

$ cargo run --package io-uring-test
$ cargo bench --package io-uring-bench

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in io-uring by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~71–320KB