# io_uring
[[Linux]] [[Asynchronous IO]] [[Systems Programming]]
> [!note] This might be worth playing with at [[My retreat at the recurse center]].
Reading [The rapid growth of io_uring [LWN.net]](https://lwn.net/Articles/810414/).
It's a mechanism for doing asynchronous IO that showed up in linux 5.1.
Classic Unix I/O had only blocking IO. Other operating systems at the time had asynchronous IO (start an operation and wait for its completion at a future time) for many years before unix was created.
Linux later came up with [io_setup(2) - Linux manual page](http://man7.org/linux/man-pages/man2/io_setup.2.html), which worked mostly for file access and networking, as it requires lower-level support.
The idea is to share a ring buffer between the kernel and userland that the userland can use to poll the status of various IO tasks in the kernel, without having to do a context switch.
Entries in the ring buffers are commands (encoded with an opcode) telling the kernel what to do:
- READ/WRITE
- READ/WRITE fixed buffers for better performance
- FSYNC
- POLL_ADD: schedules a single poll() call on a set of file descriptors
- POLL_REMOVE: cancel a poll call
- SENDMSG/RECVMSG: networking
- TIMEOUT/TIMEOUT_REMOVE
- ACCEPT/CONNECT: socket operations
- ASYNC_CANCEL: cancel another IO operation
- LINK_TIMEOUT: link a timeout that will cancel an inflight IO operation if it expires. A successful IO operation cancels the timeout itself.
These entries can support dependencies, so that one operation is only to be scheduled after another one finishes.
Detailed documentation for io_uring: [Efficient IO with io_uring](https://kernel.dk/io_uring.pdf)