io_uring drain
io_uring drain is a submission flag that delays a request until earlier requests in the same ring finish and delays later requests until the drain request finishes.
Drain orders completion within one ring; it is not a device-cache flush. [1] The documented API forbids mixing IO_DRAIN with IOSQE_CQE_SKIP_SUCCESS in one ring, including on separate requests. [2]
IOSQE_IO_DRAIN is bit 1 of the submission flags, value 2, and has been available since Linux 5.2. A drained request does not start before all previously submitted requests have completed, and later requests do not start before it completes. [2] [4]
A link chain orders only the requests joined to it, while a drain waits for every earlier request in the ring. One slow earlier request therefore also delays all requests submitted after the drain. [2]
Relations
Advantages
- Can establish a ring-scoped dependency before a synchronization request. [1]
Limitations
- It does not order another ring or validate earlier write results.
Citations
- liburing 2.9: io_uring_sqe_set_flags(3), chain and drain scope.
- liburing: io_uring_enter(2), IORING_OP_FSYNC, linking and CQE_SKIP_SUCCESS constraints.
- Linux v6.16 include/uapi/linux/io_uring.h: submission flag bits
Further reading
Sources & caveats
- flags is the liburing 2.9 io_uring_sqe_set_flags(3) page, kept from the earlier version.
- enter is the Linux man-pages io_uring_enter(2) page, reread on the access date in IOSQE_IO_DRAIN, IOSQE_IO_LINK and IOSQE_CQE_SKIP_SUCCESS.
- uapi-header is include/uapi/linux/io_uring.h at tag v6.16, read in enum io_uring_sqe_flags_bit.
- Bit 1 and value 2 come from uapi-header. 5.2 comes from enter.