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
2017-05-03 00:47:02 +03:00
An \fBlvm\fP(8) \fBcache\fP Logical Volume (LV) uses a small and
fast LV to improve the performance of a large and slow LV. It does this
by storing the frequently used blocks on the faster LV.
2014-05-18 22:09:47 +04:00
LVM refers to the small fast LV as a \fBcache pool LV\fP. The large
2017-03-27 17:45:48 +03:00
slow LV is called the \fBorigin LV\fP. Due to requirements from dm-cache
2014-05-18 22:09:47 +04:00
(the kernel driver), LVM further splits the cache pool LV into two
devices - the \fBcache data LV\fP and \fBcache 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
2017-05-03 00:47:02 +03:00
LVs. All of these associated LVs must be in the same Volume
Group (VG).
2014-05-18 22:09:47 +04:00
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
2017-05-03 00:47:02 +03:00
The primary method for using a cache type LV:
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.
2017-03-27 17:45:48 +03:00
.B lvcreate -n OriginLV -L LargeSize VG SlowPVs
2014-07-23 00:10:35 +04:00
.I Example
2014-07-22 00:41:42 +04:00
.br
2017-07-08 20:15:51 +03:00
# lvcreate -n lvol0 -L 100G vg /dev/slow
2014-07-23 00:10:35 +04:00
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.
2017-03-27 17:45:48 +03:00
.B lvcreate -n CacheDataLV -L CacheSize VG FastPVs
2014-07-23 00:10:35 +04:00
.I Example
2014-07-22 00:41:42 +04:00
.br
2017-03-27 17:45:48 +03:00
# lvcreate -n cache0 -L 10G vg /dev/fast
2014-07-23 00:10:35 +04:00
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.
2017-03-27 17:45:48 +03:00
.B lvcreate -n CacheMetaLV -L MetaSize VG FastPVs
2014-07-23 00:10:35 +04:00
.I Example
2014-07-22 00:41:42 +04:00
.br
2017-03-27 17:45:48 +03:00
# lvcreate -n cache0meta -L 12M vg /dev/fast
2014-07-23 00:10:35 +04:00
.nf
# lvs -a vg
LV VG Attr LSize Pool Origin
2017-03-27 17:45:48 +03:00
cache0 vg -wi-a----- 10.00g
cache0meta vg -wi-a----- 12.00m
lvol0 vg -wi-a----- 100.00g
2014-07-23 00:10:35 +04:00
.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.
2017-03-27 17:45:48 +03:00
.B lvconvert --type cache-pool --poolmetadata VG/CacheMetaLV
2014-10-01 19:43:53 +04:00
.RS
.B VG/CacheDataLV
.RE
2014-07-23 00:10:35 +04:00
.I Example
2014-07-22 00:41:42 +04:00
.br
2017-03-27 17:45:48 +03:00
# lvconvert --type cache-pool --poolmetadata vg/cache0meta vg/cache0
2014-07-23 00:10:35 +04:00
.nf
# lvs -a vg
LV VG Attr LSize Pool Origin
2017-03-27 17:45:48 +03:00
cache0 vg Cwi---C--- 10.00g
[cache0_cdata] vg Cwi------- 10.00g
[cache0_cmeta] vg ewi------- 12.00m
lvol0 vg -wi-a----- 100.00g
2014-07-23 00:10:35 +04:00
.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.
2017-03-27 17:45:48 +03: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
2017-03-27 17:45:48 +03:00
# lvconvert --type cache --cachepool vg/cache0 vg/lvol0
2014-07-23 00:10:35 +04:00
.nf
# lvs -a vg
LV VG Attr LSize Pool Origin
2017-03-27 17:45:48 +03:00
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
2014-07-23 00:10:35 +04:00
.fi
.SH Cache Removal
2014-07-22 00:41:42 +04:00
2014-10-06 23:04:09 +04:00
.SS Split a cache pool LV off of a cache LV
\&
A cache pool LV can be disconnected from a cache LV, leaving an
unused cache pool LV, and an uncached origin LV. This command
writes back data from the cache pool to the origin LV when necessary.
2017-03-27 17:45:48 +03:00
.B lvconvert --splitcache VG/CacheLV
2014-10-06 23:04:09 +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,
2014-10-06 23:04:09 +04:00
then removes the cache pool LV, leaving the uncached origin LV.
2014-07-23 00:10:35 +04:00
.B lvremove VG/CachePoolLV
2014-10-06 23:04:09 +04:00
An alternative command that also disconnects the cache pool from the cache
LV, and deletes the cache pool:
2017-03-27 17:45:48 +03:00
.B lvconvert --uncache VG/CacheLV
2014-10-06 23:04:09 +04:00
2014-07-23 00:10:35 +04:00
.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
2017-03-27 17:45:48 +03:00
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
2017-03-27 17:45:48 +03:00
lvol0 vg -wi-a----- 100.00g
2014-07-23 00:10:35 +04:00
.fi
2014-05-18 22:09:47 +04:00
2014-10-06 23:04:09 +04:00
.SS Removing a cache LV: both origin LV and the cache pool LV
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
\&
2014-10-06 23:04:09 +04:00
Removing a cache LV removes both the origin LV and the linked cache pool
LV.
2014-07-23 00:10:35 +04:00
.B lvremove VG/CacheLV
2014-05-18 22:09:47 +04:00
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
2017-03-27 17:45:48 +03:00
pool sub-LVs redundant.
2014-05-18 22:09:47 +04:00
2015-10-01 19:39:07 +03:00
.I Example
2014-05-18 22:09:47 +04:00
.nf
0. Create an origin LV we wish to cache
2017-07-08 20:15:51 +03:00
# lvcreate -L 10G -n lv1 vg /dev/slow
2014-05-18 22:09:47 +04:00
1. Create a 2-way RAID1 cache data LV
2017-03-27 17:45:48 +03:00
# lvcreate --type raid1 -m 1 -L 1G -n cache1 vg \\
2014-05-18 22:09:47 +04:00
/dev/fast1 /dev/fast2
2. Create a 2-way RAID1 cache metadata LV
2017-03-27 17:45:48 +03:00
# lvcreate --type raid1 -m 1 -L 8M -n cache1meta 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
2017-03-27 17:45:48 +03:00
# lvconvert --type cache-pool --poolmetadata vg/cache1meta vg/cache1
2014-05-18 22:09:47 +04:00
4. Create a cached LV by combining the cache pool LV and origin LV
2017-03-27 17:45:48 +03:00
# lvconvert --type cache --cachepool vg/cache1 vg/lv1
2014-05-18 22:09:47 +04:00
.fi
2014-08-27 01:40:47 +04:00
.SS Cache mode
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
\&
2014-08-27 01:40:47 +04:00
The default cache mode is "writethrough". Writethrough 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.
A second cache mode is "writeback". Writeback delays writing data blocks
from the cache pool back to the origin LV. This mode will increase
performance, but the loss of a device associated with the cache pool LV
can result in lost data.
2017-03-27 17:45:48 +03:00
With the --cachemode option, the cache mode can be set when creating a
2015-10-01 19:39:07 +03:00
cache LV, or changed on an existing cache LV. The current cache mode of a
cache LV can be displayed with the cache_mode reporting option:
2017-03-27 17:45:48 +03:00
.B lvs -o+cache_mode VG/CacheLV
2014-08-27 01:40:47 +04:00
.BR lvm.conf (5)
2015-10-01 19:39:07 +03:00
.B allocation/cache_mode
2014-08-27 01:40:47 +04:00
.br
defines the default cache mode.
2014-05-18 22:09:47 +04:00
2015-10-01 19:39:07 +03:00
.I Example
2014-05-18 22:09:47 +04:00
.nf
0. Create an origin LV we wish to cache (yours may already exist)
2017-03-27 17:45:48 +03:00
# lvcreate -L 10G -n lv1 vg /dev/slow
2014-05-18 22:09:47 +04:00
1. Create a cache data LV
2017-03-27 17:45:48 +03:00
# lvcreate -L 1G -n cache1 vg /dev/fast
2014-05-18 22:09:47 +04:00
2. Create a cache metadata LV
2017-03-27 17:45:48 +03:00
# lvcreate -L 8M -n cache1meta vg /dev/fast
2014-05-18 22:09:47 +04:00
2015-10-01 19:39:07 +03:00
3. Create a cache pool LV
2017-03-27 17:45:48 +03:00
# lvconvert --type cache-pool --poolmetadata vg/cache1meta vg/cache1
2014-05-18 22:09:47 +04:00
2015-10-01 19:39:07 +03:00
4. Create a cache LV by combining the cache pool LV and origin LV,
and use the writethrough cache mode.
2017-03-27 17:45:48 +03:00
# lvconvert --type cache --cachepool vg/cache1 \\
--cachemode writethrough vg/lv1
2014-05-18 22:09:47 +04:00
.fi
2015-06-15 22:30:58 +03:00
2015-10-01 19:39:07 +03:00
.SS Cache policy
2015-06-15 22:30:58 +03:00
2015-10-01 19:39:07 +03:00
\&
2015-06-15 22:30:58 +03:00
2017-03-27 17:45:48 +03:00
The cache subsystem has additional per-LV parameters: the cache policy to
2015-10-01 19:39:07 +03:00
use, and possibly tunable parameters for the cache policy. Three policies
are currently available: "smq" is the default policy, "mq" is an older
implementation, and "cleaner" is used to force the cache to write back
(flush) all cached writes to the origin LV.
2015-02-25 20:20:06 +03:00
2015-10-01 19:39:07 +03:00
The "mq" policy has a number of tunable parameters. The defaults are
chosen to be suitable for the majority of systems, but in special
circumstances, changing the settings can improve performance.
2015-02-25 20:20:06 +03:00
2017-03-27 17:45:48 +03:00
With the --cachepolicy and --cachesettings options, the cache policy
2015-10-01 19:39:07 +03:00
and settings can be set when creating a cache LV, or changed on an
existing cache LV (both options can be used together). The current cache
policy and settings of a cache LV can be displayed with the cache_policy
and cache_settings reporting options:
2015-02-25 20:20:06 +03:00
2017-03-27 17:45:48 +03:00
.B lvs -o+cache_policy,cache_settings VG/CacheLV
2015-02-25 20:20:06 +03:00
.I Example
.nf
2015-10-01 19:39:07 +03:00
Change the cache policy and settings of an existing cache LV.
2017-03-27 17:45:48 +03:00
# lvchange --cachepolicy mq --cachesettings \\
2015-10-01 19:39:07 +03:00
\(aqmigration_threshold=2048 random_threshold=4\(aq vg/lv1
2015-02-25 20:20:06 +03:00
.fi
2015-10-01 19:39:07 +03:00
.BR lvm.conf (5)
.B allocation/cache_policy
.br
defines the default cache policy.
.BR lvm.conf (5)
.B allocation/cache_settings
.br
defines the default cache settings.
2015-02-25 20:20:06 +03:00
2015-11-23 20:57:41 +03:00
.SS Chunk size
\&
The size of data blocks managed by a cache pool can be specified with the
2017-03-27 17:45:48 +03:00
--chunksize option when the cache LV is created. The default unit
2015-11-23 20:57:41 +03:00
is KiB. The value must be a multiple of 32KiB between 32KiB and 1GiB.
Using a chunk size that is too large can result in wasteful use of the
cache, where small reads and writes can cause large sections of an LV to
be mapped into the cache. However, choosing a chunk size that is too
small can result in more overhead trying to manage the numerous chunks
that become mapped into the cache. Overhead can include both excessive
CPU time searching for chunks, and excessive memory tracking chunks.
Command to display the cache pool LV chunk size:
.br
2017-03-27 17:45:48 +03:00
.B lvs -o+chunksize VG/CacheLV
2015-11-23 20:57:41 +03:00
.BR lvm.conf (5)
.B cache_pool_chunk_size
.br
controls the default chunk size used when creating a cache LV.
The default value is shown by:
.br
2017-03-27 17:45:48 +03:00
.B lvmconfig --type default allocation/cache_pool_chunk_size
2015-11-23 20:57:41 +03:00
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
2017-03-27 17:45:48 +03:00
.B lvconvert --type cache-pool VG/CacheDataLV
2014-07-22 00:41:42 +04:00
2014-10-07 01:12:51 +04:00
2014-08-27 01:40:47 +04:00
.SS Create a new cache LV without an existing origin LV
\&
A cache LV can be created using an existing cache pool without an existing
origin LV. A new origin LV is created and linked to the cache pool in a
single step.
2017-03-27 17:45:48 +03:00
.B lvcreate --type cache -L LargeSize -n CacheLV
2014-08-27 01:40:47 +04:00
.RS
2017-03-27 17:45:48 +03:00
.B --cachepool VG/CachePoolLV VG SlowPVs
2014-08-27 01:40:47 +04:00
.RE
.SS Single step cache pool LV creation
\&
A cache pool LV can be created with a single lvcreate command, rather than
using lvconvert on existing LVs. This one command creates a cache data
LV, a cache metadata LV, and combines the two into a cache pool LV.
2017-03-27 17:45:48 +03:00
.B lvcreate --type cache-pool -L CacheSize -n CachePoolLV VG FastPVs
2014-08-27 01:40:47 +04:00
2014-05-18 22:09:47 +04:00
2014-10-07 01:12:51 +04:00
.SS Convert existing LVs to cache types
\&
When an existing origin LV is converted to a cache LV, the specified cache
pool may be a normal LV, rather than a cache pool LV. In this case, lvm
will first convert the normal LV to a cache pool LV. A pool metadata LV
may optionally be specified.
.B lvcreate -n OriginLV -L LargeSize VG
.br
.B lvcreate -n CacheDataLV -L CacheSize VG
.br
2017-03-27 17:45:48 +03:00
.B lvconvert --type cache --cachepool VG/CataDataLV VG/OriginLV
2014-10-07 01:12:51 +04:00
This is equivalent to:
.B lvcreate -n OriginLV -L LargeSize VG
.br
.B lvcreate -n CacheDataLV -L CacheSize VG
.br
2017-03-27 17:45:48 +03:00
.B lvconvert --type cache-pool VG/CacheDataLV
2014-10-07 01:12:51 +04:00
.br
2017-03-27 17:45:48 +03:00
.B lvconvert --type cache --cachepool VG/CachePoolLV VG/OriginLV
2014-10-07 01:12:51 +04:00
2017-05-11 18:52:59 +03:00
.SS Cache metadata formats
\&
There are two disk formats for cache metadata. The metadata format can be
specified when a cache pool is created, and cannot be changed.
Format \fB2\fP has better performance; it is more compact, and stores
dirty bits in a separate btree, which improves the speed of shutting down
the cache.
With \fBauto\fP, lvm selects the best option provided by the current
dm-cache kernel target.
.B lvconvert --type cache-pool --cachemetadataformat auto|1|2
.RS
.B VG/CacheDataLV
.RE
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)