CSE Roadmap

Core tier · about 3 hours · 6 parts

Part 5 of 6 · 3 min read

Choosing a level

Choosing a level

Think of three ways to pack for a trip: carry everything twice, carry one spare set of clothes for the whole group, or carry nothing spare. Each is light or safe in a different way. The analogy stops in one place: a packing choice affects you once, and a RAID level affects every write for the life of the array.

In plain words: The levels trade capacity, safety and speed. Random writes are the weak point of parity. If each disk handles 150 random operations per second (made up), six disks can do 6 x 150 = 900 per second in total. In RAID 0 each logical write is one disk operation, so the array does 900 writes per second. In RAID 10 it is two operations per write, so 450. In RAID 5 it is four, so 225. In RAID 6 it is six, so 150.

A worked example. The table is for six disks of 4 TB (made up). The last column gives the random write rate for 150 operations per second for each disk.

Level Usable capacity Failures survived Random writes per second
RAID 0 24 TB none 900
RAID 10 12 TB one for sure, more if in other pairs 450
RAID 5 20 TB one 225
RAID 6 16 TB any two 150

A file server that stores large files and is mostly read fits RAID 5 or 6. A database with many small random writes fits RAID 10. A scratch area that can be recreated fits RAID 0.

The key lines. On Linux, software RAID is built with the md driver and the mdadm tool. /proc/mdstat lists the arrays and the progress of a rebuild. Many servers use a hardware RAID controller with a battery-backed cache instead, which hides the small-write penalty for bursts.

Hot spare

A hot spare is a disk in an array that holds no data and waits to take over. When a disk fails, the array starts to rebuild onto the spare at once, which shortens the time in which a second failure would be fatal.

Example: a RAID 5 of five disks with one hot spare starts to rebuild as soon as one of the five fails.

Interview angle

A common question is "What is the difference between RAID 5 and RAID 10?" A good answer gives usable capacity (N - 1 against N / 2), failures survived, the small-write penalty of four operations against two, and says that RAID 5 suits read-heavy data and RAID 10 suits random-write loads.

Check yourself: 1. Which level has the lowest random write rate in the table, and why? 2. Which level gives the most usable space but no safety? 3. Why does a hot spare make an array safer?

Words you will meet

Word Meaning
Stripe One chunk from each disk, handled together.
Mirror A second copy of a block on another disk.
Parity XOR of the data blocks of a stripe.
Rebuild Recomputing a failed disk's data onto a new disk.
Hot spare An idle disk ready to take over.

Quick notes

  • RAID combines disks. Striping gives speed, mirroring and parity give survival.
  • RAID 0 survives no failure. RAID 1 and 10 mirror. RAID 5 survives one failure, RAID 6 two.
  • Parity is the XOR of the data blocks. Any one lost block is the XOR of the others.
  • Capacity: RAID 5 is (N - 1) disks, RAID 6 is (N - 2), mirrors are N / 2.
  • A small write on RAID 5 costs four disk operations. A full-stripe write costs none extra.
  • RAID is not a backup. A rebuild of a large disk takes hours.