#uring #io #linux #lang #language

io-uring

The low-level io_uring userspace interface for Rust

30 releases

0.5.13 Feb 20, 2023
0.5.11 Dec 27, 2022
0.5.9 Nov 3, 2022
0.5.3 Jul 9, 2022
0.2.0 Jun 5, 2019

#28 in Filesystem

Download history 7467/week @ 2022-12-06 7177/week @ 2022-12-13 4138/week @ 2022-12-20 3208/week @ 2022-12-27 5825/week @ 2023-01-03 6866/week @ 2023-01-10 5288/week @ 2023-01-17 5844/week @ 2023-01-24 7068/week @ 2023-01-31 7056/week @ 2023-02-07 6406/week @ 2023-02-14 8250/week @ 2023-02-21 7942/week @ 2023-02-28 6470/week @ 2023-03-07 6184/week @ 2023-03-14 5874/week @ 2023-03-21

28,007 downloads per month
Used in 54 crates (16 directly)

MIT/Apache

230KB
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.5"

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

~225KB