Sub topic 8
RAID building blocks: striping, mirroring, and parity
RAID stands for Redundant Array of Independent Disks. It makes several physical drives behave like one logical drive, and the operating system sees a single volume. Every RAID level is built from three techniques: striping, mirroring, and parity. If you understand these three, you can work out the behavior of any level without memorizing a table.
This chapter assumes you already know:
- What a drive is and how it connects to a PC.
- The difference between storage and RAM.
- Units such as GB and TB.
The individual levels (0, 1, 5, 6, 10) get their own chapters. Here we cover only the building blocks.
Why combine drives at all
A single drive has two limits. It can only read and write so fast, and when it dies, its data is gone. Combining drives can address either limit:
- Performance: several drives working at once move more data per second.
- Availability: extra copies or recovery information let the system keep running after a drive fails.
- Capacity: several small drives can present one large volume.
No technique delivers all three at full strength. Each one trades one benefit against another, and that trade-off is the main thing to learn.
Striping: splitting data across drives
Striping divides data into fixed-size pieces called chunks (also called stripe units or blocks). The controller writes the chunks to the drives in rotation. One pass across all drives is a stripe.
The following code shows the idea. Eight bytes are written to two drives, two bytes per chunk.
def stripe(data, drives, chunk):
"""Distribute data across drives in round-robin chunks."""
disks = [bytearray() for _ in range(drives)]
for i in range(0, len(data), chunk):
disks[(i // chunk) % drives] += data[i:i + chunk]
return [bytes(d) for d in disks]
print(stripe(b"ABCDEFGH", 2, 2)) # [b'ABEF', b'CDGH']Chunks AB and EF land on drive 0. Chunks CD and GH land on drive 1. Reading the whole file now pulls from both drives at the same time.
Striping has these properties:
- Speed: large reads and writes can use all drives in parallel, so throughput rises with the drive count.
- Capacity: nothing is duplicated, so all of the raw space is usable.
- Risk: every file is spread over every drive. Losing any one drive leaves holes in nearly every file, so the whole array is lost.
Striping by itself provides no redundancy. The failure risk also grows with each drive you add, because there are more drives that can fail.
Mirroring: keeping identical copies
Mirroring writes the same data to two or more drives. Each drive holds a complete copy.
- Fault tolerance: if one drive fails, the other still has everything, and the volume stays online.
- Read speed: reads can be served from either drive, so a controller can sometimes improve read performance.
- Write speed: every write must reach every copy, so writes are no faster than a single drive.
- Cost: with two drives you get the usable space of one. That is 50% efficiency, the most expensive way to buy redundancy.
Mirroring is also the simplest to recover. You do not compute anything. The controller copies the surviving drive onto the replacement.
Parity: recovery information instead of full copies
Parity is calculated data that lets the array rebuild a missing piece. It costs less space than mirroring. The calculation is the XOR (exclusive OR) operation. For each bit position, XOR returns 1 when an odd number of inputs are 1 and returns 0 otherwise.
Take a stripe of three data blocks. The parity block is the XOR of all three:
# 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) # TrueThis works because XOR undoes itself. XOR-ing any value with the same value twice returns the original. So the parity block together with the surviving data blocks always reproduces the missing block.
Parity has these properties:
- One drive's worth of overhead: one drive of space holds parity, however many data drives you have. Efficiency improves as drives are added.
- Survives one failure: single parity can rebuild exactly one missing block per stripe. A second loss in the same stripe cannot be recovered. A level that keeps two independent parity blocks, covered later, survives two failures.
- Write penalty: changing a data block also means updating parity. The controller must read old data and old parity, then write both again. Small writes are therefore slower on parity arrays.
- Slow rebuilds: to recreate a lost block, the controller reads every surviving drive. Rebuilding a large array takes hours. The array runs degraded, and a second failure during that time can lose everything.
Many parity levels spread the parity blocks across all drives instead of dedicating one drive to it. This is distributed parity. It avoids making a single drive a write bottleneck.
How the techniques compare
| Technique | Redundancy | Space efficiency | Main benefit | Main cost |
|---|---|---|---|---|
| Striping | None | 100% | Speed | One failure loses everything |
| Mirroring | Full copy | 50% with two drives | Simple, fast recovery | Half the space is duplicate |
| Parity | Rebuild data | (n − 1) / n | Redundancy with less waste | Write penalty, slow rebuild |
Seeing the three side by side
Combining the techniques
Real RAID levels combine these building blocks:
- Striping alone gives speed.
- Mirroring alone gives redundancy.
- Striping with parity gives balanced redundancy.
- Striping over mirrors gives speed and redundancy at the cost of space.
When an exam question describes a level, ask three things. Is data split? Is it copied? Is recovery information calculated? The answers identify the level.
Common mistakes
- Treating "redundant" as "safe". Redundancy protects against drive failure only. It does not protect against deletion, corruption, malware, fire, or theft. A later chapter covers this in detail.
- Mixing drive sizes. Most arrays treat every member as the size of the smallest drive. A 4 TB drive paired with a 2 TB drive wastes 2 TB.
- Forgetting the degraded state. An array with a failed member still works, but it has lost its safety margin and is often slower. Replace the drive promptly.
- Assuming parity is free. Parity saves space but costs write speed and rebuild time.
Exercise
A technician stripes data across three drives, using the XOR parity from this chapter. The data blocks in one stripe are 0b1001 and 0b0101, and the third drive stores their parity. The drive holding 0b0101 fails. What value is rebuilt, and which operation produces it?
Show answer
The parity block is 0b1001 XOR 0b0101 = 0b1100. To rebuild the lost block, XOR the surviving data block with the parity block: 0b1001 XOR 0b1100 = 0b0101. The operation is XOR. Because XOR undoes itself, combining the survivors with the parity always reproduces the missing block.
Exercise
Match each technique to its trade-off: (1) striping, (2) mirroring, (3) parity. Trade-offs: (a) half the raw space holds duplicate data, (b) writes are slower because parity must be updated, (c) all the capacity is usable but one drive failure loses everything.
Show answer
Striping matches (c). Mirroring matches (a). Parity matches (b).