Spooling and the I/O Subsystem Summary
Spooling
Spooling (Simultaneous Peripheral Operations On-Line) is a technique for managing exclusive-access devices (especially printers) in a multi-process system. Instead of each process competing directly for the device, processes write their output to a spool directory — a file or set of files on disk. A dedicated spooler daemon reads the spool directory and feeds jobs to the device one at a time.
Spooling converts a mutual exclusion problem (only one process can use the printer at a time) into a disk-space management problem (jobs queue up on disk). The spooler handles scheduling, prioritisation, and error recovery.
Advantages:
- Processes don’t block waiting for a slow device — they write to disk (fast) and continue.
- Jobs are queued in order; no race conditions for device access.
- The spooler can retry failed jobs, notify users of completion, and enforce quotas.
Disadvantages:
- Disk space is consumed (spool files may be large — think PostScript print jobs).
- A process may think its output is “printed” when it is only spooled; if the printer is down, the output is delayed silently.
I/O scheduling (elevator algorithms)
For disk I/O, the OS can reorder queued requests to improve throughput. The classic elevator algorithm (SCAN) services requests in order of increasing track number (like an elevator visiting floors), then reverses direction. Variants include:
- C-SCAN: services in one direction only, then jumps back to the beginning. Fairer — no request suffers worst-case latency at the end of a scan.
- Deadline scheduler: imposes per-request deadlines to bound latency; gives up some throughput for predictability.
- CFQ (Completely Fair Queueing): allocates I/O bandwidth proportionally between processes, analogous to CFS for CPU scheduling.
These algorithms matter primarily for rotating magnetic disks (HDDs), where seek time dominates and ordering requests can dramatically reduce total head movement. For SSDs (no seek time), the benefit is smaller, and fairness/predictability take priority.
Summary of the I/O subsystem
| Layer | Responsibility |
|---|---|
| System-call interface | open, read, write, ioctl — the uniform API |
| Virtual file system (VFS) | Dispatching to the correct file system or device driver |
| Buffer cache / page cache | Absorbing reads and writes in memory for speed |
| I/O scheduler | Reordering and merging requests for throughput |
| Device driver | Translating generic requests to device-specific operations |
| Hardware (device + DMA) | Executing the actual data transfer |
Summary
- Spooling queues exclusive-device access through a disk-backed spool directory and daemon.
- Elevator algorithms reorder disk requests to minimise seek time on HDDs.
- The I/O subsystem is a layered stack from system call to hardware registers.