#io-uring #userspace #linux #low-level #syscalls #async #rustix

no-std rustix-uring

The low-level io_uring userspace interface for Rust

3 unstable releases

0.2.0 Dec 12, 2023
0.1.1 Mar 4, 2023
0.1.0 Mar 3, 2023

#399 in Asynchronous

Download history 30/week @ 2024-07-04 34/week @ 2024-07-11 51/week @ 2024-07-18 47/week @ 2024-07-25 62/week @ 2024-08-01 89/week @ 2024-08-08 34/week @ 2024-08-15 61/week @ 2024-08-22 62/week @ 2024-08-29 29/week @ 2024-09-05 46/week @ 2024-09-12 97/week @ 2024-09-19 74/week @ 2024-09-26 77/week @ 2024-10-03 29/week @ 2024-10-10 41/week @ 2024-10-17

235 downloads per month
Used in 2 crates

MIT/Apache

160KB
3K SLoC

A Linux io_uring API, using rustix

github actions crates license license docs.rs

This is a Linux io_uring userspace interface for Rust. It is higher-level than the userspace boundary API, but lower-level than an async runtime.

This library derived from the io_uring crate, and is modified to use rustix to perform the system calls.

Usage

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

[dependencies]
rustix-uring = "0.1"

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

use rustix_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

~1.5–9.5MB
~108K SLoC