RAID 5 Parity. What is it, and how does it work?

One morning, I started wondering how RAID 5 parity works to rebuild a disk array. It seemed “magical” to me, that you can get redundancy and still use most of your disk capacity. So I searched for it… and turned up not very much info, and one other person’s unanswered question. A few articles explained it, but in a little more detail about performance, and less detail about the actual parity function. This article attempts to fill the gap.


The good articles were at:

Sunworld
MS TechNet
Tom’s Hardware

What’s the magic?

The short answer is “XOR”. XOR is a binary operator that takes two inputs and produces one output. The rules are:

1 xor 1 = 0
1 xor 0 = 1
0 xor 1 = 1
0 xor 0 = 0

In English xor means “if there’s a difference, the result is 1”.

Parity in RAID 5 involves reserving some space for parity information. Parity data is an additional digit of information that helps you recover lost data.

Another way to describe this parity is “even parity”. That means we try to keep the number of “1” bits even. If there are 2 “1”s, the parity is “0”. If there is only 1 “1”, the parity is “1”. In short:

1 1 parity 0
1 0 parity 1
0 1 parity 1
0 0 parity 0

(I had a little difficulty “getting it” because I was used to parity calculations on a network. If you’re familiar with that, don’t apply that knowledge too much. RAID parity is just a little bit different.)

How parity data is arranged on the disk

In practial terms, the data on the disk is stored in cylinders. A cylinder is all the data that passes under the disk head in one revolution. Cylinders are grouped into stripes, which are the same-numbered cylinder across all the drives. So, stripe 1 is the group of all the cylinder 1s across all the disks. (Note that this is the idealized RAID. Actual RAID is less tidy, but the stripe is the basic set of data that is protected.)

RAID calculates parity across cylinders, within a stripe. So if you have a three-disk RAID 5 array, and your data is on stripe 0, two of the cylinders hold data, and the third cylinder holds the parity.

Parity is calculated across the cylinders. (It’s not calculated within a single byte, the way it is on networks.) So if cylinder 1 on disk 1 looks like this:

10010011101110110001101...

And cylinder 1 on disk 2 looks like this:

10000001000000010000000...

Then the parity looks like this:

00010010101110100001101...

Here are the three cylinders again, but closer together so it makes sense:

10010011101110110001101...
10000001000000010000000...
00010010101110100001101...

Notice how there are an even number of 1s in each column of bits. The parity is even.

That is how RAID can recover from a lost hard disk. If you replace a disk, you can rebuild it because you know that there should always be an even number of bits in each column.

If you lost the second disk, your data suddenly looks like this:

10010011101110110001101...
_______________________...
00010010101110100001101...

You can rebuild the second disk by setting the 1 and 0 bits based on our parity rule, that there should be an even number of 1s. Here’s an example of regenerating the first four bits:

10010011101110110001101...
1000___________________...
00010010101110100001101...

All we do is repeat this calculation several billion times, and our data is rebuilt.

(A nice feature about RAID 5 is that, as you add more disks, you still retain only one parity cylinder per stripe, so, the fraction of space used for parity decreases. A 4-disk RAID array allows you to use 3/4 of the array for data, and 1/4 for parity.)

The main downside of RAID 5 is performance, and that issue is described in the linked articles, above.

Increased Risk of Failure with More Disks

One other fact about RAID 5 is, as more disks are added, you’re more likely to experience a failure.

That just makes sense: more disks means more exposure to failure. RLR UK discusses this in more detail.

RAID 1 is more reliable, but it is less economical.

If you need lots of storage, RAID 5 is still good, but you need to run the disk scanning software all the time. You need to give the disks a chance to find their bad blocks, remap them, and fail quickly if there is a problem. Also, keep a separate backup: RAID is not a backup solution.

Is RAID Dead?

No. There was an article that claimed it was, but they got the math wrong, and the followup in 2013 said that RAID was less reliable than a single disk. That’s wrong, as well.

RAID 5 is inherently safer than a single disk, because you have redundancy, with less exposure to failure, as long as the disks are allowed to scan the surface and detect failures.

RAID 5 is less reliable than RAID 1. More disks = more exposure to failure. However, RAID 5 is more economical.

If you don’t perform the scan regularly, then, yes, a section of the disk that contains data may go bad, and sit, waiting, like a land mine. When you perform a recovery, you’ll get an unrecoverable read error.

(If you don’t use RAID, and just have solo disks, you should also perform a disk check from time to time, for the same reasons. Reading the disk gives the controller a chance to detect bad blocks, and relocate them. You will eventually get a bad sector, at which point, you should replace the disk.)

Leave a Reply