Trim (computing)#Operating system support

{{distinguish|text=trimming in computer programming, which is about removing space characters}}

{{Short description|Type of command for solid-state drive}}

{{Use dmy dates|date=August 2019}}

{{missing information|article|SMR drives (similar append-only zone problem)|date=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.{{Cite web

| url = http://www.intel.com/content/www/us/en/support/solid-state-drives/000016148.html?wapkw=trim

| title = Intel High Performance Solid State Drive – Advantages of TRIM

| date = 14 September 2010

| website = Intel.com

| publisher = Intel

| access-date = 2012-02-21

}}

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.{{Cite web|url=https://www.anandtech.com/show/2738 |title=The SSD Anthology: Understanding SSDs and New Drives from OCZ |author=Shimpi, Anand Lal |website=AnandTech.com |page=4 |date=2009-03-18 |access-date=2010-06-19}} Trimming enables the SSD to more efficiently handle garbage collection, 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 2010, 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.{{Cite web|title= Kingston SSDNow V Plus 100 Review|url=http://www.anandtech.com/show/4010/kingston-ssdnow-v-plus-100-review |date=2010-11-11|website=AnandTech.com |publisher= Anand Lal Shimpi|access-date=2010-12-10}}

TRIM is also used on some shingled magnetic recording (SMR) hard drives.{{cite web|url=https://documents.westerndigital.com/content/dam/doc-library/en_us/assets/public/western-digital/product/internal-drives/wd-purple-hdd/whitepaper-generic-benefit-for-hard-disk-drive.pdf|title=Trim Command - General Benefits for Hard disk Drives|website=Documents.westerndigital.com|access-date=November 7, 2021}}

Background

Because of the way that many file systems handle delete operations, by flagging data blocks as "not in use",{{Cite web |url=http://www.windowsitpro.com/article/john-savills-windows-faqs/q-i-heard-solid-state-disks-ssds-suffer-from-a-decline-in-write-performance-as-they-re-used-why-.aspx |title=I heard solid-state disks (SSDs) suffer from a decline in write performance as they're used. Why? |author=Savill, John |publisher=WindowsITPro |date=2009-04-21 |access-date=2010-06-19 |url-status=dead |archive-url=https://web.archive.org/web/20120819190909/http://www.windowsitpro.com/article/john-savills-windows-faqs/q-i-heard-solid-state-disks-ssds-suffer-from-a-decline-in-write-performance-as-they-re-used-why- |archive-date=19 August 2012 }}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 tools to recover files from electromechanical hard disks,{{Cite web |url=http://www.windowsitpro.com/article/file-systems/q-what-is-the-trim-function-for-solid-state-disks-ssds-and-why-is-it-important-.aspx |archive-url=https://archive.today/20130209233800/http://www.windowsitpro.com/article/file-systems/q-what-is-the-trim-function-for-solid-state-disks-ssds-and-why-is-it-important-.aspx |url-status=dead |archive-date=2013-02-09 |title=What is the TRIM function for solid-state disks (SSDs) and why is it important? |author=Savill, John |publisher=WindowsITPro |date=2009-04-22 |access-date=2010-06-19 }} 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.{{cite web | url = http://www.pcper.com/reviews/Storage/Long-term-performance-analysis-Intel-Mainstream-SSDs/Intel-Option-1-Write-Big | work=PC Perspective | title = Long-term performance analysis of Intel Mainstream SSDs | first=Allyn|last= Malventano| date=13 February 2009 | access-date=10 February 2012 }}

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. 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;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.{{cite news |url=http://www.extremetech.com/article2/0,2845,2329594,00.asp |title=Write Amplification: Intel's Secret Sauce |newspaper=Extremetech |date=8 September 2008 |publisher=ExtremeTech.com |access-date=2010-11-06 |last1=Case |first1=Loyd |archive-date=15 November 2010 |archive-url=https://web.archive.org/web/20101115074120/http://www.extremetech.com/article2/0%2C2845%2C2329594%2C00.asp |url-status=dead }}{{cite web |url=http://www.tomshardware.com/reviews/Intel-x25-m-SSD,2012-5.html |title=Inside the X25-M Controller: Wear Leveling, Write Amplification Control |publisher=TomsHardware.com |date=2008-09-08 |access-date=2010-11-06}}

Operation

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.

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.{{Cite web|title=Too TRIM? When SSD Data Recovery is Impossible |url=https://www.forensicfocus.com/articles/recovering-evidence-from-ssd-drives-in-2014-understanding-trim-garbage-collection-and-exclusions/ |date=2014-09-23 |work=Forensic Focus |access-date=2024-05-08}}

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.

class="wikitable sortable"
width="15%"|Operating System

! width="15%"|Supported since

! Notes

DragonFly BSD

| 2011-05May 2011{{Cite web|url=https://leaf.dragonflybsd.org/mailarchive/kernel/2011-05/msg00002.html|title=Preliminary TRIM support|website=leaf.dragonflybsd.org}}

|

FreeBSD

| 2010-078.1 – July 2010{{Cite web|title=FreeBSD 8.1-RELEASE Release Notes: Disks and Storage |url=http://www.freebsd.org/releases/8.1R/relnotes-detailed.html#DISKS |access-date=2010-09-01}}

| Support was added at the block device layer in 8.1. Filesystem support was added in FreeBSD 8.3 and FreeBSD 9, beginning with UFS.{{Cite web|title=Add kernel side support for BIO_DELETE/TRIM on UFS |url=http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/ufs/ffs/ffs_alloc.c#rev1.153.2.4 |access-date=2011-02-01}} ZFS trimming support was added in FreeBSD 9.2.{{Cite web|title=Added ZFS TRIM support which is enabled by default.|url=http://svnweb.freebsd.org/base?view=revision&revision=251419 |access-date=2013-06-05}}{{Cite web|title=FreeBSD 9.2-RELEASE Announcement |url=http://www.freebsd.org/releases/9.2R/announce.html |access-date=2013-10-04}} FreeBSD 10 supports trimming on software RAID configurations.{{Cite web|title=Base revision 242323 – Add basic BIO_DELETE support to GEOM RAID class for all RAID levels |url=http://svnweb.freebsd.org/base?view=revision&revision=242323 |access-date=2012-10-30}}

NetBSD

| 2012-10October 2012{{Cite web|title=TRIM support in NetBSD|url=http://mail-index.netbsd.org/source-changes/2012/10/19/msg038047.html|date=2012-10-19}}

|

Linux

| 2008-12-252.6.28–25 December 2008{{Cite web|url=https://kernelnewbies.org/Linux_2_6_28|title=Linux_2_6_28 - Linux Kernel Newbies|website=kernelnewbies.org}}

| Initial 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.{{Cite web|title=Storage changes in Linux 2.6.33|url=http://kernelnewbies.org/Linux_2_6_33#head-b9b8a40358aaef60a61fcf12e9055900709a1cfb|publisher=Kernel Newbies|access-date=2010-09-01}}

Not all filesystems make use of trim. Among the filesystems that can issue trim requests automatically are ext4,{{Cite web|url=https://sites.google.com/site/lightrush/random-1/howtoconfigureext4toenabletrimforssdsonubuntu|title=Forked by Nicolay - HOWTO: Configure Ext4 to Enable TRIM Support for SSDs on Ubuntu and Other Distributions|website=sites.google.com}} Btrfs,{{Cite web|url=https://kernelnewbies.org/Linux_2_6_32|title=Linux_2_6_32 - Linux Kernel Newbies|website=kernelnewbies.org}} FAT, GFS2, JFS,{{Cite web|title=JFS Filesystem can now handle trim|url=https://www.phoronix.com/scan.php?page=news_item&px=MTE5ODY|access-date=2012-03-28}} XFS,{{Cite web|url=https://kernelnewbies.org/Linux_3.0|title=Linux_3.0 - Linux Kernel Newbies|website=kernelnewbies.org}} ZFS,{{cite web |title=OpenZFS TRIM Support |url=https://openzfs.org/wiki/Features#TRIM_Support |website=openzfs.org}} and NTFS-3G. However, in some distributions, this is disabled by default due to performance concerns,{{cite web|url=http://opensuse.14.n6.nabble.com/SSD-detection-when-creating-first-time-fstab-td3313048.html |title=OpenSUSE forum – SSD detection when creating first time fstab |first=Greg |last=Freemyer|date=2010}} in favor of scheduled trimming on supported SSDs.{{cite web|title=How to enable TRIM?|url=http://askubuntu.com/questions/18903/how-to-enable-trim/19480#19480|website=Ask Ubuntu|access-date=11 November 2015}} 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.{{Cite web|url=https://en.opensuse.org/SDB:SSD_discard_(trim)_support|title=SDB:SSD discard (trim) support - openSUSE Wiki|website=en.opensuse.org}}

In many newer Linux distributions, systemd provides fstrim.timer unit.{{Cite web|title=Changes/EnableFSTrimTimer - Fedora Project Wiki|url=https://fedoraproject.org/wiki/Changes/EnableFSTrimTimer|access-date=2020-12-10|website=fedoraproject.org}} TRIM for swap partition can be enabled by swapon utility or fstab.{{Cite web |title=swapon(8) — Arch manual pages |url=https://man.archlinux.org/man/swapon.8.en |access-date=2024-06-20 |website=man.archlinux.org}}

macOS

| 2011-06-2310.6.8–23 June 2011{{Cite web|title=Mac OS X 10.6.8 Brings TRIM Support for Apple SSDs, Graphics Improvements|url=http://www.macrumors.com/2011/06/27/mac-os-x-10-6-8-brings-trim-support-for-apple-ssds-graphics-improvements/|date=2012-02-24}}

| Although the AHCI block device driver gained the ability to display whether a device supports the TRIM operation in 10.6.6 (10J3210),{{Cite web|title=Macbook Pros ship with active SSD TRIM support|url=http://www.appleinsider.com/articles/11/03/04/apples_macbook_pros_ship_with_active_ssd_trim_support_in_snow_leopard.html|date=2011-03-04}} 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|reason=This can easily be verified by inspecting the source code of the IOStorageFamily and xnu projects, but I'm not sure whether this counts as a real source.|date=April 2012}} 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.{{Cite web|title=Yosemite kills third-party SSD support|website=ZDNet|url=https://www.zdnet.com/article/yosemite-kills-third-party-ssd-support/}} Updated drivers now exist that work with OS X Yosemite.{{Cite web|url=http://chameleon.alessandroboschini.com/|title=Chameleon SSD Optimizer|website=chameleon.alessandroboschini.com}}{{Cite web|url=https://cindori.org/search/Trim+enabler/|title=You searched for Trim enabler|website=Cindori.org|access-date=7 November 2021|archive-date=8 November 2021|archive-url=https://web.archive.org/web/20211108084427/https://cindori.org/search/Trim+enabler/|url-status=dead}} In Mac OS X [https://support.apple.com/en-us/HT204928 update 10.10.4], Apple added a command line utility, trimforce, that can be used to enable TRIM on third-party SSDs.{{cite web|author1=Lee Hutchinson|title=Latest OS X update allows you to enable TRIM for third-party SSDs|url=https://arstechnica.com/apple/2015/06/latest-os-x-update-allows-you-to-enable-trim-for-third-party-ssds/|website=Ars Technica|publisher=Condé Nast|access-date=2015-07-01|date=30 June 2015}}

Microsoft Windows

| 2009–10Windows 7 and Windows Server 2008 R2 – October 2009{{Cite web|url=http://blogs.msdn.com/e7/archive/2009/05/05/support-and-q-a-for-solid-state-drives-and.aspx |title=Support and Q&A for Solid-State Drives |date=2009-05-09 |work=Engineering Windows 7 blog |publisher=Microsoft |archive-url=https://web.archive.org/web/20100425050749/http://blogs.msdn.com/e7/archive/2009/05/05/support-and-q-a-for-solid-state-drives-and.aspx |archive-date=2010-04-25 |first=Michael |last=Fortin |editor-first=Steven |editor-last=Sinofsky}} [https://docs.microsoft.com/en-us/archive/blogs/e7/support-and-qa-for-solid-state-drives Alt URL]{{Cite web|title=Windows 7 Enhancements for Solid-State Drives |url=http://download.microsoft.com/download/F/A/7/FA70E919-8F82-4C4E-8D02-97DB3CF79AD5/COR-T558_Shu_Taiwan.pdf |date=2008-11-12 |work=Microsoft downloads |publisher=Microsoft Corporation |access-date=2009-07-08}}

|Windows 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.[http://techreport.com/articles.x/22663 Geoff Gasior (2012)] OCZ's RevoDrive 3 X2 240GB solid-state drive It is confirmed that with native Microsoft drivers the TRIM command works on Windows 7 in AHCI and legacy IDE / ATA Mode.{{cite web |url=http://archive.benchmarkreviews.com/index.php?option=com_content&task=view&id=505&Itemid=38&limit=1&limitstart=12 |title=SSD Benchmark Tests: SATA IDE vs AHCI Mode – AHCI vs IDE Final Thoughts |first=Olin |last=Coles |date=15 April 2010 |work=BenchmarkReviews |access-date=20 August 2013}} 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.{{cite web |title=Update to add native driver support in NVM Express in Windows 7 and Windows Server 2008 R2 |url=https://support.microsoft.com/en-us/help/2990941/update-to-add-native-driver-support-in-nvm-express-in-windows-7-and-wi |website=Support |publisher=Microsoft |date=8 September 2015}}{{cite web |title=What is the TRIM Command on Solid State Drives? |url=https://datarecovery.com/rd/trim-command-solid-state-drives/ |website=datarecovery.com |date=30 January 2017 |quote=Microsoft added the feature in a Windows 7 update known as KB2990941}}

TRIM is known to be supported for ReFS and NTFS, both of which implement a DisableDeleteNotify switch for disabling it.{{cite web |title=Fsutil behavior |url=https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil-behavior |website=Microsoft Documentation |access-date=17 November 2019 |language=en-us}} It is also supported for Bitlocker volumes with ReFS and NTFS volumes within. However, Windows does not support TRIM on exFAT or the older FAT/FAT32 filesystems.{{cite web |title=TRIM support in Windows |url=https://gist.github.com/CKingX/d9843b2afa58d5dad78e192fa5ea61aa}}

OpenSolaris

| 2010-07July 2010{{Cite web|title=SATA TRIM support in OpenSolaris|url=http://www.c0t0d0s0.org/archives/6792-SATA-TRIM-support-in-Opensolaris.html|date=2010-07-29|access-date=29 July 2010|archive-date=12 August 2012|archive-url=https://web.archive.org/web/20120812002958/http://www.c0t0d0s0.org/archives/6792-SATA-TRIM-support-in-Opensolaris.html|url-status=dead}}

|

Android

| 2013-74.3{{Cite web|url=http://www.anandtech.com/show/7185/android-43-update-brings-trim-to-all-nexus-devices |title=Android 4.3 Update Brings TRIM to All Nexus Devices|date=2013-07-29|access-date=2013-07-30}} – 24 July 2013[https://www.theverge.com/2013/7/24/4550234/android-4-3-announcement "Android 4.3 announced, rolling out to Nexus devices today"].The Verge. 24 July 2013. Retrieved 24 July 2013.

|Runs 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).

= RAID issues =

{{As of|2017|1}}, 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.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.{{cite web |url=http://serverfault.com/questions/227918/possible-to-get-ssd-trim-discard-working-on-ext4-lvm-software-raid-in-linu|title=Possible to get SSD TRIM (discard) working on ext4 + LVM + software RAID in Linux? – Server Fault|access-date=2011-11-29}}

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).{{cite web| url=https://github.com/Cyberax/mdtrim|title=Cyberax/mdtrim – GitHub|website=GitHub|access-date=2011-11-29}} 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.{{cite web|url=https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/ch-ssd.html|title=Red Hat Enterprise Linux 6 Storage Administration Guide, Chapter 21. Solid-State Disk Deployment Guidelines|access-date=2016-03-09}}

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.{{cite web|url=http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/7/html-single/Storage_Administration_Guide/index.html#ssddeploy|title=Red Hat Enterprise Linux 7 Storage Administration Guide|date=2015-11-11|access-date=2016-02-29}}

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 (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.{{cite web| url=http://www.intel.com/support/chipsets/imsm/sb/CS-031491.htm |title=Is there TRIM support for RAID configurations? |access-date=2010-11-06 |date=2010-03-26 |publisher=Intel}}

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.{{cite web|url=http://www.storagereview.com/intel_confirms_raid0_trim_support_on_7series_chipsets|title=Intel Confirms RAID0 TRIM Support on 7-Series Chipsets|access-date=2013-01-14|date=2012-08-19|archive-date=22 October 2012|archive-url=https://web.archive.org/web/20121022095157/http://www.storagereview.com/intel_confirms_raid0_trim_support_on_7series_chipsets|url-status=dead}} 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.{{cite web|url=http://forums.anandtech.com/showthread.php?t=2281849|title=RAID0 trim and SRT seems possible on 6-series and 5-Series|access-date=2013-01-14|date=2012-11-18|archive-date=18 January 2013|archive-url=https://web.archive.org/web/20130118035253/http://forums.anandtech.com/showthread.php?t=2281849|url-status=dead}} It is speculated that the lack of official support for 6-series chipsets is due to validation costs{{cite web|url=http://www.anandtech.com/show/6477/trim-raid0-ssd-arrays-work-with-intel-6series-motherboards-too|title=TRIM & RAID-0 SSD Arrays Work With Intel 6-Series Motherboards Too|access-date=2013-01-14|date=2012-11-28}} or an attempt to encourage consumers to upgrade,{{cite web|url=https://www.anandtech.com/show/6161/intel-brings-trim-to-raid0-ssd-arrays-on-7series-motherboards-we-test-it|title=Intel Brings TRIM to RAID-0 SSD Arrays on 7-Series Motherboards, We Test It|access-date=2013-01-14|date=2012-08-16}} 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.{{cite web|url=http://www.anandtech.com/show/6161/intel-brings-trim-to-raid0-ssd-arrays-on-7series-motherboards-we-test-it|title=Intel Brings TRIM to RAID-0 SSD Arrays on 7-Series Motherboards, We Test It|author=Anand Lal Shimpi}} 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.{{cite web|url=http://www.tomshardware.com/news/TRIM-RST-RAID-0-SSD-7-series,16898.html|title=TRIM Command Confirmed With RAID 0 on Intel 7 Series|author=Doug Crowthers|work=Tom's Hardware|date=17 August 2012}}

= 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,{{Cite web |title= Intel SSD Optimizer White Paper |url= http://download.intel.com/design/flash/nand/mainstream/Intel_SSD_Optimizer_White_Paper.pdf |publisher= Intel Corporation |access-date= 23 January 2010 |url-status= dead |archive-url= https://web.archive.org/web/20121005122335/http://download.intel.com/design/flash/nand/mainstream/Intel_SSD_Optimizer_White_Paper.pdf |archive-date= 5 October 2012 |df= dmy-all }} G.Skill{{Cite web |title=wiper.exe for Falcon Series |url=http://www.xtremesystems.org/forums/showthread.php?p=3784347 |publisher=XtremeSystems |access-date=23 January 2010 |archive-date=25 June 2013 |archive-url=https://web.archive.org/web/20130625015930/http://www.xtremesystems.org/forums/showthread.php?224356-only-for-Falcon-Series-wiper.exe-TRIM-COMMAND-for-Falcon-Series-SSD |url-status=dead }}), or as general utilities (e.g. Linux's hdparm "wiper" since v9.17,{{Cite web|title=hdparm-9.17 released, with experimental trim/wiper scripts for SSDs |url=https://lwn.net/Articles/345020/ |access-date= 14 August 2010}}{{Cite web|title=hdparm project page |url=http://sourceforge.net/projects/hdparm |publisher= sourceforge.net |access-date= 14 August 2010}}

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.

Hardware support

= ATA =

The TRIM command specification{{Cite web |title=Data Set Management Commands Proposal for ATA8-ACS2 (revision 6) |url=http://t13.org/Documents/UploadedDocuments/docs2008/e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc |date=2007-12-12 |work=INCITS T13 |publisher=INCITS |access-date=2009-07-08 |archive-date=13 June 2010 |archive-url=https://web.archive.org/web/20100613085651/http://t13.org/Documents/UploadedDocuments/docs2008/e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc |url-status=dead }} (draft specification T13/e07154r6) 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).{{Cite web |title=T13 documents referring to TRIM |url=http://t13.org/Documents/MinutesDefault.aspx?keyword=trim |work=INCITS T13 |publisher=INCITS |access-date=2009-07-08 |archive-date=26 May 2010 |archive-url=https://web.archive.org/web/20100526115741/http://t13.org/Documents/MinutesDefault.aspx?keyword=trim |url-status=dead }} TRIM is implemented under the DATA SET MANAGEMENT command (opcode 06h) of the draft ACS-2 specification.{{Cite web|title=T13 ATA8 Draft Spec 1697-D|url=http://www.t13.org/Documents/UploadedDocuments/docs2010/d1697r4-1697D_AT_Attachment-8_-_Serial_Transport_ATA8-AST.pdf|publisher=INCITS|access-date=2010-08-14|date=2010-06-23|archive-date=22 March 2011|archive-url=https://web.archive.org/web/20110322062157/http://www.t13.org/Documents/UploadedDocuments/docs2010/d1697r4-1697D_AT_Attachment-8_-_Serial_Transport_ATA8-AST.pdf|url-status=dead}} 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.{{cite web|title=SATA 6Gb/s|url=https://www.sata-io.org/technology/6Gbdetails.asp|publisher=Serial ATA International Organization|access-date=2012-09-26}}

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.{{cite web|title=Device.Storage Requirements (Windows)|url=http://msdn.microsoft.com/en-us/library/windows/hardware/jj134356.aspx|access-date=2016-02-29}}

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.{{cite web|title=T13/2161-D: Information technology – ATA/ATAPI Command Set – 3 (ACS-3)|url=http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf|website=T13.org|access-date=2016-02-29|archive-date=5 April 2016|archive-url=https://web.archive.org/web/20160405130623/http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf|url-status=dead}} 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 provides the UNMAP command (a full analog of TRIM), and the WRITE SAME command (10 and 16 variants) with the UNMAP flag set.{{Cite web|url=https://lists.freebsd.org/pipermail/freebsd-current/2011-December/030714.html|title=RFC: SCSI UNMAP (TRIM) support|first=Alexander|last=Motin|website=Lists.freebsd.org|date=24 December 2011|access-date=7 November 2021}}

= SD/MMC =

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").

= NVM Express =

The NVM Express command set has a generic Dataset Management command, for hinting the host's intent to the storage device on a set of block ranges. If that command is executed with the Attribute – Deallocate (AD) bit set to 1 in Command Dword 11, it performs trim. It also has a Write Zeroes command, which contains a Deallocate (DEAC) bit in Command Dword 12 that allows the disk to trim and return zeroes.NVM Command Set

Specification 1.1 https://nvmexpress.org/wp-content/uploads/NVM-Express-NVM-Command-Set-Specification-Revision-1.1-2024.08.05-Ratified.pdf

Disadvantages

  • Some deniable encryption schemes involve making the whole disk look like random garbage. Using TRIM defeats this layer of plausible deniability as the all-zero (or all-one) blocks created easily indicate what blocks are used.{{cite web |url=http://asalor.blogspot.com/2011/08/trim-dm-crypt-problems.html |title=Milan Broz's blog: TRIM & dm-crypt ... problems? |date=14 August 2011 |publisher=Milan Broz |access-date=2014-10-01}} It has been argued disabling TRIM might be suspicious too.{{Cite web|url=https://i.blackhat.com/eu-18/Thu-Dec-6/eu-18-Schaub-Perfectly-Deniable-Steganographic-Disk-Encryption.pdf|title=Perfectly Deniable Steganographic Disk Encryption|website=I.blackhat.com|access-date=7 November 2021}}
  • The original version of the TRIM command has been defined as a non-queued command by the T13 subcommittee, 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 cycle.{{citation needed|date=May 2012}} This penalty can be minimized in solutions that do batched TRIMs and/or periodic TRIMs, rather than trimming upon every file deletion, by scheduling such batch jobs for times when system utilization is low. This TRIM disadvantage has been overcome in Serial ATA revision 3.1 with the introduction of the Queued TRIM Command.{{cite web|url=http://www.sata-io.org/technology/6Gbdetails.asp|title=The Path from 3Gb/s to SATA 6Gb/s: How to Migrate Current Designs to the SATA Revision 3.0 Specification|date=May 27, 2009|website=Sata-io.org|access-date=November 7, 2021}}{{cite web|url=http://techreport.com/news/21311/sata-3-1-spec-brings-swap-standard-improved-trim|title=SATA 3.1 spec brings swap standard, improved TRIM|work=The Tech Report|date=18 July 2011 }}
  • Only some hypervisors (such as Hyper-V, Parallels Desktop) have implemented TRIM for the Guest OS (as of 2023).
  • Faulty drive firmware that misreports support for queued TRIM or has critical bugs in its implementation has been linked to serious data corruption and/or serious bugs like frequent freezes in several devices, most notably Micron and Crucial's M500{{Cite web|url=https://bugzilla.kernel.org/show_bug.cgi?id=71371|title=71371 [PATCH]Crucial M500, broken "queued TRIM" support|website=bugzilla.kernel.org}} and Samsung's 840 and 850 series.{{Cite web|url=https://bugs.launchpad.net/bugs/1449005|title=Bug #1449005 trim does not work with Samsung 840 EVO after firm... : Bugs : fstrim package : Ubuntu|website=Launchpad|date=27 April 2015 }} The data corruption has been confirmed on the Linux operating system (the only OS with queued trim support as of 1 July 2015).{{cite web|url=https://github.com/torvalds/linux/blob/e64f638483a21105c7ce330d543fa1f1c35b5bc7/drivers/ata/libata-core.c#L4109-L4286|title=linux/libata-core.c at e64f638483a21105c7ce330d543fa1f1c35b5bc7 · torvalds/linux · GitHub|author=torvalds|work=GitHub}}

These devices are blacklisted in the Linux kernel's {{Mono|libata-core.c}} to force sending non-queued TRIM commands ({{Mono|ATA_HORKAGE_NO_NCQ_TRIM}}) to these drives instead of queued TRIM commands:{{cite web|url=https://github.com/torvalds/linux/blob/master/drivers/ata/libata-core.c|title=linux/libata-core.c at master · torvalds/linux · GitHub|author=torvalds|work=GitHub}}

  • 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.{{cite web|url=https://github.com/torvalds/linux/commit/cda57b1b05cf7b8b99ab4b732bea0b05b6c015cc|title=libata: force disable trim for SuperSSpeed S238 · torvalds/linux@cda57b1|author=torvalds|work=GitHub}}

{{Mono|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:

  • Crucial SSDs
  • Intel SSDs excluding the Intel SSD 510
  • Micron SSDs
  • Samsung SSDs
  • Seagate SSDs{{Cite web|url=http://patchwork.ozlabs.org/project/linux-ide/patch/1415336894-15327-2-git-send-email-martin.petersen@oracle.com/|title=[1/3] libata: Whitelist SSDs that are known to properly return zeroes after TRIM - Patchwork|website=patchwork.ozlabs.org}}

See also

References

{{Reflist|30em}}