Striping
One disk has limits: one disk's speed, one disk's size, and when it breaks its data is gone. RAID (a redundant array of inexpensive disks) joins several disks so programs see one. Here the RAID layer joins four.
Striping (RAID 0) deals blocks out one by one. Block b goes to disk b mod 3 (remainder of b ÷ 3) and row b div 3 (whole-number division). Blocks 0-2 fill row 0; blocks 3-5 fill row 1. Disk 3 waits.
Reading blocks 0, 1 and 2 keeps three disks busy at once, so a big read runs up to three times as fast. But nothing is stored twice: if any one disk dies, part of the data is simply gone.
Parity
Disk 3 stores parity: the XOR of each row. XOR gives 1 where a column holds an odd number of 1s. Row 0: 0110 XOR 1100 XOR 0011 = 1001. Now any one lost block can be worked out.
Line 1 writes new bits 1001 to block 4, so row 1's parity must change too. First the RAID layer reads two old blocks: block 4 (0101) from disk 1 and parity P1 (1110) from disk 3.
New parity = old parity XOR old block XOR new block: 1110 XOR 0101 XOR 1001 = 0010. Then two writes: 1001 to block 4 and 0010 to P1. One small write cost four disk operations.
When a disk dies
Disk 1 dies, and blocks 1 and 4 die with it. With striping alone that would be the end. With parity the array keeps running in degraded mode: one disk down, but no data lost yet.
Line 2 reads block 1, which was on the dead disk. The RAID layer reads the rest of row 0 and XORs it: 0110 XOR 0011 XOR 1001 = 1100. That is block 1, rebuilt on the fly.
A new disk replaces disk 1. The RAID layer rebuilds it row by row, each lost block the XOR of the rest of its row: block 1 = 1100, block 4 = 1001. Until it finishes, a second failure would lose data.
Rotating parity
Every small write also updates parity, and in RAID 4 all parity lives on disk 3. Writes to block 0 and block 5 use different data disks, but both need disk 3, so they must wait in line.
RAID 5 moves the parity along, row by row. Row 1's parity goes to disk 2 and its blocks shift: 3 to disk 3, 4 to disk 0, 5 to disk 1. Writes to blocks 0 and 5 now share no disk.
Each level trades disks for safety and speed. With N disks, RAID 0 keeps all N for data and survives no failure. RAID 1 mirrors, keeping N/2. RAID 4 and RAID 5 keep N - 1 and survive one; RAID 5 spreads the writes.
What happens
;; step 1/12 · one-disk
RAID redundant array of inexpensive disks
(Patterson, Gibson and Katz, Berkeley, 1988)
outside looks like one disk: a row of numbered blocks
inside several disks + a layer that maps each block
Linux the md driver (Linux software RAID) joins
disks into one device, /dev/md0
here 4 disks, 2 rows each, blocks of 4096 bytes
Real blocks hold 4096 bytes and parity is worked out on every one of their 32768 bits. The figure shows 4 bits of each block, as OSTEP does in its own example; the C program writes those bits as the first byte, 9 (binary 1001). The RAID layer can be software in the kernel (the Linux md driver behind /dev/md0) or a hardware RAID card with its own processor and memory. Either way the program just reads and writes numbered blocks.