Lvm2

From ICO wiki
Revision as of 14:49, 5 January 2016 by Atopihha (talk | contribs)
Jump to navigationJump to search

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


Requirments

1. utilities (lvm2) 2. permissions to install if missing 3. permissions to run


Setting UP

1. create OriginLV.

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

Example

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

Example

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

Example

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

Example

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

Example

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

6. Enjoy!

Removing

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


Summary

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