#io #file-io #userspace #linux-kernel #low-level #uring #queue

io-uring

The low-level io_uring userspace interface for Rust

38 releases

0.7.2 Nov 25, 2024
0.7.0 Sep 27, 2024
0.6.4 Apr 21, 2024
0.6.3 Jan 31, 2024
0.2.0 Jun 5, 2019

#60 in Asynchronous

Download history 17662/week @ 2024-08-21 17671/week @ 2024-08-28 17638/week @ 2024-09-04 15070/week @ 2024-09-11 16835/week @ 2024-09-18 18474/week @ 2024-09-25 18083/week @ 2024-10-02 24172/week @ 2024-10-09 27323/week @ 2024-10-16 27465/week @ 2024-10-23 26754/week @ 2024-10-30 26564/week @ 2024-11-06 30570/week @ 2024-11-13 28449/week @ 2024-11-20 23357/week @ 2024-11-27 18553/week @ 2024-12-04

106,922 downloads per month
Used in 120 crates (48 directly)

MIT/Apache

355KB
9K 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

~75–330KB