Speeding Up an HDD to SSD-Like Performance with LVM Cache (dm-cache / lvmcache)
Introduction
Using a high-capacity HDD on a desktop PC while getting SSD-like speeds — that’s exactly what dm-cache (lvmcache), built right into the Linux kernel, delivers. In this article, I’ll walk through an actual setup where the root partition on a 2TB HDD is cached and accelerated using an NVMe SSD.
Environment
| Item | Details |
|---|---|
| Machine | ASUSTeK TUF B450M-PLUS GAMING |
| OS | Ubuntu 24.04.4 LTS (Noble Numbat) |
| Kernel | Linux 6.8.0-101-generic (x86-64) |
| HDD | Seagate ST2000DM001 (2TB, SATA) |
| NVMe SSD | WD Blue SN550 500GB (WDS500G2B0C) |
Storage Layout
NVMe SSD (WD Blue SN550 / 465.8GB)
├─ nvme0n1p1 200MB EFI → /boot/efi
├─ nvme0n1p3 243GB BitLocker → Windows
└─ nvme0n1p6 221GB LVM → Cache pool (180GB data + 2GB meta)
HDD (Seagate ST2000DM001 / 2TB)
├─ sda1 928GB BitLocker → Windows
├─ sda2 488GB LVM → Root LV origin (320GB)
└─ sda3 447GB ext4 → /mnt/backup
LVM Layout:
VG: vg_main
├─ root_lv 320GB ext4 → / (cached)
├─ root_lv_corig 320GB → Origin data (on HDD sda2)
└─ cache_lv_cpool → Cache pool (on SSD nvme0n1p6)
├─ cpool_cdata 180GB → Cache data
└─ cpool_cmeta 2GB → Cache metadata
Key Points
- In a dual-boot setup with Windows, LVM cache is applied only to the Linux partition
- A 320GB root LV is placed on a 488GB HDD partition and cached with 180GB on the SSD
- The SSD cache covers about 56% of the HDD volume’s capacity, allowing a high hit rate
How LVM Cache (dm-cache) Works
Application
↓
root_lv (320GB / ext4 / Mount: /)
↓
dm-cache (Kernel layer)
├─ Cache HIT → Fast read from SSD (NVMe)
└─ Cache MISS → Read from HDD → Cached on SSD
dm-cache is a block-level caching mechanism included in the Linux kernel’s Device Mapper subsystem. LVM2 provides a frontend via the lvmcache / LVM commands, allowing you to transparently add caching to an LVM logical volume.
Cache Modes
| Mode | Behavior | Characteristics |
|---|---|---|
| writethrough | Writes go to both the HDD and SSD simultaneously | High safety. No data loss even if the SSD fails |
| writeback | Writes go only to the SSD first, and are flushed asynchronously to the HDD later | Writes are also fast, but there is a risk of data loss if the SSD fails |
This setup uses writethrough (the default), giving SSD-level read speeds while preserving write safety.
Cache Policy: smq
Uses smq (Stochastic Multiqueue), the default policy since Linux 4.2. It is an excellent algorithm that automatically selects what to cache based on access frequency while keeping memory overhead low.
Setup Steps
1. Prerequisites
- LVM2 is installed
- The SSD partition used for caching belongs to the same VG
sudo apt install lvm2
2. Create Physical Volumes (PV)
# HDD partition
sudo pvcreate /dev/sda2
# SSD partition
sudo pvcreate /dev/nvme0n1p6
3. Create the Volume Group (VG)
sudo vgcreate vg_main /dev/sda2 /dev/nvme0n1p6
4. Create the Root Logical Volume (LV)
# Create the origin LV on the HDD
sudo lvcreate -L 320G -n root_lv vg_main /dev/sda2
# Create the filesystem
sudo mkfs.ext4 /dev/vg_main/root_lv
5. Create and Attach the Cache Pool
# Create the cache pool LV on the SSD
sudo lvcreate --type cache-pool -L 180G -n cache_lv_cpool vg_main /dev/nvme0n1p6
# Attach the cache pool to the root LV
sudo lvconvert --type cache --cachepool vg_main/cache_lv_cpool vg_main/root_lv
With just this, accesses to root_lv are automatically routed through the SSD cache. No changes to existing mount points or filesystems are needed.
6. Verification
# Check cache status
sudo lvs -a -o +cache_mode,cache_policy vg_main
# Check Device Mapper status
sudo dmsetup status vg_main-root_lv
Current Usage
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_main-root_lv 315G 107G 194G 36% /
| Item | Value |
|---|---|
| Root LV size | 320GB (315GB usable) |
| Used space | 107GB (36%) |
| Cache data size | 180GB |
| Cache metadata size | 2GB |
| Cache mode | writethrough |
| Cache policy | smq |
Because there is 180GB of cache for 107GB of used space, virtually all frequently accessed data is cached on the SSD and can be accessed at high speed.
Comparison with Bcache
Bcache is another mechanism for “caching an HDD with an SSD” (see Storage Acceleration Setup Using Bcache on Raspberry Pi 5). Here is a comparison of the two.
| Comparison Item | lvmcache (dm-cache) | Bcache |
|---|---|---|
| Management | Unified management via LVM commands | Dedicated tool (bcache-tools) |
| Kernel integration | Part of Device Mapper | Standalone kernel module |
| Adding to an existing LV | Easy (a single lvconvert command) | Requires recreating the device |
| Combining with RAID | Integrates with LVM RAID | Built on top of mdadm RAID |
| Cache policy | smq (auto-optimized) | lru / fifo |
| Operational flexibility | Easy to attach and detach cache | Detaching procedure is somewhat complex |
If you are already using LVM, lvmcache is easy to manage, whereas Bcache has the advantage of being easy to introduce in non-LVM setups or environments like the Raspberry Pi.
Summary
| Component | Role |
|---|---|
| HDD (Seagate 2TB) | Persistent storage for large volumes of data |
| NVMe SSD (WD Blue 500GB) | Accelerates reads with a 180GB cache |
| lvmcache (dm-cache) | Transparently caches at the block level |
| writethrough mode | Accelerates reads while ensuring data safety |
The biggest advantage of LVM cache is its simplicity: you can add a cache to an existing LVM environment with a single lvconvert command, without modifying the filesystem. By caching a 2TB HDD with a 500GB NVMe SSD, you can achieve near-SSD speeds for everyday desktop use.
Created: March 2026