In computing, a TRIM command allows an operating system to inform a solid-state drive (SSD) which blocks of data are no longer considered in use and can be wiped internally. While TRIM is frequently spelled in capital letters, it is a command name, not an acronym.
TRIM was introduced soon after SSDs started to become an affordable alternative to traditional hard disks. Because low-level operation of SSDs differs significantly from hard drives, the typical way in which operating systems handle operations like deletes and formats resulted in unanticipated progressive performance degradation of write operations on SSDs. TRIM enables the SSD to handle garbage collection overhead, which would otherwise significantly slow down future write operations to the involved blocks, in advance.
Although tools to "reset" some drives to a fresh state were already available before the introduction of TRIM, they also delete all data on the drive, which makes them impractical to use for ongoing optimization. More recent SSDs will often contain internal idle/background garbage collection mechanisms that work independently of TRIM; although this successfully maintains their performance even under operating systems that do not (yet) support TRIM, it has the associated drawbacks of increased write amplification and wear of the flash cells.
Flash drive specific issues
Because of the way that file systems typically handle delete operations, storage media (SSDs, but also traditional hard drives) generally do not know which sectors/pages are truly in use and which can be considered free space. Delete operations are typically limited to flagging data blocks as "not in use" in the file system. Contrary to, for example, an overwrite operation, a delete will therefore not involve a physical write to the sectors that contain the data. Since a common SSD has no access to the file system structures, including the list of unused clusters, the storage medium remains unaware that the blocks have become available. While this often enables undelete tools to recover files from traditional hard disks, despite the files being reported as "deleted" by the operating system, it also means that when the operating system later performs a write operation to one of the sectors, which it considers free space, it effectively becomes an overwrite operation from the point of view of the storage medium. For traditional hard disks this is no different than writing an empty sector, but because of how some SSDs function at the lowest level, an overwrite produces significant overhead compared to writing data into an empty page, potentially crippling write performance.
SSDs store data in flash memory cells that are grouped into pages, with the pages (typically 4 kB each) grouped together into blocks (typically 128 pages per block, totaling 512 kB). NAND flash memory cells can only be directly written to when they are empty. If they are considered to contain data, the contents first need to be erased before a write operation can be performed reliably. In SSDs, a write operation can be done on the page-level, but due to hardware limitations, erase commands always affect entire blocks. As a result, writing data to SSD media is very fast as long as empty pages can be used, but slows down considerably once previously written pages need to be overwritten. Since an erase of the cells in the page is needed before it can be written again, but only entire blocks can be erased, an overwrite will initiate a read-erase-modify-write cycle: the contents of the entire block have to be stored in cache before it is effectively erased on the flash medium, then the overwritten page is modified in the cache so the cached block is up to date, and only then is the entire block (with updated page) written to the flash medium. This phenomenon is known as write amplification.
The TRIM command is designed to enable the operating system to notify the SSD which pages no longer contain valid data due to erases either by the user or operating system itself. During a delete operation, the OS will both mark the sectors as free for new data and send a TRIM command to the SSD to be marked as no longer valid. After that the SSD knows not to relocate data from the affected LBAs during garbage collection. This results in fewer writes to the flash, reducing write amplification and increasing drive life.
TRIM irreversibly deletes the data it affects.
- When software-based disk encryption is in use, using the TRIM command reveals information about which blocks are in use and which are not.
- TRIM has been defined as a non-queued command by the T13 subcommittee, and consequently incurs massive execution penalty if used carelessly, e.g., if sent after each filesystem delete command. The non-queued nature of the command requires the driver to first finish any operation, issue the TRIM command, then resume normal commands. TRIM can take a lot of time to complete depending on the firmware in the SSD and may even trigger a garbage collection (GC) cycle. This penalty can be minimized in solutions that periodically do a batched TRIM, rather than TRIMming upon every file deletion, by scheduling such batch jobs for times when system utilization is minimal. This TRIM shortcoming has been overcome in Serial ATA revision 3.1 with the introduction of the Queued Trim Command.
Operating system support
TRIM is only effective on operating systems which support it. The table below identifies each notable operating system and the first version supporting the command. Additionally, older solid-state drives designed before the addition of the TRIM command to the ATA standard will need firmware updates, otherwise the new command will be ignored. However, not every drive can be upgraded to support Trimming.
|Operating System||Supported since||Notes|
|DragonFly BSD||May 2011|
|FreeBSD||8.1 - July 2010||Support was added at the block device layer in 8.1. Filesystem support was added in FreeBSD 8.3 and FreeBSD 9, beginning with UFS. ZFS obtained TRIM support with FreeBSD 9.1-STABLE. FreeBSD 10 will support TRIM on ZFS as well as on software RAID configurations.|
|Linux-kernel||2.6.28–25 December 2008||Initial support for discard operations was added for FTL NAND flash devices in 2.6.28. Support for the ATA TRIM command was added in 2.6.33.
Not all filesystems make use of TRIM. Among the filesystems that can issue TRIM requests automatically are Ext4, Btrfs, FAT, GFS2 and XFS. However, this is disabled by default due to performance concerns, but can be enabled by setting the "discard" mount option. Ext3, NILFS2 and OCFS2 offer ioctls to perform offline trimming. The TRIM specification calls for supporting a list of trim ranges, but as of kernel 3.0 trim is only invoked with a single range that is slower.
|Mac OS X||10.6.8–23 June 2011||Although the AHCI block device driver gained the ability to display whether a device supports the TRIM operation in 10.6.6 (10J3210), the functionality itself remained inaccessible until 10.6.8, when the TRIM operation was exposed via the IOStorageFamily and filesystem (HFS+) support was added.
Only enabled for Apple-supplied SSDs. TRIM can be enabled for other SSDs by modifying a kernel extension.
|Microsoft Windows||NT 6.1 (Windows 7 and Windows Server 2008 R2) - October 2009||Windows 7 only supports TRIM for ordinary (AHCI) drives and does not support this command for PCI-Express SSDs that are different type of device, even if the device itself would accept the command.|
The RST (Rapid Storage Technology Option Rom ) and drivers are only allowing TRIM to pass to the controller onto the drive in Intel 7 series chipsets using driver versions post 126.96.36.199. For Intel chipsets such as the 6 series and the newest X79, a modded ( Option Rom ) must be used on these chipsets to allow TRIM to be received at the drive. The exception to X79 chipset is if the Motherboard MFG has added Rom switch, this entails both the RST and RST-E Roms are inside the BIOS/UEFI, this allows the RST Rom to be used, allowing TRIM to fuction, as TRIM does not work on the RST-E Rom.  Official response from Intel,  Best performance is to use a driver with same version as Rom, if BIOS/UEFI has a 188.8.131.52m Option Rom, then use a 11. version driver.
As of January 2012[update], support for the TRIM command has not been implemented in most RAID technologies. One case where it has been implemented is in post-January-2011 releases of the Linux kernel's dmraid, which implements BIOS-assisted "fake hardware RAID" support, and now passes through any TRIM requests from the filesystem that sits on the RAID array. Not to be confused with dmraid, Linux's general-purpose software RAID system, mdraid, has experimental support for batch-based (rather than live, upon file deletion), TRIM on RAID 1 arrays when systems are configured to periodically run the mdtrim utility on filesystems (even those like ext3 without native TRIM support). For a short time in March 2010, users were led to believe that the Intel Rapid Storage Technology (RST) 9.6 drivers supported TRIM in RAID volumes, but Intel later clarified that TRIM was supported for the BIOS settings of AHCI mode and RAID mode, but not if the drive was part of a RAID volume.
As of November 2011, Intel has indicated in the release notes for RST 11.5 Alpha that they intend to add support for TRIM on RAID 0 volumes in the next version of RST. Red Hat has also recommended against using software RAID levels 1, 4, 5, and 6 on SSDs, because during initialization, most RAID management utilities (e.g. Linux's mdadm) write to all blocks on the devices to ensure that checksums (or drive-to-drive verifies, in the case of RAID 1) operate properly, causing the SSD to believe that all blocks other than in the spare area are in use, significantly degrading performance.
As of August 2012, Intel confirms that 7-series chipsets with Rapid Storage Technology (RST) 11.2 drivers will support TRIM for RAID 0 in Microsoft Windows 7. While Intel did not confirm support for 6-series chipsets, TRIM on RAID 0 volumes as been shown to work on Z68 and P67 chipsets by hardware enthusiasts with a modified RAID option ROM. It is speculated that the lack of official support for 6-series chipsets is due to validation costs or an attempt to encourage consumers to upgrade, rather than for technical reasons.
Enabling unsupported operating systems
Where TRIM is not automatically supported by the filesystem, there are utilities which can send TRIM commands manually. Usually they determine which blocks are free and then pass this list as a series of TRIM commands to the drive. These utilities are available from various manufacturers (Intel, G.Skill) or as general utilities (hdparm since v9.17).
The TRIM command specification is being standardized as part of the AT Attachment (ATA) interface standard, led by Technical Committee T13 of the International Committee for Information Technology Standards (INCITS). TRIM is implemented under the DATA SET MANAGEMENT command (opcode 06h) the draft ACS-2 specification.
A drawback of the original ATA TRIM command is that it was defined as a non-queueable command and therefore could not easily be mixed with a normal workload of queued read and write operations. SATA 3.1 introduced a queued TRIM command to remedy this.
There are different types of TRIM, defined by SATA Words returned from an ATA IDENTIFY DEVICE command.
Non-deterministic TRIM: each read command to the LBA after a TRIM may return different data. (SATA Word 169 bit 0)
Deterministic TRIM (DRAT): all read commands to the LBA after a TRIM shall return the same data, or become determinate. (SATA Word 69 bit 14)
Deterministic Read Zero after TRIM (DZAT): all read commands to the LBA after a TRIM shall return zero. (SATA Word 69 bit 5)
There is additional information in SATA Word 105 that describes the Maximum number of 512-byte blocks per DATA SET MANAGEMENT command that a drive can support. Typically this defaults to 8 (or 4k) but many drives reduce this to one to meet the Microsoft Windows Hardware Requirements for Trim, Command completion time shall not exceed 20ms or 8ms * (number of LBA range entries), whichever is greater, and shall always be less than 600ms. http://msdn.microsoft.com/en-us/library/windows/hardware/jj134356.aspx An individual LBA range is called an LBA Range Entry and is represented by eight bytes. The LBA is expressed by the LBA Range Entry's first six bytes and the Range Length is a zero based number (e.g., 0=0 and 1=1)represented by the remaining two bytes. If the two byte range length is zero, then the LBA Range Entry shall be discarded as padding.(need reference to T13 ATA/ATAPI Command Set - 3 (ACS-3)) This means that for each 512 byte block of TRIM ranges that a device supports, the maximum is 64 ranges of 32MB, or 2GB. If a device supports SATA Word 105 at 8 then it should be able to TRIM 16GB in a single TRIM (DATA SET MANAGEMENT) command.
The MultiMediaCard and SD ERASE (CMD38) command provides similar functionality to the ATA TRIM command, although it requires that erased blocks be overwritten with either zeroes or ones. eMMC 4.5 further defines a "discard" sub-operation that more closely matches ATA TRIM in that the contents of discarded blocks can be considered indeterminate (i.e., "don't care").
- Intel Corporation (2010-09-14). "Intel® High Performance Solid State Drive - Advantages of TRIM". Intel.com. Retrieved 2012-02-21.
- Shimpi, Anand Lal (2009-03-18). "The SSD Anthology". AnandTech.com. p. 4. Retrieved 2010-06-19.
- Shimpi, Anand Lal. (2009-03-18). p. 10.
- Shimpi, Anand Lal. (2009-03-18). p. 11.
- "Kingston SSDNow V Plus 100 Review". Anandtech. Anand Lal Shimpi. 2010-11-11. Retrieved 2010-12-10.
- Savill, John (2009-04-21). "I heard solid-state disks (SSDs) suffer from a decline in write performance as they're used. Why?". WindowsITPro. Retrieved 2010-06-19.
- Shimpi, Anand Lal. (2009-03-18). p. 7.
- Savill, John (2009-04-22). "What is the TRIM function for solid-state disks (SSDs) and why is it important?". WindowsITPro. Retrieved 2010-06-19.
- Malventano, Allyn (13 February 2009). "Long-term performance analysis of Intel Mainstream SSDs". PC Perspective. Retrieved 10 February 2012.
- Shimpi, Anand Lal. (2009-03-18). p. 5.
- Shimpi, Anand Lal. (2009-03-18). p. 8.
- "Write Amplification: Intel's Secret Sauce". ExtremeTech.com. Retrieved 2010-11-06.
- "Inside the X25-M Controller: Wear Leveling, Write Amplification Control". TomsHardware.com. 2008-09-08. Retrieved 2010-11-06.
- "Too TRIM? When SSD Data Recovery is Impossible". TechGage. TechGage. 2010-03-05. Retrieved 2010-04-16.
- "TrueCrypt - TRIM Operation". TrueCrypt.org. Retrieved 2010-11-06.
- "Preliminary TRIM support".
- "FreeBSD 8.1-RELEASE Release Notes: Disks and Storage". Retrieved 2010-09-01.
- "Add kernel side support for BIO_DELETE/TRIM on UFS". Retrieved 2011-02-01.
- "Added ZFS TRIM support which is enabled by default.". Retrieved 2013-06-05.
- "Base revision 240868 – Add TRIM support". Retrieved 2012-09-24.
- "Base revision 242323 – Add basic BIO_DELETE support to GEOM RAID class for all RAID levels". Retrieved 2012-10-30.
- "Block device changes in Linux 2.6.28".
- "Storage changes in Linux 2.6.33". Kernel Newbies. Retrieved 2010-09-01.
- HOWTO: Configure Ext4 to Enable TRIM Support for SSDs on Ubuntu and Other Distributions - Forked by Nicolay
- "Btrfs improvements in Linux 2.6.32".
- "Filesystem changes in Linux 2.6.30". Retrieved 2012-03-28.
- "Filesystem changes in Linux 3.0".
- Freemyer, Greg. "OpenSUSE forum - SSD detection when creating first time fstab".
- TRIM discussion in OpenSuSE website
- "Mac OS X 10.6.8 Brings TRIM Support for Apple SSDs, Graphics Improvements". 2012-02-24.
- "Macbook Pros ship with active SSD TRIM support". 2011-03-04.
- "Trim Enabler". Retrieved 2012-04-06.
- "Support and Q&A for Solid-State Drives". MSDN. 2009-05-09. Retrieved 2010-08-12].
- "Windows 7 Enhancements for Solid-State Drives". Microsoft downloads. Microsoft Corporation. 2008-11-12. Retrieved 2009-07-08.
- Geoff Gasior (2012) OCZ's RevoDrive 3 X2 240GB solid-state drive
- "SATA TRIM support in OpenSolaris". 2010-07-29.
- "Intel SSD Optimizer White Paper". Intel Corporation. Retrieved 2010-01-23.
- "Even Without Support for the TRIM Command, SSD Flies on Mac OS X". hardmac.com. Retrieved 2010-11-06.
- "Possible to get SSD TRIM (discard) working on ext4 + LVM + software RAID in Linux? - Server Fault". Retrieved 2011-11-29.
- "Cyberax/mdtrim - GitHub". Retrieved 2011-11-29.
- "Is there TRIM support for RAID configurations?". Intel. 2010-03-26. Retrieved 2010-11-06.
- "AnandTech - Intel to Add TRIM Support for RAID 0". 2011-11-21. Retrieved 2011-11-29.
- "Red Hat Enterprise Linux 6 Storage Administration Guide". 2011-12-02. Retrieved 2012-02-23.
- "Intel Confirms RAID0 TRIM Support on 7-Series Chipsets". 2012-08-19. Retrieved 2013-01-14.
- "RAID0 trim and SRT seems possible on 6-series and 5-Series". 2012-11-18. Retrieved 2013-01-14.
- "TRIM & RAID-0 SSD Arrays Work With Intel 6-Series Motherboards Too". 2012-11-28. Retrieved 2013-01-14.
- "Intel Brings TRIM to RAID-0 SSD Arrays on 7-Series Motherboards, We Test It". 2012-08-16. Retrieved 2013-01-14.
- "wiper.exe for Falcon Series". XtremeSystems. Retrieved 2010-01-23.
- "hdparm-9.17 released, with experimental trim/wiper scripts for SSDs". Retrieved 2010-08-14.
- "hdparm project page". sourceforge.net. Retrieved 2010-08-14.
- "Data Set Management Commands Proposal for ATA8-ACS2 (revision 6)". INCITS T13. INCITS. 2007-12-12. Retrieved 2009-07-08. (draft specification T13/e07154r6)
- "T13 documents referring to TRIM". INCITS T13. INCITS. Retrieved 2009-07-08.
- "T13 ATA8 Draft Spec 1697-D". INCITS. 2010-06-23. Retrieved 2010-08-14.
- "SATA 6Gb/s". Serial ATA International Organization. Retrieved 2012-09-26.
- "Note for SCSI UNMAP support in FreeBSD mailing list".
- From write() down to flash chips – an explanation on how the TRIM command lets SSDs erase data not used by the filesystem
- TRIM Command White Paper - a white paper explaining the TRIM command's purpose and actions