8

I've recently reconfigured my current debian machine with three different drives: An SLC SSD, a QLC SSD, and a 4TB HDD. I've been toying around with lvmcache and other utilities, and I wanted to know if it was possible to create a multi-tier caching solution that leverages both of the SSDs for caching at different levels.

My utopian structure is this:

  • SLC SSD (fastest, good-reliability): Hot Cache for files that are written to and read often
  • QLC SSD (fast, OK-reliability): Warm Cache for (potentially larger) files that are written to and read from less often
  • HDD (slow, high-reliability): Cold Storage for files that aren't written to or read often

Unfortunately, I haven't found much in terms of capabilities for multi-tier caching that allows for this type of configuration in either lvmcache or bcache (or, really, anywhere else).

Is it possible for lvmcache or bcache to be configured in such a way? And, if not, are there any other solutions out there that may enable such a configuration?

Swivel
  • 236
  • 2
  • 9

1 Answers1

1

This solution uses both dm-cache for the SLC (Hot) and QLC (Warm) SSDs, and bcache for the backing device (HDD/Cold).

#!/bin/bash

# Step 1: Set up dm-cache
# Create the cache device with the SLC SSD as the fastest tier
sudo dmsetup create slc_cache --table "0 $(blockdev --getsz /dev/slc_ssd) cache /dev/slc_ssd /dev/slc_ssd_metadata"

# Create the cache device with the QLC SSD as the slower tier
sudo dmsetup create qlc_cache --table "0 $(blockdev --getsz /dev/qlc_ssd) cache /dev/qlc_ssd /dev/qlc_ssd_metadata"

# Step 2: Create bcache device
# Create the backing device using the HDD
sudo make-bcache -B /dev/hdd

# Format the bcache device
sudo mkfs.ext4 /dev/bcache0

# Step 3: Configure bcache
# Attach the dm-cache devices to the bcache device
sudo echo "slc_cache" > /sys/block/bcache0/bcache/add_cache
sudo echo "qlc_cache" > /sys/block/bcache0/bcache/add_cache

# Register the bcache device as a caching device
sudo echo "writeback" > /sys/block/bcache0/bcache/cache_mode

# Register the bcache device as the backing device for the cache devices
sudo echo "/dev/bcache0" > /sys/block/slc_cache/bcache/backing_dev
sudo echo "/dev/bcache0" > /sys/block/qlc_cache/bcache/backing_dev

# Mount the bcache device
sudo mkdir /mnt/cached_hdd
sudo mount /dev/bcache0 /mnt/cached_hdd

# Update /etc/fstab to mount the bcache device on boot
echo "/dev/bcache0 /mnt/cached_hdd ext4 defaults 0 0" | sudo tee -a /etc/fstab
Swivel
  • 236
  • 2
  • 9