With the latest release, LVM can now use fast block devices (e.g. SSDs and PCIe Flash) to improve the performance of larger but slower block devices. These hierarchical or layered logical volumes are called "Cache Logical Volumes" in LVM.
Implementation
What do we need:
- A box/vm running Linux Kernel > 3.9
- The latest version of LVM
- /usr/sbin/cache_check (apt-get thin-provisioning-tools / yum install device-mapper-persistent-data)
- Some storage drive
- Some fast(er)-storage drive
In this example I am using a Debian VM (8/Jessie) running on my private vSphere 6 platform. I have created a thin 12TB volume (rd0 on sata-store) and an eager zero'd 16GB volume (rd1 on ssd-store). It will run on pretty much any IO-device (even ramdisks when running headless)
First off, we'll check the names and availability of the devices
pvscan
Then (if needed) we'll create a volume group and a logical volume:
pvcreate /dev/rd0
vgcreate datastore0 /dev/rd0
lvcreate -n volume0 -L 12TB datastore0 /dev/rd0
Next we'll extend the volume group to contain the "SSD/PCI-E device":
vgextend datastore /dev/rd1
Then we'll create a logical cache and metadata volume:
lvcreate -n metadata -L 1GB datastore0 /dev/rd1
lvcreate -n cache -L 14GB datastore0 /dev/rd1
It is important to note to keep the same size as datastore0/metadata free (1GB in this example) for failure/recovery purposes. (cache vs metadata: 1000:1 with a min of 8mb)
Now we'll convert these into a cache pool
lvconvert --type cache-pool --poolmetadata datastore0/metadata datastore0/cache
This will throw a destroy warning! Doublecheck your syntax when using live data! Answer yes.
Attach the cache to a logical volume:
lvconvert --type cache --cachepool datastore0/cache datastore0/volume0
It should say "datastore0/volume0 is now cached". Let's check that!
lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
cache datastore0 Cwi---C--- 14.00g
volume0 datastore0 Cwi-a-C--- 12.0t cache [datastore0_corig]
That was all! Now don't forget to add/make a filesystem to the drive if you aren't using live data.