4.2.39 · D2Operating Systems

Visual walkthrough — RAID — levels 0, 1, 5, 6, 10 — trade-offs

1,906 words9 min readBack to topic

We only need one tool the whole way through: an operation called XOR. So we start there.


Step 1 — Meet XOR, the "are they different?" switch

WHAT. Before any disks, we define the single operation this whole page rests on. Write it as (a plus inside a circle). It takes two bits — a bit is just a or a — and outputs one bit. The rule is: output if the two inputs differ, output if they are the same.

Here is the operation; each and on the left is an input bit; each result on the right is the output bit. That is the entire definition — there is nothing hidden.

WHY this tool and not addition? Ordinary addition would give , which is not a bit — it overflows. We need an operation that stays inside and can be undone. XOR does both. (This is the same you met in XOR and Boolean Algebra.)

PICTURE. The truth table drawn as a light-switch: same inputs → light off (), different inputs → light on ().


Step 2 — The two properties that make magic possible

WHAT. From the table in Step 1, read off two facts. Every symbol below is a single bit.

  • : a value XORed with itself vanishes — because a thing never differs from itself, so the switch is off.
  • : a value XORed with is unchanged — because agrees where is and differs where is , leaving exactly.

Two more bookkeeping facts, straight from the table:

  • Commutative: (order does not matter).
  • Associative: (grouping does not matter).

WHY we collect these. These four rules are the only algebra we will use. "Vanishes with itself" is the trick that recovers a lost disk; "commutative + associative" is what lets us shuffle terms freely to make that cancellation happen.

PICTURE. Two bits meeting: identical pair → annihilate to ; anything meeting → passes through untouched.


Step 3 — Lay out the disks and build the parity block

WHAT. Now the disks. Picture disks side by side. On one stripe (one horizontal row across all disks) we store data blocks — one per disk — and reserve the last disk for a computed parity block . Each is just a string of bits living on disk . We define:

Read left to right: XOR the first two data blocks, then XOR the third into that running result, and so on. is the final running total — the "summary number" the Feynman story in the parent called magic.

WHY define it this way? Because of Step 2, this single block secretly "remembers" every in a way we can peel back out. We are not storing a copy of any disk — is smaller than that (one block, not ) — yet it holds enough to reconstruct any one lost block. That is the whole economy of RAID 5.

PICTURE. A stripe: data blocks flowing into an XOR gate, out comes the parity block on the dedicated cell.


Step 4 — A disk dies: set up the rescue

WHAT. Suppose disk fails, so is gone. We still hold every other data block and . Collect everything we still have and XOR it all together:

is our candidate rescue value — call it "everything left, XORed." We have not proven anything yet; we have only gathered what survived.

WHY start here? XOR is self-inverse (Step 2), so the natural move to undo a mixture is to XOR again. We throw the survivors back into hoping they cancel their own contributions and leave only the missing one.

PICTURE. The array with one greyed-out dead disk; arrows drag every surviving block plus into a single XOR machine.


Step 5 — Watch the survivors cancel, term by term

WHAT. Substitute the definition of from Step 3 into . Every survivor now appears twice: once as itself, once buried inside .

Now use commutative + associative (Step 2) to pair each survivor with its twin:

Every pair becomes by . The only term without a partner is — because never showed up among the survivors, it only lives inside . All those zeros pass through by , and what remains is:

WHY it works. This is the punchline: carried a copy of 's contribution, and XORing every other block against erased everything except . The dead disk is reborn.

PICTURE. A cancellation ladder: each survivor pairs with its ghost inside , both collapse to , and is left standing alone in the spotlight.


Step 6 — Concrete numbers (the derivation, checked)

WHAT. Take three 4-bit blocks and run the whole machine.

  • .
  • Build (Step 3): first (XOR each column), then . So .
  • Now disk 2 dies. Rescue (Step 5): .
    • ,
    • .
  • Result exactly the original . ✓

WHY show numbers. The algebra was symbolic; this proves the ghosts really cancel on a real stripe. Column-by-column, the "different?" rule reproduces the lost data with zero guessing.

PICTURE. The four bit-strings stacked as coloured columns, the XOR sweeping down each column, recovered glowing to match the original.


Step 7 — The edge case: why parity fixes ONE disk, never two

WHAT. What if two disks die at once — say and ? Run the rescue: XOR everything we still have. Now two terms have no twin, so instead of a clean answer we get:

WHY this is a dead end. That is a single equation with two unknowns — like being told "" and asked for . Infinitely many give the same ; parity cannot tell them apart. One parity block = one equation = can solve for exactly one missing block. This is the precise reason RAID 5 survives only a single failure.

The RAID 6 fix (why a second XOR would not help). Adding another plain XOR parity just gives — the same equation again, useless. RAID 6 instead computes a second, independent check , where the are distinct nonzero multipliers from a Galois field $GF(2^8)$. Because each block is weighted differently, and are two different equations in the two unknowns — now solvable. Two independent equations → two failures survivable.

PICTURE. Left: one line through a plane (one equation), the unknown pair slides freely along it — unsolvable. Right: two crossing lines (P and Q) pin a single point — solved.


The one-picture summary

WHAT. The whole journey on one canvas: define → fold data into → a disk dies → XOR survivors against → ghosts cancel → returns; and the wall at two failures where one equation cannot hold two unknowns.

Recall Feynman: tell it like a story

You and your friends each memorise one page of a comic. One extra friend memorises a single "summary": for every letter, they write down whether an odd or even number of the real pages had ink at that spot — that odd/even flag is XOR. Now one friend disappears. The rest read out their pages, the summary-friend reads their flags, and together they can fill in exactly what the missing page said — because the summary already "knew" the missing page's contribution, and everyone else's answers cancel out, leaving only the gap. But if two friends vanish, the survivors and the one summary can only tell you the combination of the two missing pages, not each one — one clue, two blanks. That is why single parity (RAID 5) saves one friend, and why you need a second, cleverly different summary (RAID 6's ) to save two.


Active recall

What is the output of ?
if and differ, if they are the same.
Which XOR law makes a survivor cancel during recovery?
— a block XORed with its own copy inside vanishes.
Why does matter in the recovery proof?
All the cancelled pairs become , and XORing with those zeros leaves unchanged.
How do you rebuild lost block ?
.
Why can single parity recover only one disk?
Two dead blocks leave — one equation, two unknowns, unsolvable.
Why doesn't a second XOR parity give RAID 6 protection?
A second XOR equals the first equation; RAID 6 uses an independent parity so two equations solve two unknowns.