Understanding I/O: From Blocking to Asynchronous Models Explained
This article explains the fundamentals of I/O, detailing the two-phase request process, the flow of a web request, and the differences between blocking, non‑blocking, synchronous, and asynchronous I/O models, including select/poll, signal‑driven, and AIO approaches.
I/O Introduction
I/O generally includes memory I/O, network I/O, and disk I/O, but the focus is usually on network I/O and disk I/O. Network I/O essentially involves socket reads.
Each I/O request consists of two phases: First, waiting for data – the data is transferred from disk to kernel memory and placed in a buffer, which can take a long time. Second, copying data – the data is copied from kernel memory to user space, which is relatively fast.
Web Request Processing
1. Client sends request to server NIC.
2. Server NIC passes request to kernel.
3. Kernel hands the request to the user‑space web server process via the appropriate socket.
4. Web server process makes a system call to obtain the needed resource (e.g., an image).
5. Kernel discovers the resource is on local disk and contacts the disk driver.
6. Kernel reads the resource from the disk.
7. Kernel stores the resource in its cache and notifies the web server process.
8. Web server copies the resource to its own buffer.
9. Web server forms a response and issues another system call to return it to the kernel.
10. Kernel sends the response to the NIC.
11. NIC delivers the response to the client.
In short: user request → user space → system call → kernel space → kernel reads disk → back to user space → response to client.
Thus the request involves two I/O phases: network I/O for the client request and disk I/O for the server to read the image.
I/O Model Terminology
When discussing I/O models, the terms synchronous, asynchronous, blocking, and non‑blocking frequently appear.
Blocking vs Non‑Blocking
Blocking means the operation does not return until it is fully completed, causing the caller to be suspended. Non‑blocking returns immediately with a status value, allowing the caller to continue execution.
Synchronous vs Asynchronous
Synchronous focuses on the communication mechanism: the caller waits for a reply before proceeding. Asynchronous uses status, notification, or callback mechanisms to inform the caller of progress.
I/O Model Types
The five I/O models are:
Blocking I/O – all stages block.
Non‑blocking I/O – returns EWOULDBLOCK if no data is available.
I/O multiplexing (select/poll) – blocks in select/poll, then copies data when a descriptor becomes ready.
Signal‑driven I/O (SIGIO) – does not block in the wait stage but blocks in the copy stage; the kernel sends a signal when data is ready.
Asynchronous I/O (AIO) – completely non‑blocking; the kernel notifies the application via a signal when the operation completes.
Blocking I/O
When an application calls a function such as recvfrom, it blocks until the kernel has prepared the data and copies it to user space, after which the call returns.
Non‑Blocking I/O
The call returns immediately with EWOULDBLOCK if no data is available. The application must repeatedly poll the descriptor until data arrives, which wastes CPU cycles.
I/O Multiplexing (select and poll)
The process blocks in select or poll waiting for one of several descriptors to become ready. Once a descriptor is ready, the application calls recvfrom to copy the data.
Signal‑Driven I/O (SIGIO)
The application enables SIGIO on a socket and installs a handler. If data is not ready, the call returns immediately; when data becomes ready, the kernel sends a SIGIO signal, and the handler can then read the data.
Asynchronous I/O (AIO)
The application issues an I/O request and continues execution. The kernel performs the operation and, upon completion, notifies the application via a signal or callback.
Summary and Comparison of the Five I/O Models
From the diagrams we see that as we move from blocking to fully asynchronous models, the amount of blocking decreases and theoretical efficiency increases. The first three models are synchronous I/O, while the last two are asynchronous.
Synchronous I/O
Blocking I/O, Non‑blocking I/O, I/O multiplexing (select/poll)
Asynchronous I/O
Signal‑driven I/O (SIGIO), Semi‑asynchronous, Asynchronous I/O (AIO) – full asynchronous.
Difference Between Asynchronous I/O and Signal‑Driven I/O
In signal‑driven I/O the kernel can notify the application with a SIGIO signal when it is ready to copy data. In asynchronous I/O the kernel notifies the application only after the entire operation has been completed.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
