[] reprint] on five kinds of I/O models under Linux

Source: Internet
Author: User

On five kinds of I/O models under Linux

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

I. On the derivation of I/O model

As we all know, for the sake of the security of the OS, the process is unable to directly manipulate the I/O device, it must use the system call request kernel to assist the I/O action, and the kernel will maintain a buffer for each I/O device. as shown in the following:

The entire request process is: The user process initiates the request, after the kernel accepts the request, obtains the data from the I/O device into buffer, and then copy the data in buffer to the address space of the user process, the user process obtains the data and then responds to the client.

During the entire request, it takes time to enter the data into buffer, and it takes time to copy the data from buffer to the process. Therefore, depending on the wait mode during these two periods of time, I/O actions can be divided into the following five modes:

  (1) Blocking I/O (Blocking I/O)

(2) Non-blocking I/O (non-blocking I/O)

(3) I/O multiplexing (I/O multiplexing)

(4) Signal-driven I/O (Signal driven I/O)

(5) asynchronous I/O (asynchrnous I/O)

Ii. Division of the I/O model

  blocking: The calling process is waiting until the operation is complete.

non-blocking: when the kernel's data is not ready, it returns immediately and the process can do other things.

From synchronous asynchronous, as well as blocking, non-blocking two dimensions to see:

    

Three, I/O model of the sub-statement

1. Blocking I/O

From what can be seen throughout the process, when the user process makes a system call, the kernel begins the first phase of I/O, prepares the data into the buffer, and when the data is ready, copies the data from the kernel buffer into the memory of the user process, and the user process removes the block state from re-running.

Therefore, the Blocking I/O is characterized by block in both phases of I/O execution.

2. Non-blocking I/O

As can be seen in the two phases of I/O execution, the user process is blocked only in the second stage, and the first stage is not blocked, but in the first phase, the user process needs to be blind, and constantly polling the kernel to see if the data is ready, so the model is more CPU-intensive.

  3. I/O multiplexing

    

As you can see in the I/O multiplexing model, both phases of I/O execution are blocked by the user process, but the two phases are independent, and in a single complete I/O operation, the user process initiated two system calls.

 4, signal-driven I/O

The model is also known as an event-driven I/O model, and you can see that in this model, only the second phase of I/O execution blocks the user process, and in the first phase there is no blocking.

At first glance, it looks like a non-blocking model, but the difference is that the model is in the first phase of I/O execution, and when the data is ready, it will proactively notify the user that the process data is ready to be completed, that is, a callback to the user process. This notification is divided into two types, one for horizontal triggering, that is, if the user process does not respond, it will always send a notification, the second is the edge trigger, that is, notify only once.

  5. Asynchronous I/O

In this model, when a user process initiates a system call, it can begin to do other things immediately, and then until both phases of I/O execution are complete, the kernel sends a notification to the user process that the process operation is complete.

Summary of four or five models

[] reprint] about five I/O models under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.