I/O management and disk structure
I/O management and disk structure
Recorded by Dr. Krithika L.B. Slot m5-io-disk
How the kernel talks to devices (polling, interrupts, DMA, buffering, caching, spooling), how a disk is organised and timed, and how RAID levels trade capacity for speed and reliability.
By the end of this session you should be able to:
Devices vary enormously — keyboards deliver a few bytes per second, NVMe SSDs gigabytes. The OS hides this variety behind a layered I/O subsystem:
The CPU repeatedly reads the controller's busy bit. Fine if the device is fast; wasteful otherwise.
The controller raises an interrupt when done (Session 1.4). The CPU works on something else meanwhile.
For bulk transfers the CPU programs a DMA controller with source, destination and count; the controller moves the whole block and interrupts once.
Memory holding data in transit — copes with speed mismatch (modem → disk) and size mismatch; double buffering lets one buffer fill while the other is written.
Keeps copies of data in faster storage (the page cache) so repeated reads avoid the device.
A buffer for a device that cannot interleave jobs (a printer): output is queued on disk and printed one job at a time.
A hard disk drive (HDD) has several platters, each with two surfaces covered by concentric tracks divided into sectors (512 bytes or 4 KB). The set of tracks at one arm position across all platters is a cylinder. A read–write head on an arm floats over each surface.
\[ \text{access time} = \text{seek time} + \text{rotational latency} + \text{transfer time} \]
The disk is addressed as a large one-dimensional array of logical blocks, mapped onto sectors in order (track by track, cylinder by cylinder). SSDs (flash) have no moving parts — no seek or rotational latency — so disk scheduling matters far less for them; they instead wear out with writes and need wear-levelling.
Before use a disk is low-level formatted (sectors with headers and error-correcting codes), partitioned, and logically formatted (a file system is created — Module 4). One partition holds the boot block (Session 1.4).
Many cheap disks can be organised for performance (read and write in parallel by striping data across disks) and reliability (survive a disk failure through redundancy: mirroring or parity). With 100 disks each having a mean time to failure of 100 000 hours, some disk fails every 1000 hours (~42 days) — redundancy is essential.
Striping, no redundancy. Block 0 → disk 0, block 1 → disk 1, … Fastest and uses 100% of capacity, but one failure loses everything.
Mirroring. Every block is written to two disks. Survives one disk failure; reads can use either copy; 50% capacity.
RAID 2: bit-level striping with Hamming-code ECC disks (obsolete). RAID 3: byte/bit-interleaved data plus a single parity disk; the controller can rebuild any one failed disk from the others' parity.
Block-level striping + a dedicated parity disk. Parity P = A1 ⊕ A2 ⊕ A3 (XOR). If a disk fails, its block = XOR of the survivors. Problem: every write updates the single parity disk — a bottleneck.
Block-level striping with distributed parity. Parity blocks are spread across all disks, removing RAID 4's bottleneck. Survives one failure; capacity (n − 1)/n. The most common parity RAID.
P + Q redundancy. Like RAID 5 with a second, independent parity — survives two simultaneous failures (important for large disks with long rebuild times). Capacity (n − 2)/n.
Nested RAID. RAID 1+0 (RAID 10) mirrors pairs of disks and then stripes across the pairs — high performance and reliability, 50% capacity; preferred for databases. RAID 0+1 stripes first then mirrors the stripes.
Data blocks 1011, 0110, 1100 → parity = 1011 ⊕ 0110 ⊕ 1100 = 0001. If the disk holding 0110 dies: 1011 ⊕ 1100 ⊕ 0001 = 0110 — recovered.
| Level | Technique | Usable capacity (n disks) | Failures survived | Typical use |
|---|---|---|---|---|
| 0 | Striping | n | 0 | Scratch space, video editing |
| 1 | Mirroring | n/2 | 1 per mirror | OS disks, small servers |
| 5 | Striping + distributed parity | n − 1 | 1 | File servers |
| 6 | Striping + double parity | n − 2 | 2 | Large archives |
| 10 | Mirror + stripe | n/2 | 1 per mirror pair | Databases |
Example: six 4 TB disks give 24 TB in RAID 0, 12 TB in RAID 1/10, 20 TB in RAID 5, 16 TB in RAID 6.
I/O management and disk structure
Recorded by Dr. Krithika L.B. Slot m5-io-disk
RAID levels
Recorded by Dr. Krithika L.B. Slot m5-raid
Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.
Answer each question in your own words first, then reveal the model answer.
Revealed 0One rotation = 60/5400 s = 11.11 ms → average = 5.56 ms.
Interrupting the CPU for every byte or word would waste it; DMA moves a whole block and interrupts once.
A buffer may hold the only copy of data in transit; a cache holds a copy of data that also exists elsewhere, to speed up access.
(5 − 1) × 2 = 8 TB; one disk failure.
Parity is distributed over all disks, so parity updates do not all hit one dedicated parity disk.
Seek time dominates HDD access. With many requests waiting, the order in which we serve them decides how far the arm travels. Next: disk-scheduling algorithms.
Continue to 5.2 — Disk scheduling algorithms →