We use RAID1+0 with md on Linux (currently 2.6.37) to create an md device, then use LVM to provide volume management on top of the device, and then use ext4 as our filesystem on the LVM volume groups.
With SSDs as the drives, we'd like to see the TRIM commands propagate through the layers (ext4 -> LVM -> md -> SSD) to the devices.
It looks like recent 2.6.3x kernels have had a lot of new SSD-related TRIM support added, including lots more coverage of Device Mapper scenarios, but we still can't seem to get it to cascade down properly.
Is this possible yet? If so, how? If not, is any progress being made?
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:
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:
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?).
Mdtrim may need more working:
As a summary, here are current recommended settings for performance and data safety on Linux.
Because of some bugs/risks, Debian does not enable LVM discard by default: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=717313
Gentoo Wiki proposes a one-time sequence to discard blocks in VG free space (as root):
About filesystems, it is recommended not to enable
discard
mount option in/etc/fstab
but to only enable fstrim.timer generally provided in systemd-based distributions.Underlying layers like software raid should handle/forward discard/trim events from FS or LVM.
You can use my MDTRIM script ( https://github.com/Cyberax/mdtrim/ ) to TRIM empty space on ext4/3 level-1 RAIDs. We start it periodically from cron and it works great for us.
Adding support for other RAID levels is possible, but I don't have time (or need) for that.
As suggested here You can use
in order to check if your blockdevices pass through the discard commands.
Also note that the section devices in lvm.conf contains an option issue_discards. See
for more info.