MDADM caching

At the request of a friend I’m doing a piece on mdadm (software raid) with caching.

Long story short, Raid 4 / 5 / 6 allows using a disk for caching purposes (the disk can be a software raid)

To create the array one would run the mdadm command like so:

mdadm --create /dev/md0 --level=5 --raid-disks=4 --write-journal=/dev/sde /dev/sda /dev/sdb /dev/sdc /dev/sdd

where /dev/sde is the fast SSD (which can also be another md device) and the other 4 drives would be the spinning drives.

Quoting from https://www.kernel.org/doc/html/latest/driver-api/md/raid5-cache.html:

Raid 4/5/6 could include an extra disk for data cache besides normal RAID disks. The role of RAID disks isn’t changed with the cache disk. The cache disk caches data to the RAID disks. The cache can be in write-through (supported since 4.4) or write-back mode (supported since 4.10). mdadm (supported since 3.4) has a new option ‘–write-journal’ to create array with cache. Please refer to mdadm manual for details. By default (RAID array starts), the cache is in write-through mode. A user can switch it to write-back mode by:

echo "write-back" > /sys/block/md0/md/journal_mode

And switch it back to write-through mode by:

echo "write-through" > /sys/block/md0/md/journal_mode

In both modes, all writes to the array will hit cache disk first. This means the cache disk must be fast and sustainable.

PS I noticed the functionality not long ago while testing a clustered zfs setup sitting on top of software raid arrays combined with a bit of drbd (don’t ask) and felt like one of those really cool features that should have been created many many years ago when SSDs came out.

Enjoy! 🙂


Posted

in

,

by