Lvmcache - a simple how to

Assumptions:

  • You already have a working OS
  • This is new storage being added
    ** (or) if you already are using lvm you could just enable a cache device for existing logical volume

My supplies:

  • 4TB WD Red Drive
  • 280G Optane (pick your poison, this is mine)

Important thing to note about how you handle your lvm storage in the future:

  • Expanding your large/slow LV in the future will need to be handled with care if you do not use every bit of the drive you are using for lvmcache

==================

Steps:

1. Setup physical volumes & volume group

#this is my wd red drive (slow PV)

pvcreate /dev/sdc
vgcreate localred /dev/sdc

#this is the optane drive (fast PV)

pvcreate /dev/nvme0n1
vgextend localred /dev/nvme0n1

2. Create logical volumes

#creating the slow & large LV

lvcreate -n red4tb -L 2t localred /dev/sdc

– Feel free to format the LV & mount it as you wish at this point –

#take note that the PV is specifed when creating the fast LV

lvcreate -n cac0 -L 100g localred /dev/nvme0n1

#take note that the PV is specifed when creating the metadata LV

lvcreate -n met0 -L 122m localred /dev/nvme0n1

3. Setup the cache

#creates the cache by combining the cache and meta LVs

lvconvert --type cache-pool --poolmetadata localred/met0 localred/cac0

#combines the cache and slow LVs

lvconvert --type cache --cachepool localred/cac0 localred/red4tb

check your work #it will take some time for your cache to start filling up

4. Enable writeback mode

#check the mode (default is writethrough)

lvs -o+cache_mode localred/red4tb

#change the mode

lvchange --cachemode writeback localred/red4tb

==========

My results

=========

The blue line is what wait I/O looked like before I changed the write mode to writeback
image

Now see how it looks after a few days, since I change write modes

8 Likes

Two days.

Today and part of tomorrow.

Cache still continues to grow… performance is very nice.

2 Likes

I may be addicted to lvmcache
…just repurposed two old drives I pulled from my old x58 desktop back when I sold it
to create another lvmcache

hi i was following this tutorial then got stuck on lvconvert output

Volume group “VG” has insufficient free space (61 extents): 512 required.

any ideas?

Free up or add space

1 Like

freed space on fast storage = didnt work

then

freed space on slow storage = tada!!! it worked

thanks :smiley:

2 Likes