Sub topic 8
RAID building blocks: striping, mirroring, and parity
This chapter assumes you know what a hard drive and an SSD are, and that you are comfortable with units such as GB and TB. It covers the three techniques that every RAID level is built from. Later chapters combine them into RAID 0, 1, 5, 6, and 10.
What RAID is
RAID (Redundant Array of Independent Disks) combines several physical drives into one logical volume. The operating system sees a single disk. The RAID controller or software decides how data is spread across the real drives.
A RAID level is a recipe built from three techniques. Each technique trades speed, safety, and capacity differently.
Striping
Striping splits data into chunks called stripes and writes them to several drives in turn. With two drives, chunk 1 goes to drive A, chunk 2 to drive B, chunk 3 to drive A, and so on.
- Reads and writes use all drives at once, so throughput rises.
- All drive capacity is usable.
- There is no redundancy. If one drive fails, every file that had a chunk on it is damaged.
Mirroring
Mirroring writes the same data to two or more drives at the same time. Each drive holds a full copy.
- If one drive fails, the other keeps serving data with no interruption.
- Reads can be fast, because either copy can answer.
- Usable capacity is only that of one drive, so half the raw space is spent on the copy.
Parity
Parity is a small piece of calculated data that lets the array rebuild lost data. The controller computes it with XOR (exclusive OR). XOR returns 1 when its two inputs differ and 0 when they match.
The parity block is the XOR of the data blocks in a stripe. If one drive fails, XOR-ing the surviving blocks with the parity block recreates the missing block.
# Three data blocks striped across three drives (4-bit values for readability)
a = 0b1010
b = 0b0110
c = 0b1100
# The parity block is the XOR of all data blocks
parity = a ^ b ^ c
print(format(parity, "04b")) # 0000
# If the drive holding b fails, XOR the survivors to rebuild it
rebuilt_b = a ^ c ^ parity
print(format(rebuilt_b, "04b")) # 0110
print(rebuilt_b == b) # TrueParity costs the space of one drive (or two, in RAID 6) and requires extra calculation on every write. In exchange, it protects against a drive failure at a lower capacity cost than mirroring.
Comparing the techniques
| Technique | Redundancy | Speed benefit | Capacity cost |
|---|---|---|---|
| Striping | None | Faster reads and writes | None |
| Mirroring | Full copy | Faster reads | Half or more of raw space |
| Parity | Rebuild from math | Faster reads, slower writes | One or two drives' worth |
Common mistakes
- Treating striping as redundancy. Striping alone makes the array less safe than one drive, because any single failure loses the data.
- Forgetting that these techniques are combined. RAID 10 uses mirroring and striping. RAID 5 uses striping and parity.
Exercise
A technician says, "I can lose any one drive and rebuild its contents by XOR-ing the remaining blocks." Which building block is being described, and why does it use less capacity than mirroring?
Show answer
Parity. The array stores one calculated XOR block per stripe instead of a full second copy of the data. That costs about one drive's worth of space, while mirroring costs half or more of the raw capacity.