Chapter 13. Enabling caching to improve logical volume performance
You can add caching to an LVM logical volume to improve performance. LVM then caches I/O operations to the logical volume using a fast device, such as an SSD.
The following procedures create a special LV from the fast device, and attach this special LV to the original LV to improve the performance.
13.1. Caching methods in LVM
LVM provides the following kinds of caching. Each one is suitable for different kinds of I/O patterns on the logical volume.
dm-cache
This method speeds up access to frequently used data by caching it on the faster volume. The method caches both read and write operations.
The
dm-cache
method creates logical volumes of the typecache
.dm-writecache
This method caches only write operations. The faster volume stores the write operations and then migrates them to the slower disk in the background. The faster volume is usually an SSD or a persistent memory (PMEM) disk.
The
dm-writecache
method creates logical volumes of the typewritecache
.
13.2. LVM caching components
When you enable caching for a logical volume, LVM renames and hides the original volumes, and presents a new logical volume that is composed of the original logical volumes. The composition of the new logical volume depends on the caching method and whether you are using the cachevol
or cachepool
option.
The cachevol
and cachepool
options expose different levels of control over the placement of the caching components:
-
With the
cachevol
option, the faster device stores both the cached copies of data blocks and the metadata for managing the cache. With the
cachepool
option, separate devices can store the cached copies of data blocks and the metadata for managing the cache.The
dm-writecache
method is not compatible withcachepool
.
In all configurations, LVM exposes a single resulting device, which groups together all the caching components. The resulting device has the same name as the original slow logical volume.
13.3. Enabling dm-cache caching for a logical volume
This procedure enables caching of commonly used data on a logical volume using the dm-cache
method.
Prerequisites
-
A slow logical volume that you want to speed up using
dm-cache
exists on your system. - The volume group that contains the slow logical volume also contains an unused physical volume on a fast block device.
Procedure
Create a
cachevol
volume on the fast device:# lvcreate --size cachevol-size --name fastvol vg /dev/fast-pv
Replace the following values:
cachevol-size
-
The size of the
cachevol
volume, such as5G
fastvol
-
A name for the
cachevol
volume vg
- The volume group name
/dev/fast-pv
-
The path to the fast block device, such as
/dev/sdf1
Attach the
cachevol
volume to the main logical volume to begin caching:# lvconvert --type cache --cachevol fastvol vg/main-lv
Replace the following values:
fastvol
-
The name of the
cachevol
volume vg
- The volume group name
main-lv
- The name of the slow logical volume
Verification steps
Examine the newly created devices:
# lvs --all --options +devices vg LV Pool Type Devices main-lv [fastvol_cvol] cache main-lv_corig(0) [fastvol_cvol] linear /dev/fast-pv [main-lv_corig] linear /dev/slow-pv
Additional resources
-
For information on this procedure and other details, including administrative examples, see the
lvmcache(7)
man page.
13.4. Enabling dm-cache caching with a cachepool for a logical volume
This procedure enables you to create the cache data and the cache metadata logical volumes individually and then combine the volumes into a cache pool.
Prerequisites
-
A slow logical volume that you want to speed up using
dm-cache
exists on your system. - The volume group that contains the slow logical volume also contains an unused physical volume on a fast block device.
Procedure
Create a
cachepool
volume on the fast device:# lvcreate --type cache-pool --size cachepool-size --name fastpool vg /dev/fast
Replace the following values:
cachepool-size
-
The size of the
cachepool
, such as5G
fastpool
-
A name for the
cachepool
volume vg
- The volume group name
/dev/fast
The path to the fast block device, such as
/dev/sdf1
NoteYou can use
--poolmetadata
option to specify the location of the pool metadata when creating the cache-pool.
Attach the
cachepool
to the main logical volume to begin caching:# lvconvert --type cache --cachepool fastpool vg/main
Replace the following values:
fastpool
-
The name of the
cachepool
volume vg
- The volume group name
main
- The name of the slow logical volume
Verification steps
Examine the newly created devices:
# lvs --all --options +devices vg LV Pool Type Devices [fastpool_cpool] cache-pool fastpool_pool_cdata(0) [fastpool_cpool_cdata] linear /dev/sdf1(4) [fastpool_cpool_cmeta] linear /dev/sdf1(2) [lvol0_pmspare] linear /dev/sdf1(0) main [fastpoool_cpool] cache main_corig(0) [main_corig] linear /dev/sdf1(O)
Additional resources
-
The
lvcreate(8)
man page. -
The
lvmcache(7)
man page. -
The
lvconvert(8)
man page.
13.5. Enabling dm-writecache caching for a logical volume
This procedure enables caching of write I/O operations to a logical volume using the dm-writecache
method.
Prerequisites
-
A slow logical volume that you want to speed up using
dm-writecache
exists on your system. - The volume group that contains the slow logical volume also contains an unused physical volume on a fast block device.
Procedure
If the slow logical volume is active, deactivate it:
# lvchange --activate n vg/main-lv
Replace the following values:
vg
- The volume group name
main-lv
- The name of the slow logical volume
Create a deactivated
cachevol
volume on the fast device:# lvcreate --activate n --size cachevol-size --name fastvol vg /dev/fast-pv
Replace the following values:
cachevol-size
-
The size of the
cachevol
volume, such as5G
fastvol
-
A name for the
cachevol
volume vg
- The volume group name
/dev/fast-pv
-
The path to the fast block device, such as
/dev/sdf1
Attach the
cachevol
volume to the main logical volume to begin caching:# lvconvert --type writecache --cachevol fastvol vg/main-lv
Replace the following values:
fastvol
-
The name of the
cachevol
volume vg
- The volume group name
main-lv
- The name of the slow logical volume
Activate the resulting logical volume:
# lvchange --activate y vg/main-lv
Replace the following values:
vg
- The volume group name
main-lv
- The name of the slow logical volume
Verification steps
Examine the newly created devices:
# lvs --all --options +devices vg LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices main-lv vg Cwi-a-C--- 500.00m [fastvol_cvol] [main-lv_wcorig] 0.00 main-lv_wcorig(0) [fastvol_cvol] vg Cwi-aoC--- 252.00m /dev/sdc1(0) [main-lv_wcorig] vg owi-aoC--- 500.00m /dev/sdb1(0)
Additional resources
-
For information, including administrative examples, see the
lvmcache(7)
man page.
13.6. Disabling caching for a logical volume
This procedure disables dm-cache
or dm-writecache
caching that is currently enabled on a logical volume.
Prerequisites
- Caching is enabled on a logical volume.
Procedure
Deactivate the logical volume:
# lvchange --activate n vg/main-lv
Replace the following values:
vg
- The volume group name
main-lv
- The name of the logical volume where caching is enabled
Detach the
cachevol
orcachepool
volume:# lvconvert --splitcache vg/main-lv
Replace the following values:
vg
- The volume group name
main-lv
- The name of the logical volume where caching is enabled
Verification steps
Check that the logical volumes are no longer attached together:
# lvs --all --options +devices [replaceable]_vg_ LV Attr Type Devices fastvol -wi------- linear /dev/fast-pv main-lv -wi------- linear /dev/slow-pv
Additional resources
-
The
lvmcache(7)
man page