A key-value store spends much of its time waiting for the network and the disk. io_uring lets it describe that waiting in batches instead of one system call at a time.
Two rings
The application writes requests into a submission ring and reads results from a completion ring, both shared with the kernel. A single system call can submit many requests at once, and completions can be collected without one.
Batching without waiting
Batching saves system calls only if the batch fills up, and waiting for it to fill adds latency to the requests already in it. The loop that works submits whatever is ready each time it runs out of other work:
- Process every completion that has arrived.
- Queue the reads and writes those completions made possible.
- Submit the queue, however long it is, and go back to step 1.
One ring per core
Sharing a ring between threads needs a lock on the hot path. A ring per core, with each connection owned by one core, keeps the path free of locks and the data in that core's cache.