A trim command (known as TRIM in the ATA command set, and UNMAP in the SCSI command set) allows an operating system to inform a storage medium which blocks of data are no longer considered to be "in use" and therefore can be erased internally. TRIM is primarily used on solid-state drives (SSDs), but is also used on some shingled magnetic recording (SMR) hard drives. Trim commands were introduced soon after SSDs. Because SSDs use different technology from earlier magnetic hard drives, the preexisting techniques for storing data caused early SSDs to become slower as they were used more. With trimming, the SSD can efficiently clear unneeded data that would otherwise slow future write operations. Although tools to "reset" some drives to a fresh state were already available before the introduction of trimming, they also delete all data on the drive, which makes them impractical to use for ongoing optimization. As of 2010, many SSDs and many flash removable storage devices had internal garbage collection mechanisms for certain filesystem(s) (such as FAT and NTFS) that worked independently of trimming. Although this successfully maintained their lifetime even under operating systems that did not support trim, it had the associated drawbacks of increased write amplification and wear of the flash cells, as well as decreased write performance of flash cells.
Background Many file systems handle delete operations by flagging data blocks as "not in use". As a result, storage media devices generally do not know which sectors/pages are truly in use and which can be considered free space. Contrary to (for example) an overwrite operation, a delete will not involve writing to the sectors that contained the data. Since a common SSD has no knowledge of the file system structures, including the list of unused blocks/sectors, the storage medium remains unaware that the blocks have become available. This allows undelete tools to recover (parts of) files from electromechanical hard disks, despite the files being reported as "deleted" by the operating system. But 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 magnetic disks, an overwrite of existing data is no different from writing into 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 typically of 4 to 16 KiB, grouped together into blocks of typically 128 to 512 pages, for example 512 kiB blocks that group 128 pages of 4 kiB each. NAND flash memory cells can be directly written to only when they are empty. If they happen to contain data, the contents must be erased before a write operation. An SSD write operation can be done to a single page but, due to hardware limitations, erase commands always affect entire blocks. Consequently, writing data to empty pages on an SSD is very fast, 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 to again, but only entire blocks can be erased, an overwrite will initiate a read-erase-modify-write cycle: the contents of the entire block are stored in cache, then the entire block is erased from the SSD, then the overwritten page(s) is written into the cached block, and only then can the entire updated block be written to the flash medium. This phenomenon is known as write amplification.
Operation The TRIM command enables an operating system to notify the drive of pages which no longer contain valid data. For a file deletion operation, the operating system will mark the file's sectors as free for new data, then send a TRIM command to the drive. After trimming, the drive will not preserve any contents of the block when writing new data to a page of flash memory, resulting in less write amplification (fewer writes), higher write throughput (no need for a read-erase-modify sequence), thus increasing drive life. Different drives implement the command somewhat differently, so performance can vary. TRIM tells the drive to mark an LBA region as invalid and subsequent reads on the region will not return any meaningful data. For a very brief time, the data could still reside on the flash internally. After the TRIM command is issued and garbage collection has taken place, recovery of deleted or corrupted data can be difficult or impossible, depending on the drive's firmware implementation of the command.
Implementation
Operating system support The TRIM command is beneficial only if the drive implements it and the operating system requests 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. The support for TRIM also varies by what the particular filesystem driver on the operating system is capable of, since only a program with an understanding of what parts of the disk are free space can safely issue the command, and on the system level this ability tends to lie in the filesystem driver itself.
RAID issues As of January 2017, support for the TRIM command is not implemented in most hardware-based RAID technologies. However, software RAID implementations often do include support for TRIM.
Windows Windows 10 offers support for TRIM in SSD ID volumes using the "optimize drives" option when configuring a RAID volume.
macOS The macOS RAID driver does not support TRIM. This is true for all versions of Mac OS X from 10.7 through macOS 10.12.
… excerpt ends here. Continue reading the full article.