TRIM (SSD command)
Encyclopedia
In computing
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...

, a TRIM command allows an operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

 to inform a solid-state drive
Solid-state drive
A solid-state drive , sometimes called a solid-state disk or electronic disk, is a data storage device that uses solid-state memory to store persistent data with the intention of providing access in the same manner of a traditional block i/o hard disk 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 not an acronym; it is merely a command name.

TRIM was introduced soon after SSDs started to become an affordable alternative to traditional hard disk
Hard disk
A hard disk drive is a non-volatile, random access digital magnetic data storage device. It features rotating rigid platters on a motor-driven spindle within a protective enclosure. Data is magnetically read from and written to the platter by read/write heads that float on a film of air above the...

s. Because low-level operation of SSDs differs significantly from traditional hard disks (see details below), the typical way in which operating systems handle operations like deletes and formats (not explicitly communicating the involved sectors/pages to the underlying storage medium) resulted in unanticipated progressive performance degradation of write operations on SSDs. TRIM enables the SSD to handle garbage collection overhead, that 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
Write amplification
Write amplification is an undesirable phenomenon associated with Flash memory and solid-state drives . Because Flash memory must be erased before it can be rewritten, the process to perform these operations results in moving user data and metadata more than once...

 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
File system
A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...

. 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 disk
Hard disk
A hard disk drive is a non-volatile, random access digital magnetic data storage device. It features rotating rigid platters on a motor-driven spindle within a protective enclosure. Data is magnetically read from and written to the platter by read/write heads that float on a film of air above the...

s, despite their 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 from 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
Kilobyte
The kilobyte is a multiple of the unit byte for digital information. Although the prefix kilo- means 1000, the term kilobyte and symbol KB have historically been used to refer to either 1024 bytes or 1000 bytes, dependent upon context, in the fields of computer science and information...

 each) further grouped into blocks (typically 128 pages, or 512 kB in total). 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
Write amplification
Write amplification is an undesirable phenomenon associated with Flash memory and solid-state drives . Because Flash memory must be erased before it can be rewritten, the process to perform these operations results in moving user data and metadata more than once...

.

Operation

The TRIM command is designed to enable the operating system to notify the SSD of which pages of data are now invalid due to erases by the user or operating system itself. During a delete operation the OS will not only mark the sectors as free for new data, but it will also send a TRIM command to the SSD with the associated LBAs
Logical block addressing
Logical block addressing is a common scheme used for specifying the location of blocks of data stored on computer storage devices, generally secondary storage systems such as hard disks....

 to be marked as no longer valid. After that point the SSD knows not to relocate the data in those LBAs during garbage collection. This will result in fewer writes to the flash enabling a lower write amplification and longer endurance. Different SSDs will act on the TRIM command somewhat differently so the final performance can also be different between different SSDs.

As the command completely purges the data it affects, typical data recovery is made impossible.

Shortcomings

  • Currently, support for the TRIM command has not been implemented in most RAID
    RAID
    RAID is a storage technology that combines multiple disk drive components into a logical unit...

     technologies. One case where it has been implemented is in post-January-2011 releases of the Linux kernel's dmraid
    Device mapper
    In the Linux kernel, the device-mapper serves as a generic framework to map one block device onto another. It forms the foundation of LVM2 and EVMS, software RAIDs, dm-crypt disk encryption, and offers additional features such as file-system snapshots....

    , 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
    Mdadm
    mdadm is a Linux utility used to manage software RAID devices.The name is derived from the md device nodes it administers or manages, and it replaced a previous utility mdctl...

    , 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
    Advanced Host Controller Interface
    The Advanced Host Controller Interface is a technical standard defined by Intel that specifies the operation of Serial ATA host bus adapters in a non-implementation-specific manner....

     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.

  • 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, which incurs massive execution penalty if used carelessly, e.g., if it's 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. The measured hit is anywhere between 15% to 1000%+. 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.

