SSD fstrim on CentOS 6.x with software raid5

Nick asked:

I have some CentOS 6.x servers. They have software raid1 and fstrim works well there.

On one of the servers, I decided to do software raid5 and ext4. I can mount it with discard and there is no error message.

However if I decide to run fstrim, I get this:

[[email protected] ~]#  fstrim /        <- (raid1 works well)
[[email protected] ~]#  fstrim /SSD     <- (raid5 does not work)
fstrim: /SSD: FITRIM ioctl failed: Operation not supported
[[email protected] ~]# uname -a
Linux server 2.6.32-573.12.1.el6.x86_64 #1 SMP Tue Dec 15 21:19:08 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

The disk supports trim and there is raid1 made with same disks.

Is this because RedHat did not backported something into the kernel or I am doing something wrong?

My answer:

mdraid support for discard on RAID 5 wasn’t available in the 2.6 kernel series; it was added in the 3.7 kernel. I’m not aware of Red Hat backporting this functionality.

Once you get a kernel with this functionality, you may find that it is disabled, because some (older) SSDs don’t actually implement TRIM properly. In this case, you need to set the kernel module option raid456.devices_handle_discard_safely=Y and then test thoroughly before putting the system into production.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.