What is the difference between io_submit and a file with O_ASYNC

I read this asynchronous io disk file this tutorial , however it does not let me understand, and in fact it confuses me more.

According to this tutorial, there are two different models of asynchronous I / O:

  • Asynchronous blocking I / O: open the file with O_ASYNC, and then use epoll / poll / select.
  • Asynchronous I / O: using glibc AIO in this article. since the glibc implementation is just a simulation through a thread pool, what I am looking at in this question is the AIO kernel , i.e. io_submit.

At least from the point of view of the concept there is not much difference, true, io_submit can allow you to issue several io reqeusts, and on the other hand, using reading with O_ASYNC, you can simply issue one request with the estimated file position.

And this guide also mentioned that using epoll as an alternative to Linux AIO:

Epoll. Linux has limited support for using epoll as a mechanism for asynchronous I / O. To read a file opened in buffer mode (this is without O_DIRECT), if the file is opened as O_NONBLOCK, then read will return EAGAIN until the corresponding part is in memory. It writes to the buffer file, as a rule, immediately, since they are written out from another write-back stream. However, these mechanisms do not provide an I / O control level that provides direct I / O.

What is the problem of using epoll as an alternative to AIO? Or, in other words, what is the problem that we need a new io_submit interface to solve?

+4
source share
1 answer

In my opinion, the critical problem behind io_ * api is the ability to achieve higher I / O throughput through two main measures:

  • Minimizing the number of system calls in the application I / O cycle. Several request packages can be submitted, and then, after some time, the application can return to check the results of individual requests at a time using io_getevents (). It is important to note that io_getevents () will return information about each individual I / O transaction, and not about an undefined bit of information returned by epoll () on every call, "fd x has pending changes."

  • The kernel I / O scheduler can rely on reordering the request to make better use of the hardware. An application may even give up some advice on how to reorder queries using the aio_reqprio field in struct iocb. Mandatory, if we allow reordering of I / O requests, we need to provide an application with the appropriate API to request whether certain requests with high priority will already be executed (thus, io_getevents ()).

We can say that io_getevents () is a really important part of the functionality, after which io_submit () is a convenient helper to use it effectively.

+1
source

Source: https://habr.com/ru/post/1479284/


All Articles