LVM caching

Many of you are familiar with LVM (I’m sure of that because you must have at least installed some linux distro like something RedHat based with default options and got some partitions on LVM because of that) and maybe some of you are also aware of its “power” (if I can call it like that) which is flexibility.

For me LVM is excellent for certain deployments where I need flexibility and the last time I used it, I remembered I needed something a bit special – wanted to store some virtual machines on disk (spinning disk) but at same time try to improve their disk IO performance with some SSD caching – and decided to share that with the world.

A bit of googling and reading through the doc gave me the solution I was looking for (short story):

Your slow HDD device is /dev/vdb
Your fast SDD device is /dev/vdc

pvcreate /dev/vdb
pvcreate /dev/vdc

#need to create the volume group on both disks
vgcreate vg_data /dev/vdb /dev/vdc

#create a LV on slow HDD for data
lvcreate -L 10G -n lv_data vg_data /dev/vdb

#create a LV on fast SSD to use as cache for metadata (ratio is 1000:1 hence 100M in this case)
lvcreate -n cachepool_meta -L 100M vg_data /dev/vdc

#create a LV on fast SSD to use as your cache for data
lvcreate -n cachepool -L 5G vg_data /dev/vdc

#create a cache pool that contains the two LVs that you created for caching
lvconvert –type cache-pool –poolmetadata cachepool_meta vg_data/cachepool

#mark it as the cache pool to be used for the data LV
lvconvert –type cache –cache-pool cachepool –cachemode writethrough vg_data/lv_data

#no need for this one unless you want writeback cache
lvchange –cachemode writeback vg_data/lv_data

#this will show you how everything looks like on disk and more

lvs -a -o +devices,cache_total_blocks,cache_used_blocks,cache_dirty_blocks,cache_read_hits,cache_read_misses,cache_write_hits,cache_write_misses,segtype

As far as I’m concerned, for my test setup, LVM rocks because I got to stay on the cheap side (not needing to pack my server full of SSDs or buy a fancy RAID card) while at same time giving me the performance and flexibility I need.

Hope it helps you (the reader) too! 🙂


Posted

in

by

Tags: