Skip to content

Instantly share code, notes, and snippets.

@mikaeldui
Forked from gabrieljcs/lvm-cache-fedora.md
Last active April 23, 2025 00:06
Show Gist options
  • Save mikaeldui/2af59f45497e71744fa1ac53529bb46f to your computer and use it in GitHub Desktop.
Save mikaeldui/2af59f45497e71744fa1ac53529bb46f to your computer and use it in GitHub Desktop.
Fedora LVM Cache for Intel Optane SSD

Fedora LVM Cache for Intel Optane

Did you know that LVM has built-in support for Intel Optane? Neither did I. It's a manual configuration though and it doesn't seem to be easy to do with BTRFS, so I simply went for EXT4.

Why would you want to enable the Optane cache? It supports super low latency no matter how much you use it while the big NVMe SSD is going to get slower the busier it is.

Note: I'm talking about laptop NVMe SSDs with built-in Optane cache. Mine is a Intel® Optane™ Memory H10 32GB + Intel® QLC 3D NAND SSD 512GB, M.2 80mm PCIe 3.0, which came pre-installed in my HP Spectre x360.

To start:

  1. Enter the UEFI and turn on ACHI for the SSD (I don't know if I did it as I forgot my UEFI password)
  2. Wipe the SSD if you don't have LVM already (I had BTRFS).
  3. Install Fedora with LVM on the main SSD (don't touch the 32 GB Optane cache yet).
    • I removed the /home partition so everything is in /root. I'm pretty sure my SSD won't not run out of space.
  4. ✅ Feel free to enable 🔒encryption/LUKS for the LVM, it'll still work as usual.
  5. Once the installation is done restart and wipe the Optane cache of 32 GB.
    • This can be a bit tricky but it's possible due to "device being busy". I used some wipefs command I think to make it sparkly clean.
  6. Then continue with the rest of this guide that I found.

Considerations

  • If you're a heavy Firefox user like me then maybe you want to create an extra 1 GB partition on the Optane just for the Firefox cache. I forgot to do that and am to lazy to redo everything, which you can. You can delete and add the LVM cache back as often as you'd like.
  • My laptop doesn't like hibernation, but if yours does then you might want a swap on the Optane too.
  • While you're wiping your NVMe SSD you might want to check if you can switch it to 4K: https://bbs.archlinux.org/viewtopic.php?id=289806
  • I backed up my home directory with Pika Backup. It was a bit hard to find the restore button, but it's there, somewhere.

Setting up LVM Cache

From the man-pages: "The cache logical volume type uses a small and fast LV to improve the performance of a large and slow LV. It does this by storing the frequently used blocks on the faster LV. LVM refers to the small fast LV as a cache pool LV. The large slow LV is called the origin LV. Due to requirements from dm-cache (the kernel driver), LVM further splits the cache pool LV into two devices - the cache data LV and cache metadata LV. The cache data LV is where copies of data blocks are kept from the origin LV to increase speed. The cache metadata LV holds the accounting information that specifies where data blocks are stored (e.g. on the origin LV or on the cache data LV). Users should be familiar with these LVs if they wish to create the best and most robust cached logical volumes. All of these associated LVs must be in the same VG."

Assuming LVM is already setup in SSD (e.g. from anaconda) and Optane is wiped.

Create a physical volume for the Optane

# pvcreate /dev/nvmeXn1

e.g. pvcreate /dev/nvme1n1, nvme1n1 being the Optane cache.

Extend your existing volume group to include the Optane

# vgextend VOLUME_GROUP /dev/nvmeXn1

anaconda names the volume group as fedora_HOSTNAME or just fedora.

Create a cache metadata LV

# lvcreate -n meta -L YMB VOLUME_GROUP /dev/nvmeXn1

Where Y is 1000 times smaller than the cache data LV, with a minimum of 8MB. e.g. if you have a 32 GB Optane, Y = 32MB.

Create a cache data LV

# lvcreate -n cache -l Z VOLUME_GROUP /dev/nvmeXn1

Where Z is the size of your cache. Use 100%FREE to use the remaining free space in the physical volume.

Note: 100%FREE didn't work for me, I got some random error (something about 8 or 30 bytes missing), so I used 99%FREE instead.

Create the cache pool LV

# lvconvert --type cache-pool --cachemode writeback --poolmetadata VOLUME_GROUP/meta VOLUME_GROUP/cache

This combines the cache data and metadata into a cache pool that uses writeback mode. Ommitting defaults to writethrough, which stores data in the cache and on the origin LV.

Create the cache

# lvconvert --type cache --cachepool VOLUME_GROUP/cache VOLUME_GROUP/root

The pool is then converted into a cache for the root partition.

Rebuild initramfs

# dracut -v -f

This will rebuild the initramfs to include the cache LV.

Sources and further info:

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/lvm_cache_volume_creation.html

http://man7.org/linux/man-pages/man7/lvmcache.7.html

Thanks to @ntn888 for the cachemode suggestion and @Yeshey for the 100%FREE option.

Congrats!

You now have a fully working Intel Optane drive on Fedora using just LVM! I guess there's a reason for why Intel never released any special software for Linux - it's not needed!

You can check the cache status with lvdisplay -m. Don't worry about dirty blocks - the Optane cache is not going to break before the SSD. Here are my stats right now:

Cache used blocks      99.99%
Cache metadata blocks  16.25%
Cache dirty blocks     0.15%
Cache read hits/misses 43970610 / 6949457
Cache wrt hits/misses  63179751 / 8528210
Cache demotions        33962
Cache promotions       33961
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment