I am reading this tutorial on asynchronous disk file I/O, however it doesn't make things clear, it actually makes me more confused.
There are two different async. I/O models according to the tutorial:
Asynchronous blocking I/O where you open a file with
O_ASYNC
, then useepoll
/poll
/select
.Asynchronous IO using glibc's AIO
Since glibc implements AIO with a thread pool, what I am referring to in this question with "AIO" is rather kernel AIO, i.e. io_submit
At least from a conceptual point of view, there seems to be no big difference -- io_submit
can let you issue multiple I/O requests, while on the other hand, using read
with O_ASYNC
you can just issue one request with a file position.
This guide also mentions using epoll
as an alternative to Linux AIO:
epoll. Linux has limited support for using
epoll
as a mechanism for asynchronous I/O. For reads to a file opened in buffered mode (that is, withoutO_DIRECT
), if the file is opened asO_NONBLOCK
, then a read will return EAGAIN until the relevant part is in memory. Writes to a buffered file are usually immediate, as they are written out with another writeback thread. However, these mechanisms don’t give the level of control over I/O that direct I/O gives.
What is the issue of using epoll
as an AIO alternative? Or in other words, what is the problem that we need [the new interface] io_submit
to solve?
O_ASYNC
. Andman 2 open
saysThis feature is available only for terminals, pseudoterminals, sockets, and (since Linux 2.6) pipes and FIFOs.
, so not for disk file IO, as you intend. Did you meanO_NONBLOCK
? – Dao