3 unstable releases

0.3.0 Apr 27, 2020
0.2.1 Apr 16, 2020
0.2.0 Apr 16, 2020
0.1.1 Apr 15, 2020
0.1.0 Apr 15, 2020

#223 in Unix APIs

28 downloads per month

MIT license

1.5K SLoC


Version License Docs Build Status

This package provides an integration of Linux kernel-level asynchronous I/O to the Tokio platform.

Linux kernel-level asynchronous I/O is different from the Posix AIO library. Posix AIO is implemented using a pool of userland threads, which invoke regular, blocking system calls to perform file I/O. Linux kernel-level AIO, on the other hand, provides kernel-level asynchronous scheduling of I/O operations to the underlying block device.


Add this to your Cargo.toml:

linux-aio-tokio = "0.3"


use std::fs::OpenOptions;

use tempfile::tempdir;

use linux_aio_tokio::{aio_context, AioOpenOptionsExt, LockedBuf, ReadFlags, WriteFlags};

async fn main() {
    let (aio, aio_handle) = aio_context(8, true).unwrap();

    let dir = tempdir().unwrap();

    let mut open_options = OpenOptions::new();

    let file = open_options
        .aio_open(dir.path().join("tmp"), false)

    let mut write_buf = LockedBuf::with_size(1024).unwrap();

    for i in 0..write_buf.size() {
        write_buf.as_mut()[i] = (i % 0xff) as u8;

    file.write_at(&aio_handle, 0, &write_buf, 1024, WriteFlags::APPEND)

    let mut read_buf = LockedBuf::with_size(1024).unwrap();

    file.read_at(&aio_handle, 0, &mut read_buf, 1024, ReadFlags::empty())

    assert_eq!(read_buf.as_ref(), write_buf.as_ref());


    println!("all good!");


This code is licensed under the MIT license.


The current implementation is based on the code created by Hans-Martin Will, available at GitHub repository.


~128K SLoC