Operating Systems Reference/Persistence & I/O

I/O Devices & DMA

Block vs character devices, the device driver stack, DMA for zero-CPU transfers, and why read/write syscalls block (or return EAGAIN) when data isn't ready.

3/5Overview: 25m

Device types

TypeExamplesAccess pattern
BlockSSD, NVMe, HDDFixed-size sectors, buffered I/O
CharacterTTY, /dev/urandomByte stream, unbuffered
Networksockets (not a /dev file on Linux)Structured via socket API

Block devices sit behind a block layer with request queues; file systems stack above.

Driver stack (simplified)

syscall (read/write) → VFS → file system → block layer → device driver → hardware

The driver maps logical sectors to device commands (NVMe queues, SATA AHCI). Interrupts signal completion — the blocked process wakes from D state.

Polling vs interrupts vs DMA

  • Polling — CPU spins checking device status. Simple, wasteful.
  • Interrupts — device signals completion; CPU handles other work meanwhile.
  • DMA (Direct Memory Access) — device reads/writes RAM directly via bus master; CPU programs transfer, gets interrupt when done. Essential at Gbps+ throughput.

Why I/O blocks

A read() on an empty pipe or slow disk puts the process in interruptible sleep until data arrives. Non-blocking mode (O_NONBLOCK) returns EAGAIN immediately — the foundation of epoll/kqueue event loops.

SSD vs HDD (awareness)

HDDs: seek latency + rotational delay dominate random I/O. SSDs/NVMe: no mechanical seek; parallel channels; but write amplification and GC pauses still cause tail latency. iostat -x fields await and %util tell you if disk is the bottleneck.

Senior-level signal

High iowait in top means CPUs idle waiting for block I/O — scaling CPU won't help. Check await in iostat, whether you're doing synchronous writes without batching, and if the workload is random-read heavy on undersized provisioned IOPS (cloud EBS gp2 vs io2).

Where this goes next

Journaling & Crash Consistency explains what happens when power fails between a DMA transfer and the metadata update that makes it durable.

Further Reading

Hands-On Tasks (Optional)

Low-setup exercises on your local machine. No autograding — the goal is to build intuition, not pass a test.

  • Observe disk I/O with iostat

    Run `iostat -x 1 5` (Linux) while copying a large file (`cp /usr/lib/libc.so.6 /tmp/`). Note await, %util, and read/write throughput. On macOS: `iostat -d 1`.

    15m