4.2.39Operating Systems

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

2,093 words10 min readdifficulty · medium

WHY does RAID exist?

The core tension: you cannot maximize capacity, speed, and reliability all at once. Pick your trade-off.


HOW parity works (derive it from scratch)

Derivation. Let data blocks be D1,D2,,Dn1D_1, D_2, \dots, D_{n-1} across n1n-1 disks. Define parity: P=D1D2Dn1P = D_1 \oplus D_2 \oplus \cdots \oplus D_{n-1} Suppose disk kk dies. We know all other DiD_i and PP. XOR everything we still have: D1Dk1Dk+1PD_1 \oplus \cdots \oplus D_{k-1} \oplus D_{k+1} \oplus \cdots \oplus P Substitute PP and use \oplus properties: xx=0x \oplus x = 0 and x0=xx \oplus 0 = x. Every surviving block cancels its own copy inside PP, leaving: =Dk = D_k

For RAID 6 we add a second, independent parity QQ using Reed–Solomon over a Galois field GF(28)GF(2^8): Q=igiDiQ = \bigoplus_i g^{i}\cdot D_i Two independent equations (PP and QQ) let you solve for two unknowns → survives 2 disk failures.


The five levels

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

The write penalty (WHY RAID 5/6 writes are slow)


Worked examples


Common mistakes (steel-manned)


Recall Feynman: explain to a 12-year-old

Imagine you and friends each copy one page of a comic. RAID 0: everyone holds a different page — super fast to read all at once, but if one friend loses their page the comic is ruined. RAID 1: two friends hold the same pages, so if one drops out the other still has it. RAID 5: each friend also writes down a magic "summary number" so that if any one friend vanishes, the rest can rebuild the missing page from the summary. RAID 6: two magic summaries, so even if two friends vanish you're fine. RAID 10: pair up friends as backups, then split the comic across the pairs — fast and safe.


Active recall

What does RAID stand for?
Redundant Array of Independent Disks.
Which RAID level has zero redundancy?
RAID 0 (pure striping).
Usable capacity of RAID 5 with n disks?
(n − 1) disks worth.
Usable capacity of RAID 6 with n disks?
(n − 2) disks worth.
How many disk failures does RAID 6 survive?
Two simultaneous failures.
Parity recovery formula for a lost block D_k?
D_k = P ⊕ (XOR of all surviving data blocks).
Why does XOR parity recover exactly one disk?
XOR is self-inverse (x⊕x=0); one parity = one equation = one unknown solvable.
How many I/Os for a small RAID 5 write, and why?
4 — read old data, read old parity, write new data, write new parity.
Formula for updating parity on a small write?
P_new = P_old ⊕ D_old ⊕ D_new.
Difference between RAID 10 and RAID 0+1?
RAID 10 = mirror then stripe (more failure-tolerant); 0+1 = stripe then mirror.
Why does RAID 6 use a second parity Q instead of another XOR P?
Two copies of XOR give the same equation; Q uses GF(2^8) coding to be independent, allowing two unknowns to be solved.
Is RAID a substitute for backups?
No — it guards against disk failure, not deletion/corruption/ransomware.
Which levels are best for a write-heavy database?
RAID 10 (fast writes + redundancy); avoid parity levels for small random writes.

Connections

  • XOR and Boolean Algebra — the math behind parity.
  • Galois Fields GF(2^n) — basis of RAID 6's second parity.
  • Disk Scheduling — how striping improves throughput.
  • Reliability and MTBF — quantifying failure tolerance.
  • Backups vs Redundancy — why RAID ≠ backup.
  • File Systems — RAID sits below the filesystem layer.

Concept Map

uses knob

uses knob

uses knob

gives

gives

via XOR

only

only

plus single parity

single erasure

add 2nd parity Q GF 2^8

mirror then stripe

mirror then stripe

RAID Array

Striping

Mirroring

Parity

Speed no redundancy

Redundancy costs 50pct

Rebuild 1 missing disk

RAID 0 capacity n

RAID 1 capacity n/2

RAID 5 survives 1

RAID 6 survives 2

RAID 10 speed plus redundancy

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, ek single disk ke do problem hote hain: woh slow hoti hai (sirf ek hi head se padh-likh sakti hai) aur fragile hoti hai (ek failure matlab pura data gaya). RAID ka idea simple hai — kai disks ko mila ke ek bada logical disk banao, taaki tum speed, reliability, ya dono khareed sako. Lekin har level mein tumhe kuch na kuch pay karna padta hai: capacity, paisa, ya write speed.

Levels yaad rakhne ka tareeka: RAID 0 = sirf striping, sabse fast par zero safety — ek disk gayi to sab gaya. RAID 1 = mirroring, har disk ka exact copy, par aadhi capacity barbaad. RAID 5 = striping + ek parity block jo XOR se banta hai aur saari disks par ghoomta hai; ek disk fail ho to parity se rebuild ho jaati hai (capacity n−1, tolerate 1). RAID 6 = do parity (P aur Q), do disk failures tak survive (capacity n−2). RAID 10 = pehle mirror, phir stripe — fast bhi, safe bhi, par mehnga.

Parity ka magic XOR hai: P=D1D2P = D_1 \oplus D_2 \oplus \cdots. Agar koi block missing ho jaye, to baaki sab ko parity ke saath XOR karo aur missing block wapas mil jata hai, kyunki xx=0x\oplus x=0. Yeh sirf ek missing piece fix kar sakta hai — isliye RAID 5 sirf 1 failure handle karta hai. Ek important point: chhoti write mein RAID 5 ko 4 I/O lagte hain (purana data + purana parity padho, naya data + naya parity likho), isliye parity levels write-heavy databases ke liye slow hote hain — wahan RAID 10 better hai.

Sabse bada exam-trap: RAID ko backup mat samajhna! RAID disk failure se bachata hai, par galti se delete, virus, ya fire se nahi — kyunki woh galti turant mirror par bhi copy ho jaati hai. Backup alag cheez hai.

Go deeper — visual, from zero

Test yourself — Operating Systems

Connections