I/O model
1. IO requests are divided into two phases
Wait for data to be ready
Copy From kernel cache to process Buffer
2. Check whether the request is blocked.
Synchronous I/O
Asynchronous I/O
3. Five I/O models of UNIX
Blocking I/O
Non-blocking I/O
I/O multiplexing (select, poll, epoll, etc. support I/O multiplexing)
Signal-driven I/O
Asynchronous I/O
The first four models are synchronous I/O.
1.
Blocking I/O
Block I/O model: When recvfrom is called in a process space, its system call will not be returned until the data packet arrives and is copied to the application's buffer zone or an error occurs, during this period, the process enters the sleep or suspension state. (Process suspended)
2.Non-blocking I/O
Non-blocking I/O model: When recvfrom the application layer to the kernel, if there is no data in the buffer, an ewouldblock error is returned directly, the user process has been calling the Recv operation to query the data readability and polling method before the data is successfully returned. (CPU usage by polling)
The above two models are like: A big uncle is in a community and knows that today he has a letter to go to the mailbox of the guard, but he does not know when.
Block I/O->The uncle waited directly at the guard until the email was sent;
Non-blocking I/O->Uncle did not wait for a while to see if he had sent the email.
3.I/O multiplexing
I/O multiplexing (select, poll, epoll, etc. support I/O multiplexing): A process passes one or more connections to a select or poll system call, i/O multiplexing achieves multiple connections or multiple connections (TCP, UDP, etc.) share the same waiting mechanism, and select returns the readable condition of a connection, call Recv/recvfrom to copy the read datagram to the buffer zone of the application process. (Multiple connections register the same SELECT statement. Nio is implemented based on the I/O Reuse Model)
I/OReuse->When the guard receives a message from the entire community, he notifies the corresponding person to pick up the email.
4. Signal-driven I/O
Signal-driven I/O: the function of capturing and processing sigio signals is implemented by calling the sigaction system, which is non-blocking. When data is ready, A sigio signal is generated for the process and the application is notified to call recvfrom through the signal callback to read the data. (Capture the signal sent by the kernel)
5.Asynchronous I/O
Asynchronous I/O: Inform the kernel to start an operation and let the kernel notify us after the entire operation is completed, including copying data from the kernel to the user space. (Asynchronous)
Signal-driven I/O->The guard notifies the corresponding person to pick up the email.
Asynchronous I/O->The guard delivers the email to the corresponding person.
5. Comparison of I/O models:
The first four models are synchronous I/O, and the last one is asynchronous.
Reference: http://blog.csdn.net/moxiaomomo/article/details/6844469