What is TRIM and how does it work?

These days, solid-state drives have become a popular choice with many computer users and equipment manufacturers. And it’s hardly surprising, given their accelerated speeds, greater durability and much more compact sizing. In addition, as the prices are coming down and larger capacities become available, the ubiquity of SSDs will probably be increasing. Yet, with all the advantages they have over rotating platter hard disks, solid-state devices have some crucial specifics not everybody is familiar with. Apart from the underlying technology, the TRIM command is something that distinguishes them from their mechanical counterparts. So, if you own an SSD or are planning to get it when upgrading your hardware, TRIM is one of the basic terms you should know about. This guide will help you to understand what it means and why it matters.

Last update: June 21, 2023

Time to read: 7 min

What is TRIM?

In order to explain the purpose of this command, it is necessary to start with the comparison of the ways how solid-state and mechanical disk drives behave during files’ deletion. First of all, when a file is removed, whether from an SSD or HDD, the particular file system applied on this device marks the corresponding storage space as being no longer in use and gets rid of the reference to that file. This allows it to reuse the released space for other files. A traditional hard disk drive is able to overwrite such areas straightaway whenever the new data comes in. However, this doesn’t work like that in case of solid-state flash memory.

A solid-state drive consists of flash memory cells that can be written to only when they are physically empty. Thus, it must either use new cells or, with the lack thereof, erase the old data before a write operation will be initiated. The cells themselves are grouped into pages of 4-16 KB, while 128 pages together constitute a block. A write operation can be done to an individual page, but erasure will always affect the whole block due to certain flash memory characteristics. Therefore, an SSD must flush the content of that block to the cache, wipe it out on the medium, replace the data in the pages from the cache that are intended for deletion and then restore the updated block to a new location. With so many steps to complete, writes becomes significantly slower than when dealing with initially unoccupied pages. So, from this perspective, it would be reasonable to prepare those memory cells for writing in advance. But the problem is that, by definition, a drive is not aware that they contain irrelevant information until the file system decides to use them. And that’s where TRIM comes into play.

TRIM is a special command that is sent by the operating system to an SSD upon the deletion of a file or formatting of a partition. It lets the drive’s controller to physically clear the blocks that still store deleted files and make them ready to receive new data. This is done by a separate process called Active Garbage Collection during idle time: it will copy all the valid data from the block and write it to empty pages of another block, so that the block in question could be cleaned out. Such an approach allows speeding up future writes and helps the drive to function optimally. Also, it reduces the amount of unnecessary writing, extending the drive's longevity.

It must be noted that the data doesn’t get erased immediately the second such a command is sent. Nevertheless, this may happen anytime, depending on various factors, for instance, when the drive is not busy or when the next write occurs. Also, SSD controllers tend to report the pending blocks as empty once they receive TRIM, even despite them being not wiped yet.

TRIM is in fact an ATA command for Serial ATA (SATA) SSDs, but it also has some analogs for other SSD interfaces, like UNMAP for SCSI and SAS drives, or DEALLOCATE for PCI Express NVMe drives.

How does it get activated on a device?

As a rule, TRIM is issued automatically by the operating system and doesn’t require any user’s interaction. However, the command is actually not mandatory. For it to function as expected, all of the following conditions must be met:

  • The solid state drive's firmware supports TRIM

Most modern SSDs introduced since 2010 are designed to support this operation. Yet, some older-generation drives may need firmware updates to implement it or even be unable to use it all. The manufacturer should provide this information in the technical specifications of the respective digital medium.

  • The computer’s OS supports TRIM

The major operating systems gained the support for TRIM around the year 2010. On PCs, TRIM is supported in Windows 7 and later. On macOS, starting from version 10.6 Snow Leopard, TRIM is available exclusively for the Apple’s own branded SSD. With the release of macOS version 10.10.4 Yosemite, the command became supported for third-party solid-state drives, but, in this case, it requires manual activation. Linux supports TRIM as well, however, it may be disabled by default in some distributions.

Despite that, not every file system appears to be compatible. For example, Windows offers TRIM for NTFS and ReFS, but doesn’t provide it for FAT32 and exFAT. Under Linux, TRIM works with ext4, Btrfs, F2FS, XFS, JFS and some other file systems.

  • The interface between the computer and SSD supports TRIM

Even when both the SSD and the OS are TRIM-aware, the physical bus between them may not support sending that command. While fully supported over the SATA interface (including eSATA), TRIM will usually not pass through when such a drive is connected externally via USB, FireWire, Thunderbolt, etc. At the same time, there are some high-end external enclosures and USB to SATA adapters that support TRIM-like commands via the USB Attached SCSI Protocol (UASP).

  • The configuration the drive belongs to is supported for TRIM

With rare exceptions, TRIM cannot be performed for member drives of most RAID configurations and certain types of composite volumes, like Windows Dynamic Disks and Apple Software RAID. The same applies to some NAS appliances.

TRIM in the context of data recovery

Though TRIM is beneficial for SSD performance, the same cannot be said when it comes to the recovery of deleted or formatted data. The content of files subjected to TRIM gets permanently destroyed and thus no longer exists on the storage. This makes them unrecoverable by whichever automated or manual technique. Even if the respective blocks were put on the waiting list to be wiped later, the SSD controller is likely to return zeros or random "garbage" when any software requests them. The only possibility to undelete the data on an SSD with enabled TRIM is left when the command hasn’t been actually carried out. Such instances are very seldom, but do take place from time to time due to the following reasons:

  • TRIM is not supported on one of the "levels"

As has been pointed out, TRIM is a feature that has to be supported by the storage medium, the operating system that controls it, the chosen file system and the interface employed to plug it in. When any link is missing from this chain, TRIM cannot be executed and, consequently, the data remains retrievable. A typical example of such a situation is when a file is deleted from an SSD attached via a USB port.

  • Corrupted data

When the key elements of the drive’s logical structure get damaged (the file system, partition table, etc.), the data may become inaccessible for both the user and the OS. Although it gets lost de facto, the operating system may not consider it to be deleted in the absence of a proper deletion operation and, as a result, will not send the TRIM command.

  • Sudden disconnection or power loss

When the drive loses power or gets disconnected immediately after deletion, the OS may not have enough time to accomplish TRIM, so the data may be left untouched.

  • Flawed SSD firmware

Firmware used in solid-state drives is not always perfect, especially in low-end models. The errors it contains may sometimes obstruct certain processes, including TRIM and Garbage Collection. In this case, the original data may still be present even after its deletion.