2014-05-18 22:09:47 +04:00
.TH "LVMCACHE" "7" "LVM TOOLS #VERSION#" "Red Hat, Inc" "\" "
.SH NAME
2014-06-11 13:06:30 +04:00
lvmcache \(em LVM caching
2014-05-18 22:09:47 +04:00
.SH DESCRIPTION
2014-07-23 00:10:35 +04:00
The \fB cache\fP logical volume type uses a small and fast LV to improve
2014-05-18 22:09:47 +04:00
the performance of a large and slow LV. It does this by storing the
frequently used blocks on the faster LV.
LVM refers to the small fast LV as a \fB cache pool LV\fP . The large
slow LV is called the \fB origin LV\fP . Due to requirements from dm-cache
(the kernel driver), LVM further splits the cache pool LV into two
devices - the \fB cache data LV\fP and \fB cache metadata LV\fP . The cache
data LV is where copies of data blocks are kept from the
origin LV to increase speed. The cache metadata LV holds the
accounting information that specifies where data blocks are stored (e.g.
on the origin LV or on the cache data LV). Users should be familiar with
these LVs if they wish to create the best and most robust cached
logical volumes.
2014-07-22 00:41:42 +04:00
.SH Cache Terms
2014-05-18 22:09:47 +04:00
.nf
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
.fi
2014-07-23 00:10:35 +04:00
.SH Cache Usage
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
The primary method for using a cache type logical volume:
2014-05-18 22:09:47 +04:00
2014-07-22 00:41:42 +04:00
2014-07-23 00:10:35 +04:00
.SS 0 . create OriginLV
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
Create an LV or identify an existing LV to be the origin LV.
.B lvcreate \- n OriginLV \- L LargeSize VG SlowPVs
.I Example
2014-07-22 00:41:42 +04:00
.br
2014-07-23 00:10:35 +04:00
# lvcreate \- n lvol0 \- L 100G vg
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
.SS 1 . create CacheDataLV
Create the cache data LV. This LV will hold data blocks from the
OriginLV. The size of this LV is the size of the cache and will be
reported as the size of the cache pool LV.
.B lvcreate \- n CacheDataLV \- L CacheSize VG FastPVs
.I Example
2014-07-22 00:41:42 +04:00
.br
2014-07-23 00:10:35 +04:00
# lvcreate \- n cache0 \- L 10G vg /dev/fast
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
.SS 2 . create CacheMetaLV
Create the cache metadata LV. This LV will hold cache pool metadata. The
size of this LV should be 1000 times smaller than the cache data LV, with
a minimum size of 8MiB.
.B lvcreate \- n CacheMetaLV \- L MetaSize VG FastPVs
.I Example
2014-07-22 00:41:42 +04:00
.br
2014-07-23 00:10:35 +04:00
# lvcreate \- n cache0meta \- L 12M vg /dev/fast
.nf
# lvs -a vg
LV VG Attr LSize Pool Origin
cache0 vg -wi-a----- 10.00g
cache0meta vg -wi-a----- 12.00m
lvol0 vg -wi-a----- 100.00g
.fi
.SS 3 . create CachePoolLV
Combine the data and metadata LVs into a cache pool LV.
The behavior of the cache pool LV can be set in this step.
2014-07-22 00:41:42 +04:00
.br
2014-05-18 22:09:47 +04:00
CachePoolLV takes the name of CacheDataLV.
2014-07-22 00:41:42 +04:00
.br
2014-05-18 22:09:47 +04:00
CacheDataLV is renamed CachePoolLV_cdata and becomes hidden.
2014-07-22 00:41:42 +04:00
.br
2014-05-18 22:09:47 +04:00
CacheMetaLV is renamed CachePoolLV_cmeta and becomes hidden.
2014-07-23 00:10:35 +04:00
.B lvconvert \- \- cachepool VG/CacheDataLV \- \- poolmetadata VG/CacheMetaLV
.I Example
2014-07-22 00:41:42 +04:00
.br
2014-07-23 00:10:35 +04:00
# lvconvert \- \- cachepool vg/cache0 \- \- poolmetadata vg/cache0meta
.nf
# lvs -a vg
LV VG Attr LSize Pool Origin
cache0 vg Cwi---C--- 10.00g
[cache0_cdata] vg Cwi------- 10.00g
[cache0_cmeta] vg ewi------- 12.00m
lvol0 vg -wi-a----- 100.00g
.fi
.SS 4 . create CacheLV
Create a cache LV by linking the cache pool LV to the origin LV.
The user accessible cache LV takes the name of the origin LV,
while the origin LV becomes a hidden LV with the name
OriginLV_corig. This can be done while the origin LV is in use.
2014-07-22 00:41:42 +04:00
.br
2014-05-18 22:09:47 +04:00
CacheLV takes the name of OriginLV.
2014-07-22 00:41:42 +04:00
.br
2014-05-18 22:09:47 +04:00
OriginLV is renamed OriginLV_corig and becomes hidden.
2014-07-23 00:10:35 +04:00
.B lvconvert \- \- type cache \- \- cachepool VG/CachePoolLV VG/OriginLV
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
.I Example
.br
# lvconvert \- \- type cache \- \- cachepool vg/cache0 vg/lvol0
.nf
# lvs -a vg
LV VG Attr LSize Pool Origin
cache0 vg Cwi---C--- 10.00g
[cache0_cdata] vg Cwi-ao---- 10.00g
[cache0_cmeta] vg ewi-ao---- 12.00m
lvol0 vg Cwi-a-C--- 100.00g cache0 [lvol0_corig]
[lvol0_corig] vg -wi-ao---- 100.00g
.fi
.SH Cache Removal
2014-07-22 00:41:42 +04:00
2014-07-23 00:10:35 +04:00
.SS Removing a cache pool LV without removing its linked origin LV
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
\&
This writes back data from the cache pool to the origin LV when necessary,
then removes the cache pool LV, leaving the un-cached origin LV.
.B lvremove VG/CachePoolLV
.I Example
2014-05-18 22:09:47 +04:00
.nf
2014-07-23 00:10:35 +04:00
# lvs vg
LV VG Attr LSize Pool Origin
cache0 vg Cwi---C--- 10.00g
lvol0 vg Cwi-a-C--- 100.00g cache0 [lvol0_corig]
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
# lvremove vg/cache0
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
# lvs vg
LV VG Attr LSize Pool Origin
lvol0 vg -wi-a----- 100.00g
.fi
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
.SS Removing an origin LV without removing its linked cache pool LV
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
\&
This removes the origin LV, leaving the cache pool LV which can be linked
to another origin LV.
.B lvremove VG/CacheLV
.I Example
.nf
# lvs vg
LV VG Attr LSize Pool Origin
cache0 vg Cwi---C--- 10.00g
lvol0 vg Cwi-a-C--- 100.00g cache0 [lvol0_corig]
# lvremove vg/lvol0
# lvs vg
LV VG Attr LSize Pool Origin
cache0 vg Cwi---C--- 10.00g
2014-05-18 22:09:47 +04:00
.fi
2014-07-23 00:10:35 +04:00
.SH Cache Topics
.SS Tolerate device failures in a cache pool LV
\&
Users who are concerned about the possibility of failures in their fast
devices that could lead to data loss might consider making their cache
pool sub-LVs redundant.
2014-05-18 22:09:47 +04:00
.nf
0. Create an origin LV we wish to cache
2014-06-11 13:06:30 +04:00
# lvcreate \- L 10G \- n lvx vg /dev/slow_devs
2014-05-18 22:09:47 +04:00
1. Create a 2-way RAID1 cache data LV
2014-06-11 13:06:30 +04:00
# lvcreate \- \- type raid1 \- m 1 \- L 1G -n lvx_cache vg \\
2014-05-18 22:09:47 +04:00
/dev/fast1 /dev/fast2
2. Create a 2-way RAID1 cache metadata LV
2014-06-11 13:06:30 +04:00
# lvcreate \- \- type raid1 \- m 1 \- L 8M -n lvx_cache_meta vg \\
2014-05-18 22:09:47 +04:00
/dev/fast1 /dev/fast2
3. Create a cache pool LV combining cache data LV and cache metadata LV
2014-07-22 00:41:42 +04:00
# lvconvert \- \- cachepool vg/lvx_cache \- \- poolmetadata vg/lvx_cache_meta
2014-05-18 22:09:47 +04:00
4. Create a cached LV by combining the cache pool LV and origin LV
2014-06-11 13:06:30 +04:00
# lvconvert \- \- type cache \- \- cachepool vg/lvx_cache vg/lvx
2014-05-18 22:09:47 +04:00
.fi
2014-07-23 00:10:35 +04:00
.SS Writethough caching
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
\&
Writethrough caching ensures that any data written will be stored both in
the cache pool LV and on the origin LV. The loss of a device associated
with the cache pool LV in this case would not mean the loss of any data.
When combining the cache data LV and the cache metadata LV to form the
cache pool LV, properties of the cache can be specified - in this case,
\fI writethrough\fP vs. \fI writeback\fP .
2014-05-18 22:09:47 +04:00
.nf
0. Create an origin LV we wish to cache (yours may already exist)
2014-06-11 13:06:30 +04:00
# lvcreate \- L 10G \- n lvx vg /dev/slow
2014-05-18 22:09:47 +04:00
1. Create a cache data LV
2014-06-11 13:06:30 +04:00
# lvcreate \- L 1G \- n lvx_cache vg /dev/fast
2014-05-18 22:09:47 +04:00
2. Create a cache metadata LV
2014-06-11 13:06:30 +04:00
# lvcreate \- L 8M \- n lvx_cache_meta vg /dev/fast
2014-05-18 22:09:47 +04:00
3. Create a cache pool LV specifying cache mode "writethrough"
2014-07-22 00:41:42 +04:00
# lvconvert \- \- cachepool vg/lvx_cache \- \- poolmetadata vg/lvx_cache_meta \\
\- \- cachemode writethrough
2014-05-18 22:09:47 +04:00
4. Create a cache LV by combining the cache pool LV and origin LV
2014-06-11 13:06:30 +04:00
# lvconvert \- \- type cache \- \- cachepool vg/lvx_cache vg/lvx
2014-05-18 22:09:47 +04:00
.fi
2014-07-23 00:10:35 +04:00
.SS Spare metadata LV
2014-07-22 00:41:42 +04:00
2014-07-23 00:10:35 +04:00
\&
2014-07-22 00:41:42 +04:00
2014-07-23 00:10:35 +04:00
See
.BR lvmthin (7)
for a description of the "pool metadata spare" LV.
The same concept is used for cache pools.
2014-07-22 00:41:42 +04:00
2014-07-23 00:10:35 +04:00
.SS Automatic pool metadata LV
2014-07-22 00:41:42 +04:00
2014-07-23 00:10:35 +04:00
\&
2014-07-22 00:41:42 +04:00
2014-07-23 00:10:35 +04:00
A cache data LV can be converted to cache pool LV without specifying a
cache pool metadata LV. LVM will automatically create a metadata LV from
the same VG.
2014-07-22 00:41:42 +04:00
2014-07-23 00:10:35 +04:00
.B lvcreate -n CacheDataLV -L CacheSize VG
.br
.B lvconvert --cachepool VG/CacheDataLV
2014-07-22 00:41:42 +04:00
2014-05-18 22:09:47 +04:00
.SH SEE ALSO
.BR lvm.conf (5),
.BR lvchange (8),
.BR lvcreate (8),
.BR lvdisplay (8),
.BR lvextend (8),
.BR lvremove (8),
.BR lvrename (8),
.BR lvresize (8),
.BR lvs (8),
.BR vgchange (8),
.BR vgmerge (8),
.BR vgreduce (8),
.BR vgsplit (8)