This article is missing information about SMR drives (similar append-only zone problem).(April 2020) |
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 solid-state drive (SSD) which blocks of data are no longer considered to be "in use" and therefore can be erased internally. [1]
Trim was introduced soon after SSDs were introduced. Because low-level operation of SSDs differs significantly from hard drives, the conventional manner in which operating systems handle storage operations—such as deletions and formatting—resulted in unanticipated progressive performance degradation of write operations on SSDs. [2] Trimming enables the SSD to more efficiently handle garbage collection, which would otherwise slow future write operations to the involved blocks. [3]
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. [4] As of 2024, many SSDs had internal garbage collection mechanisms for certain filesystem(s) (such as FAT32, NTFS, APFS) 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 and wear of the flash cells. [5]
TRIM is also used on some shingled magnetic recording (SMR) hard drives. [6]
Because of the way that many file systems handle delete operations, by flagging data blocks as "not in use", [7] [8] 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 tools to recover files from electromechanical hard disks, [8] [9] 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. [8] [10]
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. Example: 512 kiB blocks that group 128 pages of 4 kiB each. [7] [11] 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; [11] 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: [7] [12] 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. [13] [14]
The TRIM command enables an operating system to notify the SSD 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 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. [3] [9]
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, data recovery can become difficult or impossible, depending on the drive's firmware implementation of the command. [15]
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.
Operating System | Supported since | Notes |
---|---|---|
DragonFly BSD | [16] | May 2011|
FreeBSD | [17] | 8.1 – July 2010Support was added at the block device layer in 8.1. Filesystem support was added in FreeBSD 8.3 and FreeBSD 9, beginning with UFS. [18] ZFS trimming support was added in FreeBSD 9.2. [19] [20] FreeBSD 10 supports trimming on software RAID configurations. [21] |
NetBSD | [22] | October 2012|
Linux | [23] | 2.6.28–25 December 2008Initial 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. [24] Not all filesystems make use of trim. Among the filesystems that can issue trim requests automatically are ext4, [25] Btrfs, [26] FAT, GFS2, JFS, [27] XFS, [28] ZFS, [29] and NTFS-3G. However, in some distributions, this is disabled by default due to performance concerns, [30] in favor of scheduled trimming on supported SSDs. [31] 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. [32] In many newer Linux distributions, systemd provides |
macOS | [35] | 10.6.8–23 June 2011Although the AHCI block device driver gained the ability to display whether a device supports the TRIM operation in 10.6.6 (10J3210), [36] the functionality itself remained inaccessible until 10.6.8, when the TRIM operation was exposed via the IOStorageFamily and filesystem (HFS+) support was added.[ citation needed ] Until 10.10.4, Mac OS X natively enabled TRIM only for Apple-branded SSDs; third-party utilities are available to enable it for other brands. Old third party TRIM drivers stopped working as of the Yosemite update. [37] Updated drivers now exist that work with OS X Yosemite. [38] [39] In Mac OS X update 10.10.4, Apple added a command line utility, trimforce , that can be used to enable TRIM on third-party SSDs. [40] |
Microsoft Windows | [41] [42] | Windows 7 and Windows Server 2008 R2 – October 2009Windows 7 initially supported TRIM only for drives in the AT Attachment family including Parallel ATA and Serial ATA, and did not support this command for any other devices including Storport PCI-Express SSDs even if the device itself would accept the command. [43] It is confirmed that with native Microsoft drivers the TRIM command works on Windows 7 in AHCI and legacy IDE / ATA Mode. [44] Windows 8 and later Windows operating systems support the unmap command for devices that use the SCSI driver stack, including USB Attached SCSI Protocol (UASP). Windows 8.1 and later Windows operating systems support the TRIM command for NVM Express SSDs. Microsoft has released an update for Windows 7 that adds NVM Express support including TRIM for PCIe SSDs. [45] [46] TRIM is known to be supported for ReFS and NTFS, both of which implement a DisableDeleteNotify switch for disabling it. [47] Sources disagree on whether TRIM support exists for other filesystems. |
OpenSolaris | [48] | July 2010|
Android | [49] – 24 July 2013 [50] | 4.3Runs fstrim automatically up to once every 24 hours if the device has been idle for at least an hour and is at least 80% charged (30% if connected to a charger). [49] |
As of January 2017 [update] , 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 10 offers support for TRIM in SSD ID volumes using the "optimize drives" option when configuring a RAID volume.
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".)
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. [51]
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). [52] 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. [53]
However, Red Hat 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) 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. [54]
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. [53]
For a short time in March 2010, users were led to believe that the Intel Rapid Storage Technology (RST) 9.6 (and later) drivers in Windows 7 supported TRIM on 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. [55]
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. [56] 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. [57] It is speculated that the lack of official support for 6-series chipsets is due to validation costs [58] or an attempt to encourage consumers to upgrade, [59] 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. [60] 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. [61]
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, [62] G.Skill [63] ), or as general utilities (e.g. Linux's hdparm "wiper" since v9.17, [64] [65] 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 the 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 do not write all zeros to "wipe" files or free space, but some utilities do.
The TRIM command specification [66] has been standardized as part of the AT Attachment (ATA) interface standard, led by Technical Committee T13 of the International Committee for Information Technology Standards (INCITS). [67] TRIM is implemented under the DATA SET MANAGEMENT command (opcode 06h) of the draft ACS-2 specification. [68] 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. [69]
There are different types of TRIM defined by SATA Words 69 and 169 returned from an ATA IDENTIFY DEVICE command:
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. [70]
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. [71] 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 provides the UNMAP command (a full analog of TRIM), and the WRITE SAME command (10 and 16 variants) with the UNMAP flag set. [72]
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. A DISCARD sub-operation is further defined in eMMC 4.5, and optionally in SDHC and SDXC cards, that more closely matches ATA TRIM in that the contents of discarded blocks can be considered indeterminate (i.e., "don't care").
The NVM Express 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.
These devices are blacklisted in the Linux kernel's libata-core.c to force sending non-queued TRIM commands (ATA_HORKAGE_NO_NCQ_TRIM) to these drives instead of queued TRIM commands: [80]
This file also blacklists the SuperSSpeed S238 against TRIM in general due to causing the wrong blocks to lose data when TRIM is issued. [80] [81]
libata-core.c 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: [80]
Parallel ATA (PATA), originally AT Attachment, also known as IDE or Integrated Drive Electronics, 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 is used for storage devices such as hard disk drives, floppy disk drives, optical disc drives, and tape drives in computers.
SATA 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 to become the predominant interface for storage devices.
Disk formatting is the process of preparing a data storage device such as a hard disk drive, solid-state drive, floppy disk, memory card or USB flash drive for initial use. In some cases, the formatting operation may also create one or more new file systems. The first part of the formatting process that performs basic medium preparation is often referred to as "low-level formatting". Partitioning is the common term for the second part of the process, dividing the device into several sub-devices and, in some cases, writing information to the device allowing an operating system to be booted from it. The third part of the process, usually termed "high-level formatting" most often refers to the process of generating a new file system. In some operating systems all or parts of these three processes can be combined or repeated at different levels and the term "format" is understood to mean an operation in which a new disk medium is fully prepared to store files. Some formatting utilities allow distinguishing between a quick format, which does not erase all existing data and a long option that does erase all existing data.
Self-Monitoring, Analysis, and Reporting Technology is a monitoring system included in computer hard disk drives (HDDs) and solid-state drives (SSDs). Its primary function is to detect and report various indicators of drive reliability with the intent of anticipating imminent hardware failures.
In computing, Native Command Queuing (NCQ) is an extension of the Serial ATA protocol allowing hard disk drives to internally optimize the order in which received read and write commands are executed. This can reduce the amount of unnecessary drive head movement, resulting in increased performance for workloads where multiple simultaneous read/write requests are outstanding, most often occurring in server-type applications.
Cylinder-head-sector (CHS) is an early method for giving addresses to each physical block of data on a hard disk drive.
In computing, a hybrid drive is a logical or physical storage device that combines a faster storage medium such as solid-state drive (SSD) with a higher-capacity hard disk drive (HDD). The intent is adding some of the speed of SSDs to the cost-effective storage capacity of traditional HDDs. The purpose of the SSD in a hybrid drive is to act as a cache for the data stored on the HDD, improving the overall performance by keeping copies of the most frequently used data on the faster SSD drive.
sync is a standard system call in the Unix operating system, which commits all data from the kernel filesystem buffers to non-volatile storage, i.e., data which has been scheduled for writing via low-level I/O system calls. Higher-level I/O layers such as stdio may maintain separate buffers of their own.
A solid-state drive (SSD) is a solid-state storage device. It provides persistent data storage using no moving parts. It is sometimes called semiconductor storage device or solid-state device. It is also called solid-state disk because it is frequently interfaced to a host system in the same manner as a hard disk drive (HDD).
In computing, error recovery control (ERC) is a feature of hard disks which allow a system administrator to configure the amount of time a drive's firmware is allowed to spend recovering from a read or write error. Limiting the recovery time allows for improved error handling in hardware or software RAID environments. In some cases, there is a conflict as to whether error handling should be undertaken by the hard drive or by the RAID implementation, which leads to drives being marked as unusable and significant performance degradation, when this could otherwise have been avoided.
In computer storage, a disk buffer is the embedded memory in a hard disk drive (HDD) or solid-state drive (SSD) acting as a buffer between the rest of the computer and the physical hard disk platter or flash memory that is used for storage. Modern hard disk drives come with 8 to 256 MiB of such memory, and solid-state drives come with up to 4 GB of cache memory.
Intel Rapid Storage Technology (RST) is a driver SATA AHCI and a firmware-based RAID solution built into a wide range of Intel chipsets. Currently also is installed as a driver for Intel Optane temporary storage units.
SCSI / ATA Translation (SAT) is a set of standards developed by the T10 subcommittee, defining how to communicate with ATA devices through a SCSI application layer. The standard attempts to be consistent with the SCSI architectural model, the SCSI Primary Commands, and the SCSI Block Commands standards.
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 written.
USB Attached SCSI (UAS) or USB Attached SCSI Protocol (UASP) is a computer protocol used to move data to and from USB storage devices such as hard drives (HDDs), solid-state drives (SSDs), and thumb drives. UAS depends on the USB protocol, and uses the standard SCSI command set. Use of UAS generally provides faster transfers compared to the older USB Mass Storage Bulk-Only Transport (BOT) drivers.
The Intel X25-M was a line of Serial ATA interface solid-state drives developed by Intel for personal computers, announced in late 2008. The SSD was a multi-level-cell solid-state drive available in a 2.5" form factor, came in 80 GB and 160 GB capacities and utilized NAND flash memory on a 50 nm process. The second-generation SSD which was called the "X25-M G2". The X25-M G2 was also available in a 2.5" form factor and 80 GB and 160 GB capacities, but with NAND flash memory on a more efficient 34 nm process.
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 the PCI Express bus. The initial NVM stands for non-volatile memory, which is often NAND flash memory that comes in several physical form factors, including solid-state drives (SSDs), PCIe add-in cards, and M.2 cards, the successor to mSATA cards. NVM Express, as a logical-device interface, has been designed to capitalize on the low latency and internal parallelism of solid-state storage devices.
In computer data storage, Smart Response Technology is a proprietary caching mechanism introduced in 2011 by Intel for their Z68 chipset, which allows a SATA solid-state drive (SSD) to function as cache for a hard disk drive (HDD).
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-overlapping concentric magnetic tracks, while shingled recording writes new tracks that overlap part of the previously written magnetic track, leaving the previous track narrower and allowing higher track density. Thus, the tracks partially overlap similar to roof shingles. This approach was selected because, if the writing head is made too narrow, it cannot provide the very high fields required in the recording layer of the disk.
SATA Express is a computer bus interface that supports both Serial ATA (SATA) and PCI Express (PCIe) storage devices, initially standardized in the SATA 3.2 specification. The SATA Express connector used on the host side is backward compatible with the standard SATA data connector, while it also provides two PCI Express lanes as a pure PCI Express connection to the storage device.
Microsoft added the feature in a Windows 7 update known as KB2990941