In the other article, I described a quick way to create LVM cached Logical volume, Here is a bit advanced options you can play with if are running mission critical applications on lvmcache.
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. 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.
With the --cachemode option, the cache mode can be set when creating a 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:
lvs -o+cache_mode VG/CacheLV lvm.conf(5) allocation/cache_mode defines the default cache mode. Example 0. Create an origin LV we wish to cache (yours may already exist) # lvcreate -L 10G -n lv1 vg /dev/slow 1. Create a cache data LV # lvcreate -L 1G -n cache1 vg /dev/fast 2. Create a cache metadata LV # lvcreate -L 8M -n cache1meta vg /dev/fast 3. Create a cache pool LV # lvconvert --type cache-pool --poolmetadata vg/cache1meta vg/cache1 4. Create a cache LV by combining the cache pool LV and origin LV, and use the writethrough cache mode. # lvconvert --type cache --cachepool vg/cache1 --cachemode writethrough vg/lv1
The cache subsystem has additional per-LV parameters: Three policies are currently available: smq, mq, and cleaner
"smq" is the default policy,"mq" is an older implementation, mq
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.
cleaner is used to force the cache to write back (flush) all cached
writes to the origin LV.
With the --cachepolicy and --cachesettings options, the cache policy 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:
lvs -o+cache_policy,cache_settings VG/CacheLV
Change the cache policy and settings of an existing cache LV.
# lvchange --cachepolicy mq --cachesettings 'migration_threshold=2048 random_threshold=4' vg/lv1
lvm.conf(5) allocation/cache_policy defines the default cache policy.
lvm.conf(5) allocation/cache_settings defines the default cache settings.
The size of data blocks managed by a cache pool can be specified with the --chunksize option when the cache LV is created. The default unit 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: lvs -o+chunksize VG/CacheLV lvm.conf(5) cache_pool_chunk_size controls the default chunk size used when creating a cache LV. The default value is shown by: lvmconfig --type default allocation/cache_pool_chunk_size