Trim support on the Argon M.2

I have a couple Argon One M.2 v.1 (with micro hdmi ports) cases and they lacked trim support with my Kingston A400 SSDs. A little google-foo turned up some good links, here, here and the firmware from here.

After working through the links, I managed to get trim support working. However, on reboot, the discard_max_bytes kept being set to the same value as discard_max_hw_bytes and I would get an error when attempting to run fstrim -v /.

fstrim: /: FITRIM ioctl failed: Remote I/O error

So I modified the suggested udev rule which resolves the issue:

#For some reason this rule does not work... so second runs a command
#KERNEL=="sda", SUBSYSTEM=="block", ATTR{queue/discard_max_bytes}="2147450880"

KERNEL=="sda", SUBSYSTEM=="block", RUN+="/bin/sh -c 'echo 2147450880 > /sys/block/sda/queue/discard_max_bytes'"
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"

Anyone know why the first rule does not work?

Edit: It appears the newer M.2 does have a version of firmware that supports trim but you still need to configure it.

Edit 2: The same value ( 2147450880 ) is used with the Samsung 860 EVO M.2 SATA

1 Like

More fun with udev:

KERNEL=="sda", SUBSYSTEM=="block", ATTR{queue/discard_max_bytes}="2147450880", RUN+="/bin/sh -c 'cat /sys/block/sda/queue/discard_max_bytes'"

Interestingly, this works. Somehow, adding the RUN “causes” the value to be set? Riddle me that Batman.

I’ve spent days trying to get this to work, Thank you so much for this!

Just a slightly more generic version, I use both USB3 ports on the Pi for storage, so this targets the argon40 specifically, otherwise it sometimes tries to apply the discard_max_bytes to my hard drive.

I hope you don’t mind, I’m going to mention this post elsewhere I found bad advice on this topic. I have a feeling a lot of people think they have trim when really they don’t, because discard_max_bytes is not persistent.

ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="block", KERNEL=="sd?", ATTR{queue/discard_max_bytes}="2147450880", RUN+="/bin/sh -c 'cat /sys/block/$kernel/queue/discard_max_bytes'"
1 Like
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="block", ATTR{queue/discard_max_bytes}="2147450880", RUN+="/bin/sh -c 'cat /sys/block/$kernel/queue/discard_max_bytes'"

To be even more generic I removed the KERNEL=sd?, now it applies to downstream LVM and crypto devices too.

I tested both of your suggestions, but they do not work for my setup. I get errors when I run sudo fstrim -v / manually.

If I recall correctly, with the first set of changes, I get

fstrim: /: FITRIM ioctl failed: Remote I/O error

And with the second, I believe the error was discard is not supported.