Operating system and SSD support

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 will have an upgrade option. For those drives which do support the command, the operating system must also support the command. The table below identifies each notable operating system and when it first supported the command or when it is scheduled to support the command.
Operating System Supported since References Notes
Windows 7 Final release - October 2009
Windows Server 2008 R2
Windows Server 2008 R2
Windows Server 2008 R2 is a server operating system produced by Microsoft. It was released to manufacturing on July 22, 2009 and launched on October 22, 2009. According to the Windows Server Team blog, the retail availability was September 14, 2009. It is built on Windows NT 6.1, the same core...

Final release - October 2009
Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

 2.6.33
Feb 2010 Not all filesystems make use of TRIM. Ext4 and Btrfs are known to support it
OpenSolaris
OpenSolaris
OpenSolaris was an open source computer operating system based on Solaris created by Sun Microsystems. It was also the name of the project initiated by Sun to build a developer and user community around the software...

July 2010
FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

 8.1
July 2010 Only for low-level device erase (zeroing all LBAs).
FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

 8.3 & 9.0
not released yet Full support in UFS
Unix File System
The Unix file system is a file system used by many Unix and Unix-like operating systems. It is also called the Berkeley Fast File System, the BSD Fast File System or FFS...

, no support in ZFS
ZFS
In computing, ZFS is a combined file system and logical volume manager designed by Sun Microsystems. The features of ZFS include data integrity verification against data corruption modes , support for high storage capacities, integration of the concepts of filesystem and volume management,...

.
DragonFly BSD
DragonFly BSD
DragonFly BSD is a free Unix-like operating system created as a fork of FreeBSD 4.8. Matthew Dillon, an Amiga developer in the late 1980s and early 1990s and a FreeBSD developer between 1994 and 2003, began work on DragonFly BSD in June 2003 and announced it on the FreeBSD mailing lists on July...

May 2011
Mac OS X Snow Leopard v10.6.6 (Build 10J3210) 24 February 2011 (With 3rd party)* *TRIM can be unofficially enabled on Mac OS X Snow Leopard by modifying extensions. Since February 2011 MacBook Pro models that ship with Intel SSDs are supported by Apple and feature TRIM support. Reinstalling the OS disables TRIM by default. It can be re-enabled by 3rd party software. By modifying extensions TRIM feature can be patched to support third-party SSDs and installed on other Macs. Version 10.6.8, build 10K540, released 23 June 2011, enabled TRIM support for solid state hard drives shipped in Apple-produced configurations.
Mac OS X Lion
Mac OS X Lion
Mac OS X Lion is the eighth and current major release of Mac OS X, Apple's desktop and server operating system for Macintosh computers....

 v10.7 (Build 11A444d)
24 February 2011* *Lion supports TRIM for all Apple-installed SSD drives. As with Snow Leopard, TRIM support for 3rd party drives can be activated by modifying a kernel extension.

Discard parameter in Linux

Although TRIM is supported in the Linux kernel since version 2.6.33, the operating system does not automatically enable TRIM operation. The user must modify the appropriate /etc/fstab file to add the word discard in the appropriate SSD entries. Without this user modification the Linux operating system will not pass the TRIM command to the SSD.

Enabling unsupported operating systems

Where TRIM is not automatically supported by the operating system, there are utilities which can send TRIM commands manually. Usually they list all free blocks as specified by the operating system 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
Hdparm
hdparm is a command line utility for the Linux and Windows operating systems to set and view ATA hard disk hardware parameters. It can set parameters such as drive caches, sleep mode, power management, acoustic management, and DMA settings....

 since v9.17).

ATA specification

The TRIM command specification is being standardized as part of the AT Attachment
AT Attachment
Parallel ATA , originally ATA, is an interface standard for the connection of storage devices such as hard disks, solid-state drives, floppy drives, and optical disc drives in computers. The standard is maintained by X3/INCITS committee...

 (ATA) interface standard, led by Technical Committee T13 of the International Committee for Information Technology Standards (INCITS). More details can be found regarding TRIM under the DATA SET MANAGEMENT (opcode 06h) section in the most recent version of the ACS-2 specification.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK