[] repost] Talking about the five I/O models under Linux Talking about the five I/O models under Linux

Talking about five I/O models under Linux

 https://www.cnblogs.com/chy2055/p/5220793.html

 First, the introduction of the I/O model

  We all know that for the sake of OS security, a process cannot directly operate I/O devices. It must request the kernel to assist in completing I/O actions through system calls, and the kernel will maintain each I/O device. a buffer. As shown below:

   

  The whole request process is: the  user process initiates the request, after the kernel receives the request, it obtains data from the I/O device into the buffer, and then copies the data in the buffer to the address space of the user process, and the user process obtains the data and then Respond to the client.

  During the entire request process, it takes time to input data to the buffer, and it also takes time to copy data from the buffer to the process. Therefore, according to the different waiting methods during these two periods, I/O actions can be divided into the following five modes:

  (1) 阻塞I/O (Blocking I/O)

  (2) Non-Blocking I/O (Non-Blocking I/O)

  (3) For I / O Recovery (I / O Multiplexing)

  (4) Signal Driven I/O (Signal Driven I/O)

  (5) Asynchronous I/O (Asynchrnous I/O)

 

Second, the division of the I/O model

  Blocking: The calling process is in a waiting state until the operation completes.

  Non-blocking: When the kernel's data is not ready, it will return immediately, and the process can do other things.

  From the perspective of synchronization and asynchronous, as well as blocking and non-blocking dimensions:

    

 

3. I/O model description

  1. Blocking I/O

     

  It can be seen from the above figure that in the whole process, when the user process makes a system call, the kernel starts the first stage of I/O, prepares the data into the buffer, and when the data is all ready, the data is transferred from the The kernel buffer is copied to the memory of the user process, and then the user process is released from the block state and re-runs.

  Therefore, the characteristic of Blocking I/O is that it is blocked in both stages of I/O execution.

 

  2. Non-blocking I/O

     

  As can be seen from the above figure, in the two stages of I/O execution, the user process is blocked only in the second stage, while the first stage is not blocked, but in the first stage, the user process needs to wait blindly , keep polling the kernel to see if the data is ready, so this model is more CPU-intensive.

 

  3. I/O multiplexing

    

   As can be seen from the above figure, in the I/O multiplexing model, both stages of I/O execution are blocked by the user process, but the two stages are independent. In a complete I/O operation, The user process has initiated two system calls.

 

  4. Signal-driven I/O

     

  This model is also called an event-driven I/O model. It can be seen that in this model, the user process is blocked only in the second stage of I/O execution, and there is no blocking in the first stage.

  At first glance, it seems very similar to the non-blocking model, but the difference is that in the first stage of I/O execution, when the data preparation is completed, the user will be actively notified that the process data has been prepared, that is, to the user. The process makes a callback. The notification is divided into two types, one is horizontal triggering, that is, if the user process does not respond, the notification will be sent all the time, and the other is edge triggering, that is, only one notification is made.

 

  5. Asynchronous I/O

     

  In this model, when the user process initiates a system call, it can start doing other things immediately, and then until the two stages of I/O execution are completed, the kernel will send a notification to the user process, telling the user process that the operation has been completed. finished.

 

Four, five models summary

   

 https://www.cnblogs.com/chy2055/p/5220793.html

 First, the introduction of the I/O model

  We all know that for the sake of OS security, a process cannot directly operate I/O devices. It must request the kernel to assist in completing I/O actions through system calls, and the kernel will maintain each I/O device. a buffer. As shown below:

   

  The whole request process is: the  user process initiates the request, after the kernel receives the request, it obtains data from the I/O device into the buffer, and then copies the data in the buffer to the address space of the user process, and the user process obtains the data and then Respond to the client.

  During the entire request process, it takes time to input data to the buffer, and it also takes time to copy data from the buffer to the process. Therefore, according to the different waiting methods during these two periods, I/O actions can be divided into the following five modes:

  (1) 阻塞I/O (Blocking I/O)

  (2) Non-Blocking I/O (Non-Blocking I/O)

  (3) For I / O Recovery (I / O Multiplexing)

  (4) Signal Driven I/O (Signal Driven I/O)

  (5) Asynchronous I/O (Asynchrnous I/O)

 

Second, the division of the I/O model

  Blocking: The calling process is in a waiting state until the operation completes.

  Non-blocking: When the kernel's data is not ready, it will return immediately, and the process can do other things.

  From the perspective of synchronization and asynchronous, as well as blocking and non-blocking dimensions:

    

 

3. I/O model description

  1. Blocking I/O

     

  It can be seen from the above figure that in the whole process, when the user process makes a system call, the kernel starts the first stage of I/O, prepares the data into the buffer, and when the data is all ready, the data is transferred from the The kernel buffer is copied to the memory of the user process, and then the user process is released from the block state and re-runs.

  Therefore, the characteristic of Blocking I/O is that it is blocked in both stages of I/O execution.

 

  2. Non-blocking I/O

     

  As can be seen from the above figure, in the two stages of I/O execution, the user process is blocked only in the second stage, while the first stage is not blocked, but in the first stage, the user process needs to wait blindly , keep polling the kernel to see if the data is ready, so this model is more CPU-intensive.

 

  3. I/O multiplexing

    

   As can be seen from the above figure, in the I/O multiplexing model, both stages of I/O execution are blocked by the user process, but the two stages are independent. In a complete I/O operation, The user process has initiated two system calls.

 

  4. Signal-driven I/O

     

  This model is also called an event-driven I/O model. It can be seen that in this model, the user process is blocked only in the second stage of I/O execution, and there is no blocking in the first stage.

  At first glance, it seems very similar to the non-blocking model, but the difference is that in the first stage of I/O execution, when the data preparation is completed, the user will be actively notified that the process data has been prepared, that is, to the user. The process makes a callback. The notification is divided into two types, one is horizontal triggering, that is, if the user process does not respond, the notification will be sent all the time, and the other is edge triggering, that is, only one notification is made.

 

  5. Asynchronous I/O

     

  In this model, when the user process initiates a system call, it can start doing other things immediately, and then until the two stages of I/O execution are completed, the kernel will send a notification to the user process, telling the user process that the operation has been completed. finished.

 

Four, five models summary

   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325480431&siteId=291194637