An introduction to the concepts related to I/O systems.
Overview
Ports, buses, and device controllers connect to various devices and peripherals.
I/O Hardware
Device types: Storage, Transmission, and Human-Computer Interface
A port is the connection point of a device; a bus is used for data transfer between devices, common ones being the PCI bus, PCI Express (PCIe), etc.; a controller is responsible for operating ports, buses and devices, some integrated and some on separate circuit boards.
A Typical PC Bus Structure
Host-Controller Communication
There are two approaches: special I/O instructions and memory-mapped I/O. Data transfer control methods include polling and interrupts; polling suits fast devices, while interrupts can improve efficiency. Direct memory access (DMA) is used for large data transfers and can bypass the CPU to transfer data directly between I/O devices and memory.
Application I/O Interface
I/O system calls encapsulate device behavior into generic classes, letting applications access different devices in a uniform way. The device driver layer hides the differences between I/O controllers from the kernel.
| aspect | variation | example |
|---|---|---|
| data-transfer mode | character block | terminal disk |
| access method | sequential random | modem CD-ROM |
| transfer schedule | synchronous asynchronous | tape keyboard |
| sharing | dedicated sharable | tape keyboard |
| device speed | latency seek time transfer rate delay between operations | |
| I/O direction | read only write only read-write | CD-ROM graphics controller disk |
The operating system classifies I/O devices:
- Block I/O devices such as disk drives transfer and store data in units of data blocks, support operations such as read, write and seek, and also allow raw I/O, direct I/O or file-system access; memory-mapped file access can be implemented on top of the block device driver.- Character I/O devices include the keyboard, mouse, serial ports, etc.; they transfer data as a stream of characters, with commands such as get () and put (), and line editing can be implemented by libraries in the layer above.
- Memory-mapped file access maps a file into virtual memory and fetches data blocks by demand paging.
- Network sockets are used for network communication; their performance differs from block and character devices, and they have their own interface, common in operating systems such as Linux, Unix and Windows. The socket interface separates the network protocols from network operations, and includes the select () function, which returns which sockets have packets waiting or have room to accept new packets

Vectored I/O
Vectored I/O is an efficient form of I/O that allows multiple data blocks to be transferred in a single system call. It works by passing the addresses and lengths of multiple buffers to the kernel, which then reads data from or writes data to these buffers, reducing the number of system calls and improving performance.
Kernel I/O Subsystem

- I/O Scheduler: responsible for scheduling I/O requests, deciding the order and manner in which requests are executed to improve system performance.
- Buffering: allocates buffers in memory for I/O operations to improve data transfer efficiency.
- Caching: keeps frequently accessed data in memory to reduce disk accesses and improve performance.
- Spooling: sets aside a buffer area on disk to temporarily hold device output data; commonly used for devices such as printers.
- Device reservation: ensures that a device is not used by other processes during an I/O operation.
- Error handling: responsible for detecting and handling errors in I/O operations.
I/O protection: to prevent user processes from disrupting normal system operation with illegal I/O instructions, all I/O instructions are made privileged, and users can only perform I/O operations through system calls.
Kernel keeps state info for I/O components, including open file tables, network connections, character device state
Transforming I/O Requests to Hardware Operations
Consider reading a file from disk for a process:
- Determine the device holding the file
- Translate name to device representation
- Physically read data from disk into the buffer
- Make data available to the requesting process
- Return control to process
File System Layers and Operations
Life Cycle of An I/O Request
Translated from the Chinese original.

