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
2018-11-07 01:14:59 +03:00
\fBlvm\fP(8) includes two kinds of caching that can be used to improve the
performance of a Logical Volume (LV). Typically, a smaller, faster device
is used to improve i/o performance of a larger, slower LV. To do this, a
separate LV is created from the faster device, and then the original LV is
converted to start using the fast LV.
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
The two kinds of caching are:
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.IP \[bu] 2
A read and write hot-spot cache, using the dm-cache kernel module. This
cache is slow moving, and adjusts the cache content over time so that the
most used parts of the LV are kept on the faster device. Both reads and
writes use the cache. LVM refers to this using the LV type \fBcache\fP.
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.IP \[bu] 2
A streaming write cache, using the dm-writecache kernel module. This
cache is intended to be used with SSD or PMEM devices to speed up all
writes to an LV. Reads do not use this cache. LVM refers to this using
the LV type \fBwritecache\fP.
2014-07-22 00:41:42 +04:00
2018-11-07 01:14:59 +03:00
.SH USAGE
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
Both kinds of caching use similar lvm commands:
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
.B 1. Identify main LV that needs caching
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
A main LV exists on slower devices.
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
.nf
$ lvcreate -n main -L Size vg /dev/slow
.fi
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.B 2. Identify fast LV to use as the cache
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
A fast LV exists on faster devices. This LV will be used to hold the
cache.
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
.nf
$ lvcreate -n fast -L Size vg /dev/fast
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
$ lvs vg -o+devices
LV VG Attr LSize Devices
fast vg -wi------- xx.00m /dev/fast(0)
main vg -wi------- yyy.00m /dev/slow(0)
.fi
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
.B 3. Start caching the main LV
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
To start caching the main LV using the fast LV, convert the main LV to the
desired caching type, and specify the fast LV to use:
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
.nf
using dm-cache:
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
$ lvconvert --type cache --cachepool fast vg/main
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
or dm-writecache:
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
$ lvconvert --type writecache --cachepool fast vg/main
2014-07-23 00:10:35 +04:00
.fi
2018-11-07 01:14:59 +03:00
.B 4. Display LVs
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
Once the fast LV has been attached to the main LV, lvm reports the main LV
type as either \fBcache\fP or \fBwritecache\fP depending on the type used.
While attached, the fast LV is hidden, and only displayed when lvs is
given -a. The _corig or _wcorig LV represents the original LV without the
cache.
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
.nf
using dm-cache:
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
$ lvs -a -o name,vgname,lvattr,origin,segtype,devices vg
LV VG Attr Origin Type Devices
[fast] vg Cwi-aoC--- linear /dev/fast(xx)
main vg Cwi-a-C--- [main_corig] cache main_corig(0)
[main_corig] vg owi-aoC--- linear /dev/slow(0)
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
or dm-writecache:
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
$ lvs -a -o name,vgname,lvattr,origin,segtype,devices vg
LV VG Attr Origin Type Devices
[fast] vg -wi-ao---- linear /dev/fast(xx)
main vg Cwi-a----- [main_wcorig] writecache main_wcorig(0)
[main_wcorig] vg -wi-ao---- linear /dev/slow(0)
2014-07-23 00:10:35 +04:00
.fi
2018-11-07 01:14:59 +03:00
.B 5. Use the main LV
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
Use the LV until the cache is no longer wanted, or needs to be changed.
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
.B 6. Stop caching
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
To stop caching the main LV, separate the fast LV from the main LV. This
changes the type of the main LV back to what it was before the cache was
attached.
2014-07-23 00:10:35 +04:00
.nf
2018-11-07 01:14:59 +03:00
$ lvconvert --splitcache vg/main
2014-07-23 00:10:35 +04:00
.fi
2018-11-07 01:14:59 +03:00
.SH OPTIONS
2014-10-06 23:04:09 +04:00
\&
2018-11-07 01:14:59 +03:00
.SS dm-writecache block size
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
\&
2018-11-07 01:14:59 +03:00
The dm-writecache block size can be 4096 bytes (the default), or 512
bytes. The default 4096 has better performance and should be used except
when 512 is necessary for compatibility. The dm-writecache block size is
2018-11-22 00:16:23 +03:00
specified with --cachesettings block_size=4096|512 when caching is started.
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
When a file system like xfs already exists on the main LV prior to
caching, and the file system is using a block size of 512, then the
writecache block size should be set to 512. (The file system will likely
fail to mount if writecache block size of 4096 is used in this case.)
2014-10-06 23:04:09 +04:00
2018-11-07 01:14:59 +03:00
Check the xfs sector size while the fs is mounted:
2014-10-06 23:04:09 +04:00
2014-05-18 22:09:47 +04:00
.nf
2018-11-07 01:14:59 +03:00
$ xfs_info /dev/vg/main
Look for sectsz=512 or sectsz=4096
.fi
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
The writecache block size should be chosen to match the xfs sectsz value.
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
It is also possible to specify a sector size of 4096 to mkfs.xfs when
creating the file system. In this case the writecache block size of 4096
can be used.
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.SS dm-writecache settings
2014-05-18 22:09:47 +04:00
2014-07-23 00:10:35 +04:00
\&
2018-11-07 01:14:59 +03:00
Tunable parameters can be passed to the dm-writecache kernel module using
the --cachesettings option when caching is started, e.g.
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
.nf
$ lvconvert --type writecache --cachepool fast \\
--cachesettings 'high_watermark=N writeback_jobs=N' vg/main
.fi
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
Tunable options are:
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.IP \[bu] 2
high_watermark = <count>
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
Start writeback when the number of used blocks reach this watermark
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
.IP \[bu] 2
low_watermark = <count>
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
Stop writeback when the number of used blocks drops below this watermark
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.IP \[bu] 2
writeback_jobs = <count>
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
Limit the number of blocks that are in flight during writeback. Setting
this value reduces writeback throughput, but it may improve latency of
read requests.
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.IP \[bu] 2
autocommit_blocks = <count>
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
When the application writes this amount of blocks without issuing the
FLUSH request, the blocks are automatically commited.
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.IP \[bu] 2
autocommit_time = <milliseconds>
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
The data is automatically commited if this time passes and no FLUSH
request is received.
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.IP \[bu] 2
fua = 0|1
2014-07-23 00:10:35 +04:00
2018-11-07 01:14:59 +03:00
Use the FUA flag when writing data from persistent memory back to the
underlying device.
Applicable only to persistent memory.
2014-08-27 01:40:47 +04:00
2018-11-07 01:14:59 +03:00
.IP \[bu] 2
nofua = 0|1
2015-10-01 19:39:07 +03:00
2018-11-07 01:14:59 +03:00
Don't use the FUA flag when writing back data and send the FLUSH request
afterwards. Some underlying devices perform better with fua, some with
nofua. Testing is necessary to determine which.
Applicable only to persistent memory.
2014-08-27 01:40:47 +04:00
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.SS dm-cache with separate data and metadata LVs
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
\&
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
When using dm-cache, the cache metadata and cache data can be stored on
separate LVs. To do this, a "cache-pool LV" is created, which is a
special LV that references two sub LVs, one for data and one for metadata.
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
To create a cache-pool LV from two separate LVs:
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.nf
$ lvcreate -n fastpool -L DataSize vg /dev/fast1
$ lvcreate -n fastpoolmeta -L MetadataSize vg /dev/fast2
$ lvconvert --type cache-pool --poolmetadata fastpoolmeta vg/fastpool
2014-05-18 22:09:47 +04:00
.fi
2018-11-07 01:14:59 +03:00
Then use the cache-pool LV to start caching the main LV:
2015-06-15 22:30:58 +03:00
2018-11-07 01:14:59 +03:00
.nf
$ lvconvert --type cache --cachepool fastpool vg/main
.fi
2015-06-15 22:30:58 +03:00
2018-11-07 01:14:59 +03:00
A variation of the same procedure automatically creates a cache-pool when
caching is started. To do this, use a standard LV as the --cachepool
(this will hold cache data), and use another standard LV as the
--poolmetadata (this will hold cache metadata). LVM will create a
cache-pool LV from the two specified LVs, and use the cache-pool to start
caching the main LV.
2015-06-15 22:30:58 +03:00
2018-11-07 01:14:59 +03:00
.nf
$ lvcreate -n fastpool -L DataSize vg /dev/fast1
$ lvcreate -n fastpoolmeta -L MetadataSize vg /dev/fast2
$ lvconvert --type cache --cachepool fastpool \\
--poolmetadata fastpoolmeta vg/main
.fi
2015-02-25 20:20:06 +03:00
2018-11-07 01:14:59 +03:00
.SS dm-cache cache modes
2015-02-25 20:20:06 +03:00
2018-11-07 01:14:59 +03:00
\&
2015-02-25 20:20:06 +03:00
2018-11-07 01:14:59 +03:00
The default dm-cache cache mode is "writethrough". Writethrough ensures
that any data written will be stored both in the cache and on the origin
LV. The loss of a device associated with the cache in this case would not
mean the loss of any data.
2015-02-25 20:20:06 +03:00
2018-11-07 01:14:59 +03:00
A second cache mode is "writeback". Writeback delays writing data blocks
from the cache back to the origin LV. This mode will increase
performance, but the loss of a cache device can result in lost data.
2015-02-25 20:20:06 +03:00
2018-11-07 01:14:59 +03:00
With the --cachemode option, the cache mode can be set when caching is
started, or changed on an LV that is already cached. The current cache
mode can be displayed with the cache_mode reporting option:
.B lvs -o+cache_mode VG/LV
2015-10-01 19:39:07 +03:00
.BR lvm.conf (5)
2018-11-07 01:14:59 +03:00
.B allocation/cache_mode
2015-10-01 19:39:07 +03:00
.br
2018-11-07 01:14:59 +03:00
defines the default cache mode.
2015-02-25 20:20:06 +03:00
2018-11-07 01:14:59 +03:00
.nf
$ lvconvert --type cache --cachepool fast \\
--cachemode writethrough vg/main
.nf
2015-02-25 20:20:06 +03:00
2018-11-07 01:14:59 +03:00
.SS dm-cache chunk size
2015-11-23 20:57:41 +03:00
\&
2018-11-07 01:14:59 +03:00
The size of data blocks managed by dm-cache can be specified with the
--chunksize option when caching is started. The default unit is KiB. The
value must be a multiple of 32KiB between 32KiB and 1GiB.
2015-11-23 20:57:41 +03:00
Using a chunk size that is too large can result in wasteful use of the
2018-11-07 01:14:59 +03:00
cache, in which small reads and writes cause large sections of an LV to be
stored in 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.
2015-11-23 20:57:41 +03:00
2018-11-07 01:14:59 +03:00
Command to display the chunk size:
2015-11-23 20:57:41 +03:00
.br
2018-11-07 01:14:59 +03:00
.B lvs -o+chunksize VG/LV
2015-11-23 20:57:41 +03:00
.BR lvm.conf (5)
.B cache_pool_chunk_size
.br
2018-11-07 01:14:59 +03:00
controls the default chunk size.
2015-11-23 20:57:41 +03:00
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
2018-11-07 01:14:59 +03:00
.SS dm-cache cache policy
2014-07-22 00:41:42 +04:00
2014-07-23 00:10:35 +04:00
\&
2014-07-22 00:41:42 +04:00
2018-11-07 01:14:59 +03:00
The dm-cache subsystem has additional per-LV parameters: the cache policy
to 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.
2014-07-22 00:41:42 +04:00
2018-11-07 01:14:59 +03:00
The older "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.
2014-07-22 00:41:42 +04:00
2018-11-07 01:14:59 +03:00
With the --cachepolicy and --cachesettings options, the cache policy and
settings can be set when caching is started, or changed on an existing
cached LV (both options can be used together). The current cache policy
and settings can be displayed with the cache_policy and cache_settings
reporting options:
2014-10-07 01:12:51 +04:00
2018-11-07 01:14:59 +03:00
.B lvs -o+cache_policy,cache_settings VG/LV
2014-08-27 01:40:47 +04:00
2018-11-07 01:14:59 +03:00
.nf
Change the cache policy and settings of an existing LV.
2014-08-27 01:40:47 +04:00
2018-11-07 01:14:59 +03:00
$ lvchange --cachepolicy mq --cachesettings \\
\(aqmigration_threshold=2048 random_threshold=4\(aq vg/main
.fi
2014-08-27 01:40:47 +04:00
2018-11-07 01:14:59 +03:00
.BR lvm.conf (5)
.B allocation/cache_policy
.br
defines the default cache policy.
2014-08-27 01:40:47 +04:00
2018-11-07 01:14:59 +03:00
.BR lvm.conf (5)
.B allocation/cache_settings
.br
defines the default cache settings.
2014-08-27 01:40:47 +04:00
2018-11-07 01:14:59 +03:00
.SS dm-cache spare metadata LV
2014-08-27 01:40:47 +04:00
\&
2018-11-07 01:14:59 +03:00
See
.BR lvmthin (7)
for a description of the "pool metadata spare" LV.
The same concept is used for cache pools.
2014-05-18 22:09:47 +04:00
2018-11-07 01:14:59 +03:00
.SS dm-cache metadata formats
2014-10-07 01:12:51 +04:00
\&
2018-11-07 01:14:59 +03:00
There are two disk formats for dm-cache metadata. The metadata format can
be specified with --cachemetadataformat when caching is started, 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 module.
2014-10-07 01:12:51 +04:00
2018-11-07 01:14:59 +03:00
.SS mirrored cache device
2017-05-11 18:52:59 +03:00
\&
2018-11-07 01:14:59 +03:00
The fast LV holding the cache can be created as a raid1 mirror so that it
can tolerate a device failure. (When using dm-cache with separate data
and metadata LVs, each of the sub-LVs can use raid1.)
2017-05-11 18:52:59 +03:00
2018-11-07 01:14:59 +03:00
.nf
$ lvcreate -n main -L Size vg /dev/slow
$ lvcreate --type raid1 -m 1 -n fast -L Size vg /dev/fast1 /dev/fast2
$ lvconvert --type cache --cachepool fast vg/main
.fi
2017-05-11 18:52:59 +03: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)