Skip to main content

Lesson 19 of 26 · 12 min read

Hard disk drives and RAID

Calculate hard disk seek, rotational, and transfer latency, understand disk scheduling (SSTF/SCAN/SPTF), and compare RAID-0, RAID-1, RAID-4, and RAID-5 analytically.

Four storage and RAID topics: Seek + Rotate, RAID-0 / 1, RAID-4/5 parity, and Small-write cost.
Mechanical seek and rotational math govern hard drives while RAID levels balance capacity, failure tolerance, and write cost.
Course syllabus · lesson 19 of 26
In this lesson

File systems talk to any disk as a clean linear array of 512-byte or 4 KiB sectors (0..N-1). Beneath that uniform block interface, spinning Hard Disk Drives (HDDs) are mechanical devices whose performance varies by over two orders of magnitude depending on whether accesses are random or sequential.

The crux of the problem is two-fold: how HDD seek and rotation mechanics dictate I/O timing (T_I/O), and how combining multiple drives into a RAID delivers higher capacity, speed, and fault tolerance without turning tiny random writes into a bottleneck.

HDD I/O timing formula (seek plus rotation plus transfer) feeding into four RAID levels: RAID-0 striping, RAID-1 mirroring, RAID-4 dedicated parity bottleneck, and RAID-5 rotated parity with 4-I/O small-write penalty.
Open full-size diagram
HDDs punish random seeks; RAID arrays combine disks transparently for speed and redundancy, trading usable capacity against write amplification.

Reconstruct a missing RAID-5 block

Disk 0 A = 6, Disk 1 B = 3, Disk 2 C = 5, Disk 3 parity = 0Disk 0A = 6Disk 1B = 3Disk 2C = 5Disk 3parity = 0

Step 1 of 3

Store one stripe

This four-disk stripe stores three data blocks and one XOR parity block. In RAID-5 other stripes rotate the parity position.

Inside a spinning disk: Seek, rotate, transfer

Every HDD I/O pays three distinct physical delays:

  • T_seek: Moving the mechanical arm onto the target concentric track (typical average ~4–10 ms).
  • T_rotation: Waiting for the platter spinning at 7,200 to 15,000 RPM to bring the target sector under the read/write head. Average wait = half a full rotation (1 / (2 * RPS) — e.g., at 10,000 RPM, 1 rev = 6 ms, so average T_rotation = 3 ms). Track skew staggers block numbering across tracks so sequential reads do not miss the start of the next track during a 1-track settle!
  • T_transfer: Streaming bytes past the head (transfer_size / max_transfer_rate, tiny microseconds for 4 KiB).

Summing all three gives T_I/O = T_seek + T_rotation + T_transfer, yielding R_I/O = Size / T_I/O. Compare a typical drive (9 ms avg seek, 4.2 ms avg rotation, 100 MB/s stream):

  • Random 4 KiB workload: T_I/O = 13.2 ms -> ~0.31 MB/s (abysmal!).
  • Sequential 100 MB workload: One seek+rotate (13.2 ms) amortized across 100 MB -> ~98.7 MB/s — over 300x faster!

To tame random requests, disk schedulers reorder queued requests by physical proximity: SSTF (shortest seek first, risks starvation), SCAN / C-SCAN (sweep the arm across tracks like an elevator), and SPTF (shortest positioning time first, combining both seek and rotation — usually implemented inside the drive's own firmware!).

Track position changes during a seek

A platter can have two recordable surfaces. Each surface has its own head, and a track is one ring of sectors on one surface. Tracks at the same radius form a cylinder. Switching to another head on that cylinder avoids a long radial seek, though the switch itself can take time. A logical block number identifies a sector through the drive firmware. Modern disks can put more sectors on longer outer tracks and remap defective sectors, so dividing a logical block number by a fixed track size is safe only in a model that specifies that geometry.

For a timing trace, assume one recording surface, 12 sectors per track, and exactly 7,200 RPM. A revolution takes 60 / 7200 s = 8.333 ms, and one sector passes every 0.694 ms. Number the sectors on track 0 from 0 through 11. The head is over the start of sector 10 and needs to read sector 11. It waits one slot and transfers for one slot, finishing about 1.389 ms later. At that instant the disk is at angular slot 0. If moving to the next track takes two sector times, the head reaches the next track at slot 2. With no skew the next logical sector started passing at slot 0, so it now waits another ten slots. Place the next track's first logical sector at angular slot 2 and the head can start reading it immediately after the move.

The disk continues rotating while the arm seeks. Suppose two equal-size requests are queued. The closer track takes 1 ms to reach, but its sector has just passed at arrival, so the residual rotational wait is 7 ms. A farther track takes 3 ms to reach and the sector arrives 0.5 ms later. Shortest seek chooses the first request at 8 ms of positioning. Shortest positioning chooses the second at 3.5 ms. With sustained arrivals, a sweep or an age limit gives old requests a chance to get serviced even when newer requests are mechanically cheaper.

Average rotational delay assumes each request arrives at a uniformly random angular position. A single 4 KiB request on the drive above takes about 13.241 ms if the model rounds the mean rotation to 4.2 ms. Its service rate is about 75.5 IOPS. Multiply by 4,096 bytes per operation to get roughly 0.309 MB/s in decimal units. These are single-request service estimates. End-to-end response time also includes queueing, and a deeper queue can change the average service time by giving the scheduler more choices.

RAID: Turning multiple disks into one fast, reliable virtual drive

RAID (Redundant Array of Inexpensive Disks) uses the same transparency trick as virtual memory: present N physical disks as a single logical block array. Assume a fail-stop fault model (1 dead disk detectable immediately) across N identical disks of capacity C, sequential speed S, and random speed R:

  1. RAID-0 (Striping): Spread chunks round-robin across all N disks. With one block per chunk, logical block b goes to disk b mod N at disk block floor(b / N).
    • Capacity: N * C (100%). Fault tolerance: 0 disks (any disk failure loses data!). Speed: With balanced requests and enough parallel work, sequential throughput can approach N * S and random throughput can approach N * R.
  2. RAID-1 (Mirroring): Organize an even number of disks into mirrored pairs and stripe across the pairs. Each logical chunk has two copies.
    • Capacity: (N / 2) * C (50%). Fault tolerance: 1 disk guaranteed (and up to N/2 if each pair keeps one survivor). Speed: Sequential reads reach (N / 2) * S (or N * S), sequential writes (N / 2) * S, random reads N * R, random writes (N / 2) * R (every logical write hits 2 physical mirrors).
  3. RAID-4 (Dedicated Parity Disk): Store N - 1 data disks plus 1 disk holding the XOR parity (D0 ^ D1 ^ D2 ^ P = 0) across every stripe! If any single disk dies, reconstruct its exact bits by XORing all N - 1 surviving drives!
    • Capacity: (N - 1) * C. Fault tolerance: 1 disk.
    • The Small-Write Problem: Updating one 4 KiB block without rewriting the whole stripe uses subtractive parity: read old D_old (1), read old P_old (2), compute P_new = (D_old ^ D_new) ^ P_old, write new D_new (3), write new P_new (4) -> 4 physical I/Os per logical write! Worse yet, in RAID-4 every write must touch that single dedicated Parity disk, serializing random write throughput to R / 2 no matter how many drives you buy!
Code exampleTrace
RAID-5 Subtractive Parity Update (1 logical 4 KiB write -> 4 physical I/Os):
  1. Read  D_old (target data disk)  +  Read  P_old (stripe parity disk)
  2. Compute P_new = (D_old XOR D_new) XOR P_old
  3. Write D_new (target data disk)  +  Write P_new (stripe parity disk)

  1. RAID-5 (Rotating Parity): Keeps (N - 1) * C capacity and 1-disk tolerance, while rotating parity chunks across all N disks stripe by stripe! Balanced random reads can reach N * R. Small random writes with balanced data and parity traffic can reach (N / 4) * R under the four-I/O update model.

A long full-stripe write to either parity layout can stream three data chunks per four physical chunks written, for an ideal host write rate of (N - 1) * S. A four-drive pair-mirrored array streams two logical chunks per four physical chunks written, for (N / 2) * S. These estimates assume that all drives stay busy. If a workload repeatedly reads one hot block, a single-copy layout sends that traffic to one disk. With mirroring, the controller can choose either copy and spread independent requests across the pair.

Worked trace: 4-disk RAID capacity and small-write I/O

Evaluate a 4-disk array of 1 TB drives (R = 100 IOPS, S = 100 MB/s each):

  1. Usable capacity: RAID-0 = 4 TB (0 faults), RAID-1 = 2 TB (1+ fault), RAID-4 = 3 TB (1 fault), RAID-5 = 3 TB (1 fault).
  2. Trace one 4 KiB random write to Block 1 on RAID-5: Block 1 belongs to Stripe 0 (D1), whose parity sits on Disk 3 (P0). RAID-5 issues parallel reads (D1_old, P0_old), XORs D1_old ^ D1_new ^ P0_old, and writes (D1_new, P0_new) — 4 physical I/Os.
  3. Compare parity placement: Now issue two concurrent 4 KiB writes: Block 1 (Stripe 0, parity on Disk 3) and Block 4 (Stripe 1, parity on Disk 2). On RAID-4, both writes fight for the single dedicated parity Disk 3 (bottleneck!). For this RAID-5 layout their parity hits disks 3 and 2, respectively. Both data chunks can still land on disk 1, so the two operations can overlap while competing for that disk. Parity rotation balances load across many stripes.

Do the XOR and count the work

Use one 4 KiB chunk per disk per stripe. For RAID-5 in this example, select parity disk 3 - (stripe mod 4) and place the three data chunks on the remaining disks in ascending order. To locate logical block b, divide by three. The quotient is the stripe and the remainder is the index among that stripe's data disks. Block 4 gives stripe 1 and data index 1. The data disks are 0, 1, and 3, so disk 1 holds block 4 and disk 2 holds its parity. With larger chunks, apply this calculation to the logical chunk number, then add the intra-chunk block offset.

Trace only the first byte in each chunk, since XOR works independently on every bit. Stripe 0 contains D0 = 0x3C, D1 = 0xA5, and D2 = 0x0F. Old parity is 0x96. Change D1 to 0xC2. The change mask is 0xA5 XOR 0xC2 = 0x67. Applying it to old parity gives 0x96 XOR 0x67 = 0xF1. If disk 1 now fails, 0x3C XOR 0x0F XOR 0xF1 reconstructs 0xC2. If the parity disk fails, reading all three data chunks is enough to rebuild parity. An otherwise healthy read of one data chunk touches a single disk. A read of that missing chunk needs the three survivors and therefore competes with other requests across the array.

For one changed block on this four-drive array, the subtractive update reads old data and old parity and then writes new data and new parity. The controller can also generate parity from the two unchanged chunks and the incoming new data. That alternative also costs two reads and two writes here. On a wider array, reconstructing parity from all unchanged data may cost more for one change and less when most blocks in the stripe are changing. A full-stripe write knows all three new data chunks and calculates parity from them. It issues four writes and zero old-block reads for 12 KiB of host data.

On the illustrative 100-IOPS drives, RAID-4 can issue at most 100 / 2 = 50 logical small writes per second because each requires a parity read and write on the same disk. RAID-5 has an ideal budget of 400 / 4 = 100 such writes per second if work balances. Treat these as throughput estimates, distinct from the latency of a lone write. Its writes depend on the results of the read phase even when both operations within each phase overlap. Finally, the two updated chunks must agree after power loss. If new data persists and old parity remains, reconstruction can produce the wrong bytes. A controller needs a way to recover such interrupted updates, for example a durable record of work in progress.

Next, build an actual POSIX file system on top of a block device in files, directories, and VSFS.

Before you move on

Try it in your workspace

Compare a 4-disk RAID-0, RAID-1, RAID-4, and RAID-5 array on capacity, fault tolerance, sequential throughput, and random small writes (including RAID-4 parity bottleneck vs. RAID-5 rotation).

Keep a short note of what you tried, what passed, and what you still need to check.

Your practice record

0 of 3 checked.

Saved in this browser when storage is available. Uncheck any item to revisit it. This is your own record, not an assessment.