Should you trim external SSDs?

Trim, which isn’t an abbreviation but is often set in capitals, is a command that can be sent to some types of storage including SSDs to tell them to perform housekeeping. About ten years ago, when SSDs were relatively novel, trim was one of their big issues. Since 2015, it has faded, and now most who use SSDs don’t know whether they are trimmed, or whether they should be. While I’d dearly love to cast some light on this important topic, all I can do is explain what we don’t know.

Why trim?

On any storage medium, the file system normally deletes files by marking their storage blocks as being no longer in use. When re-using those blocks for new files only requires that they are rewritten, as on a hard disk, that’s not a problem, as the disk controller can choose to reuse them whenever it wants without any side effects.

However, before NAND flash memory cells used in SSDs can be re-used for writing, their contents must be erased, a process that makes writing to them significantly slower. This is complicated by the fact that data is written in pages of 4-16 kB, but erase commands always affect complete blocks, typically consisting of 128-512 pages. This is commonly addressed by relocating any other retained data within the block, so enabling that block to be erased ready to receive the new data.

To avoid incurring such overhead, the operating system can maintain a list of blocks that are no longer in use, and once a block becomes unused, it can inform the SSD’s firmware that the block can now be re-used. This allows the SSD controller to erase that block, and maintains good write performance even under heavy use with limited free space. That’s what the TRIM command does for SATA SSDs, and why it’s often set in capitals.

This is different from wear levelling, performed to ensure that erase cycles are evenly distributed across all the blocks in the SSD. That’s normally performed by the SSD’s inbuilt controller, and isn’t managed in any way by the file system or operating system.

Trim support

Operating systems, including macOS, gained support for the TRIM command around 2010, but this has proved complex and varies by type of SSD, and by file system. While generally available for software RAID systems, but not in AppleRAID, the TRIM command is normally not supported by hardware RAID systems.

Enabling the TRIM command doesn’t automatically improve performance, and in some circumstances can instead impair performance. In early releases of APFS, some users who manually enabled TRIM reported longer boot times, generally attributed to TRIM commands being sent to the SSD during the boot process, although I’m not aware of any good evidence to support that. In practice, it shouldn’t be hard to detect poor write performance on an SSD that could be addressed by enabling trimming. I have yet to see any reports that external SSDs in APFS format need the TRIM command to be enabled because write performance has deteriorated, although in the past the default in macOS has been to disable trim support for external SSDs.

Most accounts of trim and its support are now getting old, dating from 2010-2015, and don’t refer to file systems such as APFS that are optimised to work with SSDs. I’ve been unable to find any recent recommendation from Apple or a similarly authoritative source that trim support should be enabled on external SSDs running the current version of APFS. Not only that, but over that period, Macs have moved away from SATA internal SSDs, and now use NVMe, where the TRIM command doesn’t exist, and DEALLOCATE is its closest substitute.

macOS does include a command tool that in the past could enable the use of the TRIM command to external SSDs, trimforce. For example, you can use
sudo trimforce enable
then restart your Mac for it to take effect on all external SSDs. But its man page warns: “Use extreme caution when enabling TRIM, as some drives may not correctly handle the commands” and hasn’t been updated since 2015, before Apple released APFS. There doesn’t appear to be any way to discover whether the TRIM command is enabled, as all trimforce can do is enable and disable it. More recently, some have claimed that this command no longer works anyway.

Not only is there no way of telling whether the TRIM command is enabled, but Macs may tell you that TRIM isn’t supported on many SSDs whose manufacturers claim that they do support it. I have an array of four Samsung 860 EVO SSDs in a ThunderBay 4 enclosure, each of which macOS reports as not supporting TRIM, although Samsung insists that all its SSDs support it. There’s also doubt over whether Macs can send a TRIM command to any SSD, SATA or NVMe, connected via USB rather than Thunderbolt.

APFS

Apple has still released very limited information about APFS, and its latest reference manual doesn’t even mention trim or TRIM/DEALLOCATE commands.

Two important features of APFS are its Space Manager (Spaceman) and the Reaper. Spaceman is responsible for allocating and freeing blocks to store file system objects and file data. Each APFS container has just one Spaceman, which has to manage all space within that container, for as many volumes as share that space. The Reaper is the mechanism by which APFS deletes large objects requiring multiple transactions within the file system. There’s only one Reaper for each APFS container, and it’s thought to be responsible for cleaning up deleted snapshots, for example.

Recently, when I’ve been looking at how macOS mounts APFS volumes in disk images and Thunderbolt SSDs, I’ve discovered that Spaceman scans for free blocks and trims APFS containers when they’re mounted.

Summary

  • Trimming SSDs was a hot topic in 2010-15, and considered important for maintaining good write performance with efficient use of storage life.
  • There is no documented need or use for trimming SSDs formatted in APFS.
  • The trimforce command is inadequate, and may not work any more.
  • Many SSDs claimed by the manufacturer to have TRIM command support are reported by macOS as not having TRIM support.
  • APFS appears to automatically perform trimming on at least some SSDs when they’re mounted.
  • Although I suspect that enabling trimming is no longer necessary for SSDs using APFS, there is no documentation that we can rely on to establish whether it might still be required.

If you know any better, then please let us know.

References

Wikipedia on TRIM