Trim (computing)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 193.179.199.50 (talk) at 11:36, 19 September 2011 (The referenced commit has been related to HEAD (e.g, future release). FreeBSD 8.2 tree has been created on Dec 21, before the mentioned commit and doesn't contain it.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Template:Other uses2 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 not an acronym; it is merely a command name.[1]

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 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.[2] TRIM enables the SSD to handle garbage collection overhead, that would otherwise significantly slow down future write operations to the involved blocks, in advance.[3]

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.[4] 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.[5]

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.[6][7] 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,[7][8] 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.[7]

SSDs store data in flash memory cells that are grouped into pages, with the pages (typically 4 kB each) further grouped into blocks (typically 128 pages, or 512 kB in total).[6][9] 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.[9] 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:[6][10]: 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.[11][12]

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 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.[3][8]

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

Shortcomings

  • The TRIM command does not work on RAID volumes.[14][15] For a short time in March 2010, users were led to believe that the Intel Rapid Storage Technology 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.[16]
  • When software-based disk encryption is in use, using the TRIM command reveals information about which blocks are in use and which are not.[17]
  • 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%+.[18][19][20][21][22]

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 [23]
Windows Server 2008 R2 Final release - October 2009 [24]
Linux 2.6.33 Feb 2010 [25] Not all filesystems make use of TRIM. Ext4 and Btrfs are known to support it[26]
OpenSolaris July 2010 [27]
FreeBSD 8.1 July 2010 [28] Only for low-level device erase (zeroing all LBAs).
FreeBSD 8.3 & 9.0 not released yet [29] Full support in UFS[30], no support in ZFS[31].
DragonFly BSD May 2011 [32]
Mac OS X Snow Leopard v10.6.6 (Build 10J3210) 24 February 2011 (With 3rd party)* [33] *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.[34] Version 10.6.8, build 10K540, released 23 June 2011, enabled TRIM support for solid state hard drives shipped in Apple-produced configurations.[35]
Mac OS X Lion v10.7 (Build 11A444d) 24 February 2011* [36] *Lion added TRIM support for all SSDs that came with a Mac[37]

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.[38]

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,[14] G.Skill[39]) or as general utilities (hdparm since v9.17[40][41]).

ATA specification

The TRIM command specification[42] 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).[43] 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.[44]

References

  1. ^ Intel Corporation (14 September 2010). "Intel® High Performance Solid State Drive - Advantages of TRIM". Intel.com. Retrieved 17 March 2011.
  2. ^ Shimpi, Anand Lal (18 March 2009). "The SSD Anthology". AnandTech.com. p. 4. Retrieved 19 June 2010.
  3. ^ a b Shimpi, Anand Lal. (2009-03-18). p. 10.
  4. ^ Shimpi, Anand Lal. (2009-03-18). p. 11.
  5. ^ "Kingston SSDNow V Plus 100 Review". Anandtech. Anand Lal Shimpi. 11 November 2010. Retrieved 10 December 2010.
  6. ^ a b c Savill, John (21 April 2009). "I heard solid-state disks (SSDs) suffer from a decline in write performance as they're used. Why?". WindowsITPro. Retrieved 19 June 2010.
  7. ^ a b c Shimpi, Anand Lal. (2009-03-18). p. 7.
  8. ^ a b Savill, John (22 April 2009). "What is the TRIM function for solid-state disks (SSDs) and why is it important?". WindowsITPro. Retrieved 19 June 2010.
  9. ^ a b Shimpi, Anand Lal. (2009-03-18). p. 5.
  10. ^ Shimpi, Anand Lal. (2009-03-18). p. 8.
  11. ^ "Write Amplification: Intel's Secret Sauce". ExtremeTech.com. Retrieved 6 November 2010.
  12. ^ "Inside the X25-M Controller: Wear Leveling, Write Amplification Control". TomsHardware.com. 8 September 2008. Retrieved 6 November 2010.
  13. ^ "Too TRIM? When SSD Data Recovery is Impossible". TechGage. TechGage. 5 March 2010. Retrieved 16 April 2010.
  14. ^ a b "Intel SSD Optimizer White Paper" (PDF). Intel Corporation. Retrieved 23 January 2010.
  15. ^ "Even Without Support for the TRIM Command, SSD Flies on Mac OS X". hardmac.com. Retrieved 6 November 2010.
  16. ^ "Is there TRIM support for RAID configurations?". Intel. 26 March 2010. Retrieved 6 November 2010.
  17. ^ "TrueCrypt - TRIM Operation". TrueCrypt.org. Retrieved 6 November 2010.
  18. ^ "Performance of TRIM command on ext4 filesystem".
  19. ^ "The trouble with discard (trim)".
  20. ^ "non-queued trim".
  21. ^ "Thread at realworld tech site (over 200 posts)".
  22. ^ "TRIM discussion w.r.t. raid".
  23. ^ "Support and Q&A for Solid-State Drives". MSDN. 2009-05-09. Retrieved 2010-08-12]. {{cite web}}: Check date values in: |accessdate= (help)
  24. ^ "Windows 7 Enhancements for Solid-State Drives" (PDF). Microsoft downloads. Microsoft Corporation. 12 November 2008. Retrieved 8 July 2009.
  25. ^ "Trim on Linux". Kernel Newbies. Retrieved 1 September 2010.
  26. ^ "HOWTO: Configure Ext4 to Enable TRIM Support for SSDs on Ubuntu and Other Distributions". Retrieved 8 May 2011.
  27. ^ "SATA TRIM support in OpenSolaris". 29 July 2010.
  28. ^ "FreeBSD 8.1-RELEASE Release Notes: Disks and Storage". Retrieved 1 September 2010.
  29. ^ "Add kernel side support for BIO_DELETE/TRIM on UFS". Retrieved 1 February 2011.
  30. ^ "SVN revision 216796". 29 December 2010.
  31. ^ "TRIM clustering". 5 May 2011.
  32. ^ "Preliminary TRIM support".
  33. ^ "Macbook Pros ship with active SSD TRIM support". 4 March 2011.
  34. ^ "Hardmac.com - The universal solution to activate TRIM". 27 March 2011.
  35. ^ [1]
  36. ^ "New Build of Mac OS X Lion with TRIM Support for all Macs that Shipped with SSDs". 4 March 2011.
  37. ^ "Hardmac.com - The universal solution to activate TRIM". 27 March 2011.
  38. ^ Williams, Rob (6 May 2011). "Enabling and Testing SSD TRIM Support Under Linux". Techgage. Retrieved 21 June 2011.
  39. ^ "wiper.exe for Falcon Series". XtremeSystems. Retrieved 23 January 2010.
  40. ^ "hdparm-9.17 released, with experimental trim/wiper scripts for SSDs". Retrieved 14 August 2010.
  41. ^ "hdparm project page". sourceforge.net. Retrieved 14 August 2010.
  42. ^ "Data Set Management Commands Proposal for ATA8-ACS2 (revision 6)". INCITS T13. INCITS. 12 December 2007. Retrieved 8 July 2009. (draft specification T13/e07154r6)
  43. ^ "T13 documents referring to TRIM". INCITS T13. INCITS. Retrieved 8 July 2009.
  44. ^ "T13 ATA8 Draft Spec 1697-D" (PDF). INCITS. 23 June 2010. Retrieved 14 August 2010.

External links