Chapter 13: I/O Systems

I/O Hardware and Application I/O Interface

I/O Hardware Basics

I/O devices vary widely in functionality and performance. Common categories:

  • Block Devices Transfer data in fixed-size blocks (e.g., disks, SSDs).

  • Character Devices Stream-oriented (e.g., keyboards, mice, terminals).

  • Network Devices Exchange packets with remote systems.

Key hardware components:

  • Controller – Electronics that operate a device.

  • Device Registers – Used for control, status, and data transfer.

  • Interrupts – Notify CPU that I/O has completed.

  • DMA (Direct Memory Access) Hardware that transfers data between memory and device without CPU involvement.

Application I/O Interface

The OS provides I/O abstractions:

  • Blocking vs Non-blocking I/O – Synchronous vs asynchronous execution.

  • Memory-Mapped I/O – Device registers appear as memory addresses.

  • File-Abstraction Model – Many devices appear as files (UNIX philosophy).

  • Device Drivers – Kernel modules that provide device-specific handling.

Standardized system calls include:

  • open(), close(), read(), write(), ioctl() for device control and data transfer.

Kernel I/O Subsystem

The kernel manages I/O using these components:

  • I/O Scheduling Determines order of requests to optimize performance (e.g., disk scheduling algorithms).

  • Buffering Temporary storage to handle speed mismatch, reduce overhead, or support copy semantics.

  • Caching Keeps recently accessed data in memory to reduce I/O operations.

  • Spooling Queues output for devices that cannot accept interleaved jobs (e.g., printers).

  • Device Reservation Prevents simultaneous access to devices that only support exclusive use.

  • Error Handling Retries, fallback routines, and reporting of hardware errors.

I/O Request Life Cycle

The typical sequence of an I/O request:

  1. Application issues I/O call (e.g., read() or write())

  2. Kernel verifies parameters Checks permissions, device state, and request validity.

  3. Device driver activation Driver converts request into device-specific commands.

  4. Scheduling and dispatching I/O scheduler places the request in a queue; device driver sends it to the hardware.

  5. Device performs operation Possibly using DMA for data transfer.

  6. Interrupt occurs Device notifies CPU that operation is complete.

  7. Kernel interrupt handler runs Updates status, wakes up blocked processes.

  8. Application resumes Returns success or failure code.