A trim command (known as TRIM in the
ATA command set, and UNMAP in the
SCSI command set) allows an
operating system
An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs.
Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
to inform a
solid-state drive
A solid-state drive (SSD) is a solid-state storage device that uses integrated circuit assemblies to store data persistently, typically using flash memory, and functioning as secondary storage in the hierarchy of computer storage. It is ...
(SSD) which blocks of data are no longer considered to be 'in use' and therefore can be erased internally.
Trim was introduced soon after SSDs were introduced. 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.
Trimming enables the SSD to more efficiently handle
garbage collection
Waste collection is a part of the process of waste management. It is the transfer of solid waste from the point of use and disposal to the point of treatment or landfill. Waste collection also includes the curbside collection of recyclable m ...
, which would otherwise slow future write operations to the involved blocks.
[Shimpi, Anand Lal. (18 March 2009). p. 10.
TRIM is an ATA command (Advanced Technology Attachment Command) that allows an OS to inform SSD about the blocks of data no longer in use. The SSD then deletes such blocks of data to make a way for newer blocks of data. TRIM is basically used for enhancing the performance and life span of the SSD.
Unfortunately, the boon of TRIM becomes a bane for data recovery from SSD. Therefore, it is strongly recommended to regularly make a backup copy of your data using a reliable tool (for example Disk Drill for Windows), especially if your OS is warning about SSD failing.
]
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.
[Shimpi, Anand Lal. (18 March 2009). p. 11.] As of , many SSDs and USB flash drives had internal garbage collection mechanisms for certain filesystems (such as
FAT32
File Allocation Table (FAT) is a file system developed for personal computers. Originally developed in 1977 for use on floppy disks, it was adapted for use on hard disks and other devices. It is often supported for compatibility reasons by c ...
,
NTFS
New Technology File System (NTFS) is a proprietary journaling file system developed by Microsoft. Starting with Windows NT 3.1, it is the default file system of the Windows NT family. It superseded File Allocation Table (FAT) as the preferred fil ...
,
APFS
Apple File System (APFS) is a proprietary file system developed and deployed by Apple Inc. for macOS Sierra (10.12.4) and later, iOS 10.3 and later, tvOS 10.2 and later, watchOS 3.2 and later, and all versions of iPadOS. It aims to fix c ...
) that worked independently of trimming. Although this successfully maintained their lifetime and performance even under operating systems that did not support trim, it had the associated drawbacks of increased
write amplification
Write amplification (WA) is an undesirable phenomenon associated with flash memory and solid-state drives (SSDs) where the actual amount of information physically written to the storage media is a multiple of the logical amount intended to be wr ...
and wear of the flash cells.
TRIM is also widely used on
shingled magnetic recording
Shingled magnetic recording (SMR) is a magnetic storage data recording technology used in hard disk drives (HDDs) to increase storage density and overall per-drive storage capacity. Conventional hard disk drives record data by writing non-overl ...
(SMR) hard drives.
Background
Because of the way that many
file system
In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
s handle delete operations, by flagging data blocks as "not in use",
[Shimpi, Anand Lal. (18 March 2009). p. 7.] 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. Contrary to (for example) an overwrite operation, a delete will not involve a physical write to the sectors that contain 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. While this often enables
undelete
Undeletion is a feature for restoring computer files which have been removed from a file system by file deletion. Deleted data can be recovered on many file systems, but not all file systems provide an undeletion feature. Recovering data with ...
tools to recover files from electromechanical
hard disk
A hard disk drive (HDD), hard disk, hard drive, or fixed disk is an electro-mechanical data storage device that stores and retrieves digital data using magnetic storage with one or more rigid rapidly rotating platters coated with magnet ...
s,
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 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 with 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
The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit ...
, grouped together into blocks of typically 128 to 512 pages. Example: 512 kiB blocks that group 128 pages of 4 kiB each.
NAND flash memory
Flash memory is an electronic non-volatile computer memory storage medium that can be electrically erased and reprogrammed. The two main types of flash memory, NOR flash and NAND flash, are named for the NOR and NAND logic gates. Both use ...
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;
[Shimpi, Anand Lal. (18 March 2009). p. 5.] 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:
[Shimpi, Anand Lal. (18 March 2009). p. 8.] 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
Write amplification (WA) is an undesirable phenomenon associated with flash memory and solid-state drives (SSDs) where the actual amount of information physically written to the storage media is a multiple of the logical amount intended to be wr ...
.
Operation
The TRIM command enables an operating system to notify the SSD of pages which no longer contain valid data. For a
file deletion
File deletion is the removal of a computer file, file from a computer's file system.
All operating systems include commands for deleting files (rm (Unix), rm on Unix, del (command), era in CP/M and DR-DOS, del (command), del/del (command), eras ...
operation, the operating system will mark the file's sectors as free for new data, then send a TRIM command to the SSD. After trimming, the SSD 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 SSDs implement the command somewhat differently, so performance can vary.
TRIM tells the SSD 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. However, after the TRIM command is issued and garbage collection has taken place, it is highly unlikely that even a forensic scientist would be able to recover the data.
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
, support for the TRIM command is not implemented in most hardware-based
RAID
Raid, RAID or Raids may refer to:
Attack
* Raid (military), a sudden attack behind the enemy's lines without the intention of holding ground
* Corporate raid, a type of hostile takeover in business
* Panty raid, a prankish raid by male college ...
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.x.
TRIM is supported for RAID (0,1,4,5 & 10) volumes when using the third-party SoftRAID® application, including TRIM support with non-Apple SSD devices.
(Note: TRIM for non-Apple SSD devices must be specifically enabled using the terminal command "sudo trimforce enable")
Linux
TRIM is available with RAID volumes in post-January-2011 releases of the Linux kernel's
dmraid, which implements BIOS-assisted "fake hardware RAID" support, and which 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
File deletion is the removal of a computer file, file from a computer's file system.
All operating systems include commands for deleting files (rm (Unix), rm on Unix, del (command), era in CP/M and DR-DOS, del (command), del/del (command), eras ...
) 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). In later versions of Linux, e.g. Red Hat Enterprise Linux 6.5 and beyond, mdraid supports actually passing through TRIM commands in real-time, rather than just as a batch job.
However,
Red Hat
Red Hat, Inc. is an American software company that provides open source software products to enterprises. Founded in 1993, Red Hat has its corporate headquarters in Raleigh, North Carolina, with other offices worldwide.
Red Hat has become ass ...
recommends against using software RAID levels 1, 4, 5, and 6 on SSDs with most RAID technologies, because during initialization, most RAID management utilities (e.g. Linux's
mdadm
mdadm is a Linux utility used to manage and monitor software RAID devices. It is used in modern Linux distributions in place of older software RAID utilities such as raidtools2 or raidtools.
mdadm is free software originally maintained by, ...
) write to all blocks on the devices to ensure that checksums (or drive-to-drive verifies, in the case of RAID 1 and 10) operate properly, causing the SSD to believe that all blocks other than in the spare area are in use, significantly degrading performance.
On the other hand, Red Hat does recommend the use of RAID 1 or RAID 10 for
LVM RAIDs on SSDs, as these levels support TRIM ("discard" in Linux terminology), and the LVM utilities do not write to all blocks when creating a RAID 1 or RAID 10 volume.
Firmware-based RAID
For a short time in March 2010, users were led to believe that the Intel Rapid Storage Technology (RST) 9.6 drivers supported TRIM on RAID volumes, but Intel later clarified that TRIM was supported for the BIOS settings of
AHCI
The Advanced Host Controller Interface (AHCI) is a technical standard defined by Intel that specifies the register-level interface of Serial ATA (SATA) host controllers in a non-implementation-specific manner in its motherboard chipsets.
The ...
mode and RAID mode, but not if the drive was part of a RAID volume.
As of August 2012, Intel confirms that 7-series chipsets with Rapid Storage Technology (RST) 11.2 drivers support TRIM for RAID 0 in Microsoft Windows 7. While Intel did not confirm support for 6-series chipsets, TRIM on RAID 0 volumes has been shown to work on Z68, P67, and X79 chipsets by hardware enthusiasts with a modified RAID
option ROM
An Option ROM for the PC platform (i.e. the IBM PC and derived successor computer systems) is a piece of firmware that resides in ROM on an expansion card (or stored along with the main system BIOS), which gets executed to initialize the device and ...
. 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.
An exception to the need for a modified option ROM on motherboards with an X79 chipset is if the manufacturer has added a ROM switch; this entails both the RST and RST-E ROMs being inside the BIOS/UEFI. This allows the RST ROM to be used instead of the RST-E ROM, allowing TRIM to function. Intel notes that best performance can be achieved by using a driver with same version as the ROM; for example, if the BIOS/UEFI has an 11.0.0.0m option ROM, an 11.x version driver should be used.
Enabling unsupported filesystems
Where the filesystem does not automatically support TRIM, some utilities can send trimming commands manually. Usually they determine which blocks are free and then pass this list as a series of trimming commands to the drive. These utilities are available from various manufacturers (e.g. Intel,
G.Skill), or as general utilities (e.g. Linux's
hdparm
hdparm is a command line program for Linux to set and view ATA hard disk drive hardware parameters and test performance. It can set parameters such as drive caches, sleep mode, power management, acoustic management, and DMA settings. GParted ...
"wiper" since v9.17, or mdtrim, as mentioned
above). Both hdparm and mdtrim find free blocks by allocating a large file on the filesystem and resolving what physical location it was assigned to.
Regardless of operating system, the drive can detect when the computer writes all-zeros to a block, and de-allocate (trim) that block instead of recording a block of zeros. If reading a de-allocated block always returns zeros, this shortcut is transparent to the user, except for faster writing (and reading) of all-zero blocks, in addition to the usual benefit of faster writing into unused areas. Operating systems don't write all-zeros to
"wipe" files or free space, but some utilities do.
Hardware support
ATA
The TRIM command specification has been standardized as part of the
AT Attachment
Parallel ATA (PATA), originally , also known as IDE, is a standard interface designed for IBM PC-compatible computers. It was first developed by Western Digital and Compaq in 1986 for compatible hard drives and CD or DVD drives. The connection ...
(ATA) interface standard, led by Technical Committee T13 of the
International Committee for Information Technology Standards
The InterNational Committee for Information Technology Standards (INCITS), (pronounced "insights"), is an ANSI-accredited standards development organization composed of Information technology developers. It was formerly known as the X3 and NCITS. ...
(INCITS). TRIM is implemented under the DATA SET MANAGEMENT command (opcode 06h) of the draft ACS-2 specification. The ATA standard is supported by both parallel (IDE, PATA) and serial (SATA) ATA hardware.
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 69 and 169 returned from an ATA IDENTIFY DEVICE command:
* Non-deterministic TRIM: Each read command to the
logical block address (LBA) after a TRIM may return different data.
* Deterministic TRIM (DRAT): All read commands to the LBA after a TRIM shall return the same data, or become determinate.
* Deterministic Read Zero after TRIM (RZAT): All read commands to the LBA after a TRIM shall return zero.
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 4 kB) but many drives reduce this to 1 to meet the Microsoft Windows Hardware Requirements for TRIM, that command completion time shall not exceed 20 ms or 8 ms × (number of LBA range entries), whichever is greater, and shall always be less than 600 ms.
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 counter (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. This means that for each 512-byte block of TRIM ranges that a device supports, the maximum is 64 ranges of 32 MB, or 2 GB. If a device supports SATA Word 105 at 8 then it should be able to trim 16 GB in a single TRIM (DATA SET MANAGEMENT) command.
SCSI
SCSI
Small Computer System Interface (SCSI, ) is a set of standards for physically connecting and transferring data between computers and peripheral devices. The SCSI standards define commands, protocols, electrical, optical and logical interface ...
provides the UNMAP command (a full analog of TRIM), and the WRITE SAME command (10 and 16 variants) with the UNMAP flag set.
SD/MMC
The
MultiMediaCard
The MultiMediaCard, officially abbreviated as MMC, is a memory card standard used for solid-state storage. Unveiled in 1997 by SanDisk and Siemens, MMC is based on a surface-contact low pin-count serial interface using a single memory stack subs ...
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").
NVM Express
The
NVM Express
NVM Express (NVMe) or Non-Volatile Memory Host Controller Interface Specification (NVMHCIS) is an open, logical-device interface specification for accessing a computer's non-volatile storage media usually attached via PCI Express (PCIe) bus. The ...
command set has a generic ''Dataset Management'' command set, for hinting the host's intent to the storage device on a set of block ranges. One of its operations, DEALLOCATE performs trim. It also has a WRITE ZEROES command that provides a DEALLOCATE hint and allows the disk to trim and return zeroes.
Disadvantages
* Some
deniable encryption
In cryptography and steganography, plausibly deniable encryption describes encryption techniques where the existence of an encrypted file or message is deniable in the sense that an adversary cannot prove that the plaintext data exists.
The users ...
schemes involve making the whole disk look like random garbage. Using TRIM defeats this layer of
plausible deniability
Plausible deniability is the ability of people, typically senior officials in a formal or informal chain of command, to denial, deny knowledge of or responsibility for any damnable actions committed by members of their organizational hierarchy. Th ...
as the all-zero (or all-one) blocks created easily indicate what blocks are used. It has been argued disabling TRIM might be suspicious too.
* The original version of the TRIM command has been defined as a non-queued command by the
T13 subcommittee
The InterNational Committee for Information Technology Standards (INCITS), (pronounced "insights"), is an ANSI-accredited standards development organization composed of Information technology developers. It was formerly known as the X3 and NCITS. ...
, and consequently can incur 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 wait for all outstanding commands to be finished, 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
Waste collection is a part of the process of waste management. It is the transfer of solid waste from the point of use and disposal to the point of treatment or landfill. Waste collection also includes the curbside collection of recyclable m ...
cycle. This penalty can be minimized in solutions that periodically do a batched TRIM, rather than trimming upon every
file deletion
File deletion is the removal of a computer file, file from a computer's file system.
All operating systems include commands for deleting files (rm (Unix), rm on Unix, del (command), era in CP/M and DR-DOS, del (command), del/del (command), eras ...
, by scheduling such batch jobs for times when system utilization is minimal. This TRIM disadvantage has been overcome in
Serial ATA
SATA (Serial AT Attachment) is a computer bus interface that connects host bus adapters to mass storage devices such as hard disk drives, optical drives, and solid-state drives. Serial ATA succeeded the earlier Parallel ATA (PATA) standard t ...
revision 3.1 with the introduction of the Queued TRIM Command.
* Faulty drive firmware that misreports support for queued TRIM or has critical bugs in its implementation has been linked to serious data corruption in several devices, most notably Micron and Crucial's M500
and Samsung's 840 and 850 series. The data corruption has been confirmed on the Linux operating system (the only OS with queued trim support as of 1 July 2015).
These devices are blacklisted in the Linux kernel's to force sending non-queued TRIM commands () to these drives instead of queued TRIM commands:
* Micron/Crucial M500 using all firmware versions including factory recertified SSDs
* Micron M510 using firmware version MU01
* Micron/Crucial M550 using firmware version MU01
* Crucial MX100 using firmware version MU01
* Samsung 840 and 850 series SSDs using all firmware versions
This file also blacklists the SuperSSpeed S238 against TRIM in general due to causing the wrong blocks to lose data when TRIM is issued.
also has a whitelist to list SSDs that are reliably known to the subsystem's maintainers to correctly implement the DRAT and RZAT flags (
ATA_HORKAGE_ZERO_AFTER_TRIM
), rather than ignoring them, as many drives do. The whitelisted drives are as follows:
* Crucial SSDs
* Intel SSDs excluding the Intel SSD 510
* Micron SSDs
* Samsung SSDs
* Seagate SSDs
See also
*
Data remanence
Data remanence is the residual representation of digital data that remains even after attempts have been made to remove or erase the data. This residue may result from data being left intact by a nominal file deletion operation, by reformatting o ...
References
External links
''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 command's purpose and actions
* Fusion-io Paten
"Apparatus, system, and method for redundant write caching"
{{DEFAULTSORT:Trim
Solid-state computer storage
SCSI
Serial ATA