wiki:lvm-cache

Version 2 (modified by JaimeV, 4 years ago) ( diff )

--

An lvm cache logical volume uses a small logical volume consisting of fast block devices (such as SSD drives) to improve the performance of a larger and slower logical volume ( like spinning disks ) by storing the frequently used blocks on the smaller, faster logical volume.

Setup lvm cache

To setup lvm cache for a logical volume on one of our virtual servers observe the following steps

In the example below our new block device is /dev/sdb but it will not always be, make sure you have correctly identified the correct empty block device and change the command accordingly. In this example we plan on caching the logical volume "home" that belongs to volume group vg_erica0 , so we'll add our new block device to vg_erica0

# vgextend vg_erica0 /dev/sdb

Enabling the cache

Creating the cache is a multistep process but we can automate most of it with one command. In the example below vg_erica0/home is the logical volume we want to cache and /dev/sdb is our new SSD block device.

# lvcreate --type cache --cachemode writeback -l 100%FREE --name home_cachepool vg_erica0/home /dev/sdb
  Using 96.00 KiB chunk size instead of default 64.00 KiB, so cache pool has less than 1000000 chunks.
  Logical volume vg_erica0/home is now cached.

Disabling the cache

# lvconvert --uncache vg_erica0/home
  Flushing 6 blocks for cache vg_erica0/home.
  Flushing 4 blocks for cache vg_erica0/home.
  Logical volume "home_cachepool" successfully removed
  Logical volume vg_erica0/home is not cached.

Examining the cache

# lvs -a 
  home                   vg_ossie0 Cwi-aoC--- 889.00g [home_cachepool] [home_corig] 0.46   16.21           71.37           
  [home_cachepool]       vg_ossie0 Cwi---C--- <90.14g                               0.46   16.21           71.37           
  [home_cachepool_cdata] vg_ossie0 Cwi-ao---- <90.14g                                                                      
  [home_cachepool_cmeta] vg_ossie0 ewi-ao----  48.00m                                                                      
  [home_corig]           vg_ossie0 owi-aoC--- 889.00g 

More Details

LVM caching uses the following LVM logical volume types. All of these associated logical volumes must be in the same volume group.

  • Origin logical volume the large, slow logical volume
  • Cache pool logical volume the small, fast logical volume, which is composed of two devices: the cache data logical volume, and the cache metadata logical volume
    • Cache data logical volume the logical volume containing the data blocks for the cache pool logical volume
    • Cache metadata logical volume the logical volume containing the metadata for the cache pool logical volume, which holds the accounting information that specifies where data blocks are stored (for example, on the origin logical volume or the cache data logical volume).
  • Cache logical volume the logical volume containing the origin logical volume and the cache pool logical volume. This is the resultant usable device which encapsulates the various cache volume components.
Note: See TracWiki for help on using the wiki.