How to configure a filesystem+LVM for effective usage of SSD

configurationext4lvmperformancessd

ext4 is one of the filesystems recommended for using on SSDs (with a number of built-in techniques and advices how to tune it for better performance and wear-levelling of SSDs).

I want to install a Linux system onto an SSD, and I'm going to use ext4, because it is the better tested FS (I don't want to use the more experimetal btrfs).

But what if I add LVM between ext4 and SSD? Will the performance and wear-levelling tweaks for ext4 loose their effect? (Because LVM would hide the actual disk layout from the FS.) Can LVM be configured so that it will use the SSD features effectively?

(I want to use LVM to able to have snapshots of older states of the system, as well as for more flexibility with the sizes of the partitions.)

Best Answer

The main issue here is the alignment. You want the filesystem blocks to be aligned with the SSD erase blocks so that sectors aren't unnecessarily erased. When adding LVM into the mix you just need to ensure that the alignment stays intact. By default LVM will align data on PVs on 64KiB boundaries -- if your SSD's erase block size is bigger than that you want to use the --dataalignment option to pvcreate to specify that. (Note that if you're using an MBR/GPT partition under the PVs you also need to address alignment there.)

According to this ServerFault question, TRIM works correctly through ext4+LVM+mdraid as of Linux 2.6.38.

Related Question