I/O モデル
Unix I/O モデル説明
I/O モデル
- Synchronous IO
Blocking I/OModel (Blocking / Synchronous) : BIO, ブロッキング IONon-Blocking I/O(Non-Blocking / Synchronous) : NIO, ノンブロッキング IOI/O Multiplexing(Blocking / Asynchronous): I/O 多重化Signal-driven I/O(SIGIO): シグナル駆動 、Synchronous I/O に属 する
Asynchronous I/O(Non-Blocking / Asynchronous): AIO, 非同期 IO

BIO
sequenceDiagram
participant App as Application
participant K as Kernel
Note over App: process blocks in a call to recvfrom
App ->> K: recvfrom - system call
K ->> K: no datagram ready
Note over K: wait for data
K ->> K: no datagram ready
Note over K: wait for data
K ->> K: datagram ready
K ->> K: copy datagram
K ->> K: copy complete
Note over K: copy data from kernel to user
K ->> App: return OK
App ->> App: process datagram
NIO
sequenceDiagram
participant App as Application
participant K as Kernel
Note over App: process repeatedly calls recvfrom, waiting for an OK return (polling)
App ->> K: recvfrom - system call
K ->> K: no datagram ready
K ->> App: EWOULDBLOCK
App ->> K: recvfrom - system call
K ->> K: no datagram ready
K ->> App: EWOULDBLOCK
App ->> K: recvfrom - system call
K ->> K: no datagram ready
K ->> App: EWOULDBLOCK
Note right of K: wait for data
App ->> K: recvfrom - system call
K ->> K: datagram ready
Note right of K: copy data from kernel to user
K ->> K: copy datagram
K ->> K: copy complete
K ->> App: return OK
App ->> App: process datagram
IO Multiplexing
sequenceDiagram
participant App as Application
participant K as Kernel
Note over App: process repeatedly calls select, waiting for one possibly many sockets to become readable
App ->> K: select - system call
K ->> K: no datagram ready
Note over K: wait for data
K ->> K: datagram ready
K ->> App: return readable
Note over App: process repeatedly calls select, waiting for one possibly many sockets to become readable
App ->> K: recvfrom - system call
K ->> K: copy datagram
Note right of K: copy data from kernel to user
K ->> K: copy complete
K ->> App: return OK
App ->> App: process datagram
Signal-Driven IO
sequenceDiagram
participant App as Application
participant K as Kernel
Note over K: wait for data
App ->> App: establish SIGIO signal handler
App ->> K: sigaction - system call
K ->> App: return
Note over App: process continues executing
K ->> K: datagram ready
Note over App: process blocks while data copied into application buffer
Note left of App: signal handler
K ->> App: deliver SIGIO
App ->> K: recvfrom - system call
K ->> K: copy datagram
Note right of K: copy data from kernel to user
K ->> K: copy complete
K ->> App: return OK
App ->> App: process datagram
AIO
sequenceDiagram
participant App as Application
participant K as Kernel
Note over K: process continues executing
App ->> K: aio_read - system call
Note over App: wait for data
K ->> K: no datagram ready
K ->> App: return
K ->> K: datagram ready
Note right of K: copy data from kernel to user
K ->> K: copy complete
K ->> App: deliver signal specified in aio_read
Note over App: signal handler process datagram
Network IO
入出力
(IO) 操作
の核心
概念
は、User Space Buffer と Kernel Space Buffer 間
でのデータ相互
コピーです。
通常 、以下 の 2 つのステップを含 みます:
- ネットワークデータが NIC に到着
するのを待
つ (read-ready) / NIC が Writable になるのを待
つ (write-ready)
→
Kernel Space Bufferに read / write Kernel Space BufferからUser Space Bufferにデータをコピー (read)User Space BufferからKernel Space Bufferにデータをコピー (write)