io_uring: add support for backlogged CQ ring
authorJens Axboe <axboe@kernel.dk>
Wed, 6 Nov 2019 18:31:17 +0000 (11:31 -0700)
committerJens Axboe <axboe@kernel.dk>
Sat, 9 Nov 2019 18:45:29 +0000 (11:45 -0700)
commit1d7bb1d50fb4dc141c7431cc21fdd24ffcc83c76
tree97e72316da883d4a76c1f376509df38e5df08d85
parent78e19bbef38362cebff38aa1ca12e2c82bb72eb8
io_uring: add support for backlogged CQ ring

Currently we drop completion events, if the CQ ring is full. That's fine
for requests with bounded completion times, but it may make it harder or
impossible to use io_uring with networked IO where request completion
times are generally unbounded. Or with POLL, for example, which is also
unbounded.

After this patch, we never overflow the ring, we simply store requests
in a backlog for later flushing. This flushing is done automatically by
the kernel. To prevent the backlog from growing indefinitely, if the
backlog is non-empty, we apply back pressure on IO submissions. Any
attempt to submit new IO with a non-empty backlog will get an -EBUSY
return from the kernel. This is a signal to the application that it has
backlogged CQ events, and that it must reap those before being allowed
to submit more IO.

Note that if we do return -EBUSY, we will have filled whatever
backlogged events into the CQ ring first, if there's room. This means
the application can safely reap events WITHOUT entering the kernel and
waiting for them, they are already available in the CQ ring.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c
include/uapi/linux/io_uring.h