linux five IO model

linux five IO model

  • In java, there are three IO models are blocking IO (BIO), non-blocking IO (NIO) and asynchronous IO (AIO);

  • java provided IO related API, when a file handle, in fact, rely on the operating system level IO operations are implemented.

  • In linux operating system, a total of five different types: blocking IO model, non-blocking IO model, IO multiplexing model, model and IO signal driving Asynchronous IO model.

  • Refers to data read from IO hardware (hard disk) into user space, kernel space is called the intermediate transition space.

1. blocking IO model
Here Insert Picture Description
application process calls recvfrom to receive data through the system, but the kernel is not ready datagram, the application process will be to block until the kernel is ready datagram, recvfrom datagram complete copy job application process to end obstruction status.

  • Simple, low concurrency, low timeliness requirements.

2. The non-blocking IO model
Here Insert Picture Description

  • Before the application process to the kernel interaction, the purpose is not reached, no longer blindly wait, but directly returned. Then by polling the way, stop to ask whether the kernel data ready. If a poll found that the data is ready, it will copy the data to the user space; if not ready kernel will return error.
  • Two requests clearance to complete other tasks, increasing time efficiency.

3. The drive signal IO model
Here Insert Picture Description

  • Application process notifies the kernel when reading a file, a socket if an event occurs, please send me a signal. After receiving the signal, the signal processing function corresponding to the subsequent processing.
  • Application process in advance to the kernel to register a signal handler, then the user process returns without obstruction, when the kernel data is ready to send a signal to the process, the user process will be in the signal handler began to copy the data to the user space.
  • Implement complex
  1. IO multiplexing model
    Here Insert Picture Description
  • IO can be registered to multiple processes on the same pipeline, this pipeline will be unified and kernel interaction. When a request for a data pipeline requires ready, then the process corresponding to the data copied to the user space.
  • Multi-IO multiplexer if the transfer is a select function, IO multiple processes can be registered to the same select, when a user process calls the select, select listens to all registered good IO, the IO monitor if all required data when not ready, select the calling process will be blocked. When any of the required IO data is ready, select call returns, then the process is carried out by recvfrom copies of data.
  • IO multiplexing model here, and signal processing function is not registered to the kernel, so he was not non-blocking. After issuing the select process, until all IO operations select the monitor at least one of the required data is ready, we will have to return, and also need to re-send the request to copy the file.
  • Effective mention the efficiency of homes.

The four kinds are synchronized, real data copying process are carried out simultaneously.

Drive signal, the kernel notification process after the data is ready, and then process the data via recvfrom copy operation. Can be considered data preparation phase is asynchronous, however, is still synchronized copies of data, all the whole process can not be considered to be asynchronous.

5. Asynchronous IO model

  • After the application process the IO requests to the kernel, complete copy of the file by the kernel to operate. After the completion of the relevant core operations, it will send a signal to tell this IO application process has been completed.
    Here Insert Picture Description
    A user process initiated aio_read after the operation, passing the kernel descriptor, a buffer pointer, buffer size, etc., to tell the kernel when the entire operation is completed, how the notification process, and then immediately do other things. When the kernel receives aio_read later, we will return immediately, and then wait for data preparation, you're ready to copy to user space, and then notify this IO has been completed.

5 IO Model Comparison

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/qq_35958788/article/details/93708886