From ICO wiki

LVM2 Cache Feature

One of the LVM2 great features is the Cache option. The main idea of this feature is to store frequently used blocks of the large and slow LV (called as origin LV) on the small and fast LV (called as cache pool LV). Large and slow is a well known old friend HDD, small and fast is our new friend SSD. LVM2 caching feature is built on top of dm-cache[1]. As a result of this, cache pool LV consists of two parts: the cache data LV and cache metadata LV. The cache data LV stores blocks from the origin LV to increase access speed. The cache metadata LV holds the summary information specifying where are the data blocks stored (e.g. on the origin LV or on the cache data LV). All of these associated LVs must be in the same VG[2][3].

Short Topology

origin LV OriginLV large slow LV
cache data LV CacheDataLV small fast LV for cache pool data
cache metadata LV CacheMetaLV small fast LV for cache pool metadata
cache pool LV CachePoolLV CacheDataLV + CacheMetaLV
cache LV CacheLV OriginLV + CachePoolLV


1. utilities (lvm2)
2a. regular root permissions to install and run package
2b. specific user permissions to install software if missing as well as specefic permissions to run utilities
(superuser can allow user to run specific commands)[4]

Setting UP

1. create OriginLV.

lvcreate -n OriginLV -L LargeSize VG /dev/slow


lvcreate -n originlogvol -L 100G cacheVG /dev/hda

2. create CacheDataLV.
This LV will store the data blocks from OriginLV and this volume size will be reported as the cache pool size.

lvcreate -n CacheDataLV -L CacheSize VG /dev/fast


lvcreate -n cachedata -L 10G cacheVG /dev/sda1

3. create CacheMetaLV. This will create cache metadata LV. This volume will hold the cache metadata.
This volume size must be 1000 times smaller than the cache data LV, with a minimum size of 8MiB.

lvcreate -n CacheMetaLV -L MetaSize VG /dev/fast


lvcreate -n cachemeta -L 12M cacheVG /dev/sda2

4. create CachePoolLV.
Merge the data and metadata LVs into a cache pool LV.
During this step we configure LVM to use volumes that we prepared before to work as a cache pool LV.

CachePoolLV takes the name of CacheDataLV.
CacheDataLV is renamed CachePoolLV_cdata and becomes hidden.
CacheMetaLV is renamed CachePoolLV_cmeta and becomes hidden.

lvconvert --type cache-pool --poolmetadata VG/CacheMetaLV VG/CacheDataLV


lvconvert --type cache-pool --poolmetadata cacheVG/cachemeta cacheVG/cachedata

5.create CacheLV.
Finally, you have to create a cache LV.
This is done by linking the cache pool LV to the origin LV.

CacheLV takes the name of OriginLV.
OriginLV is renamed OriginLV_corig and becomes hidden.

lvconvert --type cache --cachepool VG/CachePoolLV VG/OriginLV


lvconvert --type cache --cachepool cacheVG/cachedata cacheVG/originlogvol

6. Enjoy!


1. Safely split volumes and write back data from the cache data pool onto the main origin volume.

lvconvert --splitcache VG/CacheLV

2. Safely write data back to the origin volume and remove the cache pool.

lvremove VG/CachePoolLV


New LVM2 feature is a great opportunity to improve disk system performance. All you need is a fast SSD drive. Of course, you have to take into concideration the risks of using a single SSD drive to cache the Origin volume. It is much more safe to use a RAID1 mirror for the cache LV as well as a mirror for the Origin LV to avoid a possibility of physical failure. Good news, that small SSDs aren't that expensive and it is really possible to create safe and productive business solution to cache the most used data of big and slow hard disk drives using fast solid state drives.

Artice references