Cache logical volumes with dm-writecache

When caching LVs with dm-writecache, a cache layer is created between the logical volume and storage device. dm-writecache stores writes on faster media, such as SSDs, before writing them to primary storage. This improves write-intensive workload performance.

Before you begin

  • Administrative access.

Procedure

  1. Display the logical volume you want to cache and its volume group:
    # lvs -o lv_name,vg_name
      LV                   VG
      LogicalVolumeName    VolumeGroupName
  2. Create a cache volume:
    # lvcreate --name CacheVolumeName --size SizeVolumeGroupName /FastDevicePath

    Replace CacheVolumeName with the name of the cache volume. Replace Size with the size for your cache pool. Replace VolumeGroupName with the name of the volume group. Replace /FastDevicePath with the path to your fast device, for example SSD or NVME.

  3. Deactivate the cache volume:
    # lvchange -an VolumeGroupName/CacheVolumeName

    Replace VolumeGroupName with the name of the volume group. Replace CacheVolumeName with the name of the cache volume.

  4. Attach the cache volume to the LV:
    # lvconvert --type writecache --cachevol CacheVolumeName VolumeGroupName/LogicalVolumeName

    Replace CacheVolumeName with the name of the cache volume. Replace VolumeGroupName with the name of the volume group. Replace LogicalVolumeName with the name of the logical volume.

Results

  • Verify that the LV is now cached:
    # lvs -o lv_name,pool_lv
      LV                   Pool
      LogicalVolumeName    [CacheVolumeName_cvol]