使用 LVMCache 或 BCache 进行热-温-冷缓存

使用 LVMCache 或 BCache 进行热-温-冷缓存

我最近用三种不同的驱动器重新配置了我当前的 Debian 机器:SLC SSD、QLC SSD 和 4TB HDD。我一直在尝试lvmcache其他实用程序,我想知道是否可以创建一个多层缓存解决方案,利用两个 SSD 进行不同级别的缓存。

我的乌托邦结构是这样的:

  • SLC SSD(最快、可靠性高):用于经常写入和读取的文件的热缓存
  • QLC SSD(快速、可靠性良好):用于写入和读取频率较低的(可能较大)文件的热缓存
  • HDD(慢速、高可靠性):冷存储,用于不经常写入或读取的文件

lvmcache不幸的是,我还没有发现太多允许在或bcache(或者实际上是其他任何地方)中进行此类配置的多层缓存功能。

lvmcache是否可以bcache这样配置?如果没有,是否还有其他解决方案可以实现这种配置?

答案1

该解决方案同时使用dm-cache对于 SLC(热)和 QLC(温)SSD,以及bcache用于支持设备(HDD/冷)。

#!/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

相关内容