This option is used to mark a participating volume as a "slow-performing" volume so that most of the reads from an array will come from other, faster, volumes. This option is most useful when creating a RAID-1 mirrored array where the participating volumes might be connected over a variety of media (i.e., network/USB) in combination with faster connections (SAS/SATA/fiber). However, this option does allow for some interesting and creative RAID solutions, especially when mixing storage media of different sizes/speeds.
Example 1: Slow/Fast Disks
Lenny T. is building a computer that has lots and lots of video game ROMs and disk images. He also has lots of movies, music, and other files that take up lots of space. These would be time-consuming to re-download in the case of a drive failure. He has an off-site backup solution in place, but he really doesn't have time time/resources to recover from backup for something as simple as a failed hard drive. Meteor strike would be a different story, but he would prefer to keep his computer with maximum up-time. Lenny's computer has a single 2TB SATA hard drive, and he has an external 2TB hard drive connected via USB. Lenny wants to configure the 2 drives in a RAID-1 mirror so that if either of the 2 drives fails, his computer will remain functional until the failed hardware can be replaced. (Lenny is aware that RAID'ing a USB device is a bad idea, but he's got what he's got, and his fancy RTX 2080ti wasn't cheap, so another drive isn't in the budget right now.)
Lenny can use the following command to configure the USB drive as a "write-mostly" drive so that when the computer boots and he does his computery stuff, most of the reads come from his internal drive:
$ sudo mdadm --create --verbose --assume-clean /dev/md0 --level=1 --raid-devices=2 /dev/sda --write-mostly /dev/sdb
In this example, /dev/md0 will be the new RAID-1 volume, /dev/sda is Lenny's internal SATA drive, and /dev/sdb is his USB-connected external drive. Because of the --write-mostly option preceding his "slow" devices, his computer will perform all write operations on both drives, but most of his read operations will come from /dev/sda.
Example 2: Asymmetric Disk Sizes
Lenny is building a computer. He has 4x 2TB SATA hard drives and 1x 8TB hard drive. Lenny wants to create a striped RAID-0 with his 2TB drives, and then he wants to mirror that whole array to a single 8TB hard drive. He wants to do this because he really, really needs 8TB of space, he wants the performance benefit of RAID-0, he wants the redundancy of RAID-1, but he can't assemble a RAID-10/RAID-01 because he doesn't have enough 2 TB drives. (He also doesn't have 8 drive bays in his computer.)
Lenny can use the following command to build the RAID-0:
$ sudo mdadm --create --verbose /dev/md0 --level-0 --raid-devices=4 /dev/sda /dev/sdb /dev/sdc /dev/sdd
After this is successful, Lenny can use the following command to build the RAID-1:
$ sudo mdadm --create --verbose --assume-clean /dev/md1 --level-1 --raid-devices=2 /dev/md0 --write-mostly /dev/sde
Note that this is similar to the process of (manually) creating a RAID-10/RAID-01. In this example, /dev/md0 (the 8TB RAID-0 volume across 4 disks) is one of the participants of /dev/md1 (the RAID-1 mirrored volume). The other participant is the single 8TB disk, /dev/sde.
In the aforementioned examples, we have seen how the --write-mostly option can be used to manually configure a RAID array to "prefer" reads from one participant of the array over another participant. The hard work of this preference is done by the md driver. This isn't a fool-proof way of making this preference, and it's not even the best way to create/use RAID arrays. However, if you are in a pinch and need to save some time, this is a quick way to maximize the space/performance from the available storage options. Performance testing will show that, while the array WILL attempt to read from the faster device first, it will sometimes still attempt to read from the slower device. This will result in the following idiosyncracies:
- Write performance will be equal to the slowest participant in the RAID-1 array. In Example 1, every write operation will occur at the speed of the USB drive. In Example 2, every write operation will occur at the speed of the single 8TB disk. This can be mitigated with the
--write-behindoption (which caches writes to the array).
- Read performance will be somewhere between the fastest device and the slowest device. This is because md WILL occasionally still attempt to read from the slower device...and it will wait for the data to be delivered.
However, this arrangement CAN overcome some issues with more traditional RAID levels:
- You can overcome the cost/space disadvantages of a RAID-10/RAID-01 arrangement because you don't need to use as many disks.
- You can reduce the write performance disadvantage AND the high write-workload of RAID-5 and RAID-6 because there's no need for parity calculations for every write operation.