The main advantage of dm-cache over [LVM](https://sourceware.org/lvm2/) and [Bcache](https://bcache.evilpiepirate.org/) is that it is possible to setup on devices that already have a filesystem with data on them. Both LVM and Bcache requires unformatted, empty devices, to setup (there are ways to get around, but can be risky).
dm-cache utilises the `dmsetup` utility which usually can be found in [lvm2](https://packages.debian.org/bookworm/lvm2) or [device-mapper](https://pkgs.alpinelinux.org/packages?name=device-mapper&branch=edge&repo=&arch=&maintainer=) packages.
dm-cache requires three devices
-**origin**: The slow device.
-**cache**: A fast SSD or NVME device. Can be of any size.
-**meta**: A small device that holds dm-cache metadata.
The metadata device size depends on how many cache blocks fit on the cache device. With **default** setting it should be a least 0.01% of the cache device size. If the cache device is 50GiB, and a cache block size of 128KiB, a metadata device of 5MiB is enough. Smaller block sizes requires more metadata and memory, while larger block sizes may reduce effectiveness of the cache by storing cold data. Check metadata usage with `cachestats.sh` to ensure you are within limits.
It is important to mount the filesystem on the dm-cache using the
`/dev/mapper/dmname` path and not with the filesystem UUID as is commonly done. This is because the kernel might still see the
UUID from the origin device, and this can cause data loss!
If you\'re using Btrfs, the following message can be seen in the kernel log:
```text
# dmesg
BTRFS warning: duplicate device /dev/sdj1 devid 1 generation 182261 scanned by mount (13706)
```
There is a udev rule that prevents this issue by removing the `/dev/disk/by-uuid/` symlink to the origin device.
## Documentation
Full documentation is available at https://wiki.tnonline.net/w/Linux/dm-cache
## Cache Statistics
`cachestats.sh` is used to see current stats of the dm-cache device.