aio: enable polling for IOCTX_FLAG_SQTHREAD
authorJens Axboe <axboe@kernel.dk>
Fri, 14 Dec 2018 16:31:30 +0000 (09:31 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 3 Jan 2019 15:14:03 +0000 (08:14 -0700)
commit94f72c195b62fec14812c5bbc43f2b954ad369de
tree7521efa8c21c801ca418b39faaccdabc5d5242cb
parentb006a100f85c26febd7a210b7fd339853d5e697d
aio: enable polling for IOCTX_FLAG_SQTHREAD

This enables an application to do IO, without ever entering the kernel.
By using the SQ ring to fill in new events and watching for completions
on the CQ ring, we can submit and reap IOs without doing a single system
call. The kernel side thread will poll for new submissions, and in case
of HIPRI/polled IO, it'll also poll for completions.

For O_DIRECT, we can do this with just SQTHREAD being enabled. For
buffered aio, we need the workqueue as well. If we can satisfy the
buffered inline from the SQTHREAD, we do that. If not, we punt to the
workqueue. This is just like buffered aio off the io_ring_enter(2)
system call.

Proof of concept. If the thread has been idle for 1 second, it will set
sq_ring->kflags |= IORING_SQ_NEED_WAKEUP. The application will have to
call io_ring_enter() to start things back up again. If IO is kept busy,
that will never be needed. Basically an application that has this
feature enabled will guard it's io_ring_enter(2) call with:

barrier();
if (ring->kflags & IORING_SQ_NEED_WAKEUP)
io_ring_enter(ctx, to_submit, 0, IORING_SUBMIT);

instead of calling it unconditionally.

Improvements:

1) Maybe have smarter backoff. Busy loop for X time, then go to
   monitor/mwait, finally the schedule we have now after an idle
   second. Might not be worth the complexity.

2) Probably want the application to pass in the appropriate grace
   period, not hard code it at 1 second.

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