Conquering the RAID levels
When it comes to building PCs, for enthusiasts, it's all about performance. Everyone loves to brag about CPU speed or GPU power. We get it, because we do, too. All too often though, storage gets left behind in the conversation. Many may be led to think "Hey, I've got an SSD and HDD. What more could I want?"
As it turns out, you may not know what you're missing.
A redundant array of independent (or inexpensive) disks—RAID for short—is one way to skirt around the limitations of SATA throughput. What RAID does is pretty much the opposite of partitioning. RAID combines many physical (or logical) storage devices into a single logical storage device. Partitioning, on the other hand, splits a physical or logical device into many logical devices that can be formatted, encrypted, or backed up separately.
When we build systems here at Maximum PC, we find that two is very often better than one. We see this all the time with video cards. Two GTX 980s offer better performance than a single Titan X, for instance. But unlike video cards, the performance gains of RAID can stack much more drastically, depending on the level.
Hold on, what are RAID levels?
When we talk about RAID, a level is referring to the type of array. There are many RAID levels out there. Some are more common, like RAID 0 and RAID 1, while levels like RAID 60 are considered more exotic. Most motherboards only support the more common levels, but don't get upset quite yet. For most use cases outside of a server room, the common levels are plenty good enough.
Also, don't think that the higher the RAID level, the faster or "better" the array. Actually, it's quite the opposite: RAID 0 is considered the most lightning-fast (and most risky) RAID level out there.
Before we continue about RAID levels, we have to understand the concept of parity. Simply put, parity is when a copy of a block of data exists somewhere else on the array. When a device fails for some reason, the data can be recovered from the parity block.
It's important to know that data parity is not the same as a backup. The parity block in RAID is written at the same time the primary data block is. That means when you save an image file, parts of that image file are saved in the parity blocks that make up the file. At the same time, when you delete the file, it is also deleted from the parity block. If a virus corrupts the data in the file, you can bet that the data in the parity blocks contain corrupted or infected data as well. In this sense, it is best to think of RAID parity data as a hedge against physical failure of a device, not a backup solution. Heed this warning, young Padawan.
RAID 0: The speed demon
Ah, RAID 0. How we all love thee. RAID 0 is the Evil Knievel of RAID levels. It takes chances, and gets lots of performance in trade.
To understand why, we have to revisit the idea of parity. RAID 0 doesn't use parity. Instead, it takes chunks of data (called chunks or stripes) and "stripes" them across all of the devices in the array. Say there's a file that's 64KB in size, and the RAID is set up across two drives using 16KB stripes. When writing a file, the first 16K and third 16KB would be written to the first drive in sequence, while the second and fourth 16KB blocks would go to the second drive. This doesn't sound all that impressive on its face.
MORE: How to set up RAID in Windows and Linux
What's impressive about RAID 0 is that these two streams are written at the same time, which theoretically halves the time of writing the data to a single drive. The same holds true for reading data. In practice, there is some overhead to using RAID (and this varies based on implementation), so don't expect data rates to be exactly double.
There's a downside to all of this speed: When something fails, it fails hard.
RAID 0 drive failure: Yeah, it's kind of like that.
Like we said, RAID 0 doesn't have any data parity. That means when one drive fails, there is no backup of the data anywhere. Since the data for each file is striped across two or more drives, a single drive failure means that a significant portion of each file is gone. That results in a failure for the whole array.
Taken to its obvious conclusion, this means that RAID 0 multiplies the chances of failure across all of the drives in the array. One bad drive can ruin the whole thing. That's why builders should never use old drives in a RAID 0 array; it's the equivalent to strapping a brand-new rocket motor to a rusty mountain bike from 1997. Bad things will happen, it's just a matter of when.
If you really crave the speed, go with new, identical drives and make regular backups.
RAID 1: The savior
If RAID 0 is all speed and glory, then RAID 1 is the cautious type. When you have an array in RAID 1, you're choosing data safety. It drives in the slow lane while wearing a reflective vest and water wings.
MORE: How to set up RAID 1 in Windows and Linux
The way RAID 1 works is pretty darned straightforward: When you write a file to RAID 1, every device in the array gets a copy. That means that an array in RAID 1 is incredibly robust when it comes to drive failure protection. As long as there's one or more dives still working, all you have to do is swap out the dead drive and keep on rockin'.
When one drive fails, the others keep on going in RAID 1.
Just as RAID 0, however, there's a penalty—but with RAID 1, the penalty is speed. No matter how many drives you have in RAID 1, the performance will resemble that of a single drive. There are some exceptions, but usually any performance increases that could be realized in RAID 1 are only available in big UNIX servers with specialized hardware. Since we're working with PC hardware, just make the assumption that RAID 1 reads and writes will be only as fast as the drives and interfaces used.
RAID 5: The great compromise
RAID 5 is special in that it fits somewhere between RAID 0 and 1. It offers parity and striping for a mix of protection and speed. This RAID level provides what is called "distributed parity." To perform this act of trickery, RAID 5 needs a minimum of three drives to work.
MORE: How to set up RAID 5 in Windows and Linux
When a file is written to an array in RAID 5, the first two pieces of data are striped across two drives, just like in RAID 0. The third drive gets a full parity block, as if the two pieces were written on RAID 1. The next two pieces are written to the first and third drives, while the parity block is written to the second drive, and so on.
Here's how the data is arranged using this method:
Drive 1 | Drive 2 | Drive 3 |
A | B | A (parity) |
C | C (parity) | B (parity) |
E (parity) | D (parity) | D |
F (parity) | E | F |
As you can see, if any one drive fails, the entirety of the data (A-F) can be recovered somewhere else in the array. This makes RAID 5 pretty robust in most circumstances, but the array can only sustain one failure. If a drive fails, it needs to be replaced immediately, and the data on that drive needs to be rebuilt. The calculations for rebuilding a RAID 5 array is expensive (in terms of compute time, not dollars) and takes some time, but the array will still be usable while it is being rebuilt.
A "healthy" RAID 5 array has all of its data intact, and can provide read performance of a RAID 0 setup of one less drive (n-1). When an array is missing data or had a failed drive, it is considered "degraded." A degraded array is slower, and can be considered as risky as RAID 0.
With RAID 5, a degraded array can still work, but it can't afford a second blow.
A degrade array is a liability for servers, and failed drives in RAID 5 should be replaced immediately. It is for this reason that the Linux RAID software, mdadm, has the email software Postfix as a dependency. The software can be set up to automatically send emails when there is a failure that requires attention.
Write speeds in RAID 5 are about as fast as RAID 1 or a single drive, since the parity information has to go down a single SATA pipe.
It is also important to note that RAID 5 should not be used with SSDs. (We used SSDs for the sake of testing only.) RAID 5 is bad for SSDs because it keeps TRIM (the set of commands that keeps the SSD cells healthy and cleared) from working properly. This means that with continued normal use full of writes and deletes, the SSD memory cells will slowly grow corrupted. Use with caution.
RAID 10: The best of both worlds
When we get into the double digits with RAID, the levels cease to be unique flavors of their own. Instead, they become a mixture of levels that deliver the best both have to offer. RAID 10 is the simplest of these mixes.
RAID 10 (or RAID 1+0) requires a minimum of four drives to work. In a four-drive RAID 10, the first two drives are combined in RAID 1. The other two drives are combined in their own RAID 1 pair. The two pairs, treated like logical drives, are then striped in RAID 0.
MORE: How to set up RAID 10 in Windows and Linux
The advantage to RAID 10 is that you get the speed of RAID 0, but the array acts as if there is only half the number of drives present. This coupled with the minimum requirement of four drives makes RAID 10 the most financially taxing of the common RAID levels.
You'll need to save up if you want to have a RAID 10 setup with high-capacity SSDs.
On the upside, RAID 10 offers the robust data protection of RAID 1 paired with RAID 0's speed. Many consider RAID 10 to be the best option for this reason. On the downside, many motherboards only support RAID up to four SATA ports. (RAID that is implemented in the OS can overcome this limitation.)
There is a flipped version of RAID 10 called RAID 0+1. RAID 0+1 is just like RAID 1, but reversed. RAID 0 arrays are combined in RAID 1. Each "drive" in the RAID 1 layer is made up of an array in RAID 0, so the speed is about the same as RAID 10. Both RAID 10 and RAID 0+1 offer the same performance and protection, so RAID 0+1 is less common in order to keep things simple.
The Exotics
Other more "exotic" RAID levels include other variations on RAID 10, like RAID 50 or 60. These types of arrays are even more costly to set up. (RAID 50 requires at least six drives.) The computations are also more expensive for the CPU, so many of these levels render better performance with dedicated RAID hardware.
The other single-digit RAID levels are variations of RAID 5, but handle the parity in different ways. RAID 6 offers "double parity," so an array can sustain more than one drive failure. RAID 4 stripes data like RAID 5 but keeps all of the parity blocks on a single drive with a method called "dedicated parity."
In the next article in this series, we'll take a look at how the different RAID levels perform compared to a single drive.