Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm currently building a new Ubuntu 13.04 server with 2 256GB SSDs in a raid mirror to run a MariaDB instance. We typically place LVM on top of dm-crypt encryption on top of an md raid 1 array, but haven't used SSDs in this setup previously.

My question is, since we'll be using a newer (3.8) kernel, it should allow fstrim to be applied to the raid volume directly as I understand it. Can I now simply rely on this to work properly with fstrim -v / via a cron job, just as I would if the raid wasn't in place? Is this true even with LVM on top of the raid volume? We plan to use the hardware encryption present on the drives, so we won't need dm-crypt here.

NOTE: I'm aware that there are several similar questions involving backporting updated kernel versions and implementing discard with the md volume -- I'm asking specifically if fstrim works against md-raid without further modification in newer kernels.

UPDATE: Just wanted to follow up and post that this worked fine. There's now a job in cron.daily that runs fstrim on / and /boot and it's working perfectly. Also, it turned out the hardware encryption on the SSDs (Samsung 840 Pros) appears to require TPM support, which we don't have, so we did configure with software encryption as shown in the link. By adding discard to the options in /etc/crypttab (not to /etc/fstab) and issue_discards = 1 to the devices section of /etc/lvm/lvm.conf, fstrim works fine even through LVM, encryption, and RAID layers. More info about configuring for trim/discard on SSDs with LVM and encryption is available here.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Patches for mdraid RAID 1 and 10 support for TRIM went up about a year ago.

You can test your kernel's support by mounting the filesystem with the discard option (which enables automatic TRIM). If it is supported, you'll see a message in syslog or dmesg like the following:

EXT4-fs (md1): re-mounted. Opts: discard,data=ordered

Otherwise you would get this:

EXT4-fs warning (device md1): ext4_issue_discard:2619: discard not supported, disabling

You don't need to reboot to see if it's working:

mount /dir -o remount
share|improve this answer
    
So if I understand you correctly, if mounting with discard works, then fstrim should as well? –  nedm May 16 '13 at 22:59
    
Correct. If it's fully implemented all the way down, then it will work either way. –  Michael Hampton May 16 '13 at 23:02
    
Perfect, thanks. –  nedm May 16 '13 at 23:04
1  
Remember to change the mount options afterward, if you don't intend to do automatic TRIM. :) –  Michael Hampton May 16 '13 at 23:04
1  
For the record, TRIM support for RAID1 was added on October 11 2012, see here lkml.indiana.edu/hypermail/linux/kernel/1203.1/01772.html So kernel 3.4 doesn't support it but 3.8 does (don't know about 3.5/3.6/3.7) –  Joril Jan 8 at 16:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.