Possible to get SSD TRIM (discard) working on ext4 + LVM + software RAID in Linux?

Solution 1:

As of 2.6.37, it should be present (source). The kernel doesn't do it in the background, the block discard process is currently designed to be run on demand (cron script!). Dm-crypt support doesn't exist yet.

On January 13th, 2011 a patch was merged into dm-raid1.c that reads:

dm raid1: support discard

Enable discard support in the DM mirror target.
Also change an existing use of 'bvec' to 'addr' in the union.

I'm not 100%, but I think that's the merge-window for 2.6.38.

EXT4 added support a while ago, as did LVM. RAID is the one key that doesn't have support. As of 1/13/2011, it appears support has been added. Look for it in 2.6.38 or maybe 2.6.39.


Time has passed and TRIM support is definitely included in the 3.7 kernel. The commit for RAID10 reads:

This makes md raid 10 support TRIM. If one disk supports discard and another not, or one has discard_zero_data and another not, there could be inconsistent between data from such disks. But this should not matter, discarded data is useless. This will add extra copy in rebuild though.

Solution 2:

UPD. 2020-06-17

Looking back through commits history from 2020:

  • 2010-08: Allow discards to be passed through to linear mappings if at least one underlying device supports it.

2 years later there're commits in regards for md (LSR), the one among them:

  • 2012-10: md: raid 10 supports TRIM

— Basically in a few months since I edited my answer previously, Linux kernel became able to support block discards in the setup.


Previous versions of the answer:

UPD. 2012-07-17 UPD.: Thanks to Wodin for letting me know — according to lkml.org/lkml/2012/3/11/261 this functional has been addedproposed recently. proposed != accepted, though.

UPD. 2011-02-01 Not possible, cause Linux Soft RAID doesn't support this (yet?).