Linux AIO [email_address]
Agenda IO Models POSIX AIO Linux Native AIO
IO Models
Sync Blocking IO
Sync Non-blocking IO
Async Blocking IO
Async Non-blocking IO
POSIX AIO glibc implementation Built on top of pthread All user space
POSIX AIO man 3 aio aio_init(3), aio_cancel(3), aio_cancel64(3),  aio_error(3), aio_error64(3), aio_fsync(3), aio_fsync64(3), aio_init(3), aio_read(3),  aio_read64(3), aio_return(3), aio_return64(3),  aio_suspend(3), aio_suspend64(3), aio_write(3), aio_write64(3)
POSIX AIO __aio_enqueue_request if (nthreads < optim.aio_threads && idle_thread_count == 0) aio_create_helper_thread (&thid, handle_fildes_io, newp) Queued operations: LIO_READ,LIO_WRITE,LIO_NOP LIO_DSYNC, LIO_SYNC, LIO_READ64,LIO_WRITE64
POSIX AIO handle_fildes_io pread/read pwrite/write fdatasync/fsync
POSIX AIO Example...
Linux Native AIO Kernel space implementation Use workqueue to handle deferred left-overs Libaio wrappers
Linux Native AIO Only support AIO-DIO No AIO fsync/fdatasync Not on sockets/pipes
Supported Operations IO_CMD_PREAD, IO_CMD_PWRITE IO_CMD_FSYNC, IO_CMD_FDSYNC IO_CMD_POLL, IO_CMD_NOOP IO_CMD_PREADV, IO_CMD_PWRITEV
Syscall APIs int io_setup(int maxevents, io_context_t *ctxp); int io_destroy(io_context_t ctx); int io_submit(io_context_t ctx, long nr, struct iocb *ios[]); int io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt); int io_getevents(io_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct timespec *timeout);
Libaio wrappers int io_queue_init(int maxevents, io_context_t *ctxp);  int io_queue_release(io_context_t ctx); int io_queue_run(io_context_t ctx); io_prep_pread, io_prep_pwrite, io_set_callback
Kernel Implementation io_submit() aio_setup_iocb() aio_run_iocb() kiocb->ki_retry callback aio_complete() static struct workqueue_struct *aio_wq;
Native AIO Example...
Q & A?

Linux aio