16

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.

nedm
  • 5,610
  • 5
  • 30
  • 52

1 Answers1

13

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
Nowaker
  • 281
  • 3
  • 10
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • 1
    So if I understand you correctly, if mounting with discard works, then fstrim should as well? – nedm May 16 '13 at 22:59
  • 1
    Correct. If it's fully implemented all the way down, then it will work either way. – Michael Hampton May 16 '13 at 23:02
  • 3
    Remember to change the mount options afterward, if you don't intend to do automatic TRIM. :) – Michael Hampton May 16 '13 at 23:04
  • 2
    For the record, TRIM support for RAID1 was added on October 11 2012, see here http://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 08 '14 at 16:00
  • Any idea if this is backported in precise or trusty? Is the only way to find out to try it? – Jonathan S. Fisher Apr 21 '14 at 03:50
  • 3
    @MichaelHampton that is unfortunately not true. For example, having kernel 3.2, with ext4 on LVM on MD(soft) RAID1, (re)mounting ext4 with discard won't report error, but won't work either (as MD RAID1 in 3.2.x kernels don't support passing down of TRIM commands). So only way to know for sure is to [test it](https://clusterbuffer.wordpress.com/2011/10/02/how-do-you-know-trim-is-working-with-your-ssd-in-your-system/) – Matija Nalis Dec 03 '14 at 00:33