Quantcast
Features

White Paper: The TRIM Command

Share/Save

Preventing SSD write slowdowns is possible, simply by scheduling deletions

Though solid state drives have existed for years, it is only recently that they’ve gained any sort of market penetration for average users. As we stated in our February 2009 white paper on the subject, solid state drives offer many advantages over traditional magnetic drives. Unlike mechanical hard drives, SSDs have no moving parts, so they draw less power and produce no vibrations. They’re also more resistant to physical shock. And most importantly, solid state drives offer much higher read and write speeds than traditional hard drives—at least when they’re new. Due to their NAND flash architecture, SSDs can suffer serious slowdowns once they run out of fresh blocks to write to. The TRIM command, found in Windows 7 and newer releases of the Linux kernel, aims to fix this. But what is TRIM, and why is it even necessary?

Why is TRIM Necessary?

When a file is deleted, the operating system doesn’t erase the data right away—instead, it marks that area on the disk as overwriteable in the index of all files on the disk, so the next time data needs to be written to the drive, it can use the space previously taken up by that file. This, incidentally, is why file recovery software works—provided the space hasn’t been written over, the data is still on your drive and can thus be recovered. It’s important to note that the drive itself doesn’t know anything about the status of the data on the drive. This blind-drive system works fine for mechanical hard drives since they can overwrite old data with no penalty, but because of the way NAND flash memory is arranged, slowdowns can occur once all the blocks on the drive have been used once.

The flash memory in solid state drives typically stores data in 4KB chunks, called pages, grouped in blocks of 128 pages each. Data can be read and written at the 4KB page level, but can only be erased at the 512KB block level. And while reading data and writing to unused pages on an SSD is much faster than on a standard hard drive, overwriting data is a complicated, multi-step procedure, one that SSDs typically perform only when they have run out of fresh blocks to write to.


(click to enlarge)

When an SSD runs out of fresh blocks, it has to write over data the file system has marked as deleted. And that’s where the slowdowns begin. To overwrite a single 4KB page the file system first has to copy the entire 512KB block to its memory cache. Then, in cache, the overwriteable pages are deleted and replaced with the new data. Next, the entire 512KB block on the drive is erased and rewritten with the cached data. If you’re writing to many blocks at a time—either through a series of small random write operations, or simply by writing a large file to disk—you can overload your drive’s cache pretty quickly, and then your write speeds will plummet. You can imagine how slow it can be when you’re writing a 2GB file or performing lots of 4KB writes. Users of early SSDs sometimes found themselves with write latencies of up to a second. To compensate, SSD manufacturers began increasing the size of their drives’ DRAM cache to 64MB or even 128MB, and adopting faster drive controllers. This largely eliminated random-write stuttering, but drives were still slowing down as they ran out of fresh pages.

What TRIM Does

In a nutshell, the problem is that the OS and the file system don’t communicate information about deleted files to the SSD, and all writes to pages that contain unerased deleted data require a full block-level erase and rewrite, which can drastically reduce write speeds.  There are two approaches to fixing this problem. The first is to run a garbage-collection program periodically that scans the entire drive and erases the contents of deleted pages.  Many drive vendors now ship a program called wiper.exe that will erase deleted pages throughout the entire drive to return it to like-new performance. In some cases this program actually completely clears the drive, requiring valid data to be backed up beforehand. The second, better approach is to have the OS tell the drive when data is deleted, so that the drive can erase those blocks immediately. That’s what the TRIM command does.

When a file is deleted on a TRIM-enabled system, the OS sends a command to the SSD to let it know that the data in a particular set of pages can be overwritten, moving control over deleted data from the OS level to the drive’s firmware. The SSD then copies the blocks containing the deleted data to cache, erases the blocks, then rewrites only the pages with data on them. Thus, the caching and erasing process is moved out of the time-sensitive write cycle and into the time between the actual deletion and the next write, so the slowdown is less likely to cause a noticeable performance hit.

Adoption

For the TRIM command to work, both the OS and the drive need to support it. TRIM is implemented in the Linux kernel as of revision 2.6.28, as well as in Windows 7, and all major SSD manufacturers have announced support. TRIM support may be added to some older drives via a firmware update, but not all older drives can support the TRIM command. If you plan on buying an SSD, make sure it supports the TRIM command—and if you already own an SSD, contact the vendor to see if a firmware upgrade is available.  If not, your best bet is to see if your manufacturer has an SSD optimization utility (frequently called wiper.exe) that you can run on a regular basis to erase deleted pages.

8 comments
avatarSSD XP/Vista/7 general knowledge!

OK; first things first, Windows XP is no longer a fully supported OS.
What this means to the end user is that nothing will be added,
therefore no TRIM support is in the future for XP. However WIN 7 is
written on a Vista skeleton, so many drivers will work back and forth
between the two. Note I said many that does not mean all.

So
there will not be TRIM support for XP unless written by the Hrd DRV
manufacturer. If you want to know if trim is working open a DOS prompt
(as am Administrator) in 7 definitely, probably in Vista as well, I
doubt this command exists in XP at all.  Type "fsutil behavior query
DisableDeletNotify" hit enter, if your return is DisableDeletNotify =0
Trim is enabled and functional, if the equals is =1 it is not. So either
you need to flash the SSD firmware if available, or it will not be
working on your drive.

As for support that is questionable as well
as dependant on exactly who you get if you call support, and there
knowledge level. So even if it is or is nor supported by your drive the
easiest way to find out is through the admin DOS prompt as I outlined. I
would copy that command and paste it unless you wanna type if over and
over. The reason I say this is it usually take a few times beforre it
will work correctly. I was also told "by a support rep", that I would
have to enable AHCI mode which is also untrue. It works physically on my
computer in sata mode although I do have raid mode enable in BIOS,
which means the MB may be running SATA/AHCI mode by default.

Newest
system won on hothardware.com From the site CyberPower PC, Thermaltake,
Intel, and Kingston (I added the second GPU from my existing system
when I won), I also added the two (WD, Samsung) harddrives from my old
system. I then incorporated my old system with my wifes old computer and
built her an AMD Phenom II X4 BE 965 C3 barn burner, then took all the
excess parts and some I had around the house and built another system
for a familyeithout the means to buy a computer (there daughter is about
to start school so they needed one)!

       Machine name: rapid1
  
Operating System: Windows 7 Ultimate 64-bit (6.1, Build 7600)
System
Manufacturer: Gigabyte Technology Co., Ltd.
       System Model:
X58A-UD5
               BIOS: Award Modular BIOS v6.00PG
         
Processor: Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz (8 CPUs),
~2.8GHz
             Memory: 6144MB RAM
Available OS Memory:
6142MB RAM
          Page File: 1589MB used, 6599MB available
       
Windows Dir: C:\Windows
    DirectX Version: DirectX 11
DX Setup
Parameters: Not found
     Graphics Card1: ATI Radeon HD 5800 Series
    
Graphics Card2: ATI Radeon HD 5800 Series

      Drive: C:
 Free
Space: 40.0 GB
      Model: KINGSTON SNV325S2 ATA Device

     
Drive: M: (Media)
 Free Space: 695.4 GB
      Model: WDC
WD7501AALS-00E8B0 ATA Device

      Drive: P: (Programs)
 Free
Space: 399.4 GB
      Model: SAMSUNG HD753LJ ATA Device

     
Drive: S: (Backup
 Free Space: 233.7 GB
      Model: SAMSUNG
HD753LJ ATA Device

      Drive: U: (Virtual Memory 1)
 Free
Space: 4.0 GB
      Model: WDC WD7501AALS-00E8B0 ATA Device

     
Drive: V: (Virtual Memory 2)
 Free Space: 4.0 GB
      Model:
SAMSUNG HD753LJ ATA Device

      Drive: D:
      Model:
HL-DT-ST DVDRAM GH22NS40 ATA Device
    
      Drive: K:
     
Model: HL-DT-ST DVDRAM GH24NS50 ATA Device
    

Login or register to post comments
avatarIn some cases this program

In some cases this program actually completely clears the drive, requiring valid data to be backed up beforehand.

this statement is clearly written by a person who has not used the wiper tool. i have noticed all max pc does is regurgitate facts from knowlegable sites without knowing crap about what they are saying. oh and by the way THANKS FOR SAYING THE TORX DRIVE IS FASTER THAN THE INTEL i listened and got rid of my faster, MUCH FASTER, intel just another case of mpc not knowing crap BUT I STILL LOVE YOU GUYS USUALLY!

 

Login or register to post comments
avataragree

I have to agree with you here. A lot of the ssd articles on maxpc seem to just be regurgitated snippets from other tech sites. They rarely ever contain hard data, merely hearsay. Also, SSD technology is so different from current drive technology that the methods we have previously used to test drives are being rendered useless. If you want the real down and dirty about SSDs head over to anandtech. Hes been doing real research for some time now and can show hard data to back up the findings.

Login or register to post comments
avatarSSD INFO

anandtech is where i goto too max pc should pay those guys for more knowledgeable articles

Login or register to post comments
avatarWhich has trim?

Been watching SSDs thinking of purchasing, but how the heck do I differenciate which drives support trim and which don't. Am not buying a trim-less drive.

Login or register to post comments
avatarNo one is forcing...

http://blogs.msdn.com/e7/archive/2009/05/05/support-and-q-a-for-solid-state-drives-and.aspx

Windows 7 requests the Trim operation for more than just file delete operations. The Trim operation is fully integrated with partition- and volume-level commands like Format and Delete, with file system commands relating to truncate and compression, and with the System Restore (aka Volume Snapshot) feature.

@jcollins 

"Or are they just planning on forcing people to either update to Win7 or use a wiper.exe app on a regular basis? "

I wouldn't consider it forcing.  You don't have to use TRIM at all.  And you don't have to upgrade, but native support for TRIM might certainly be a benefit that will impact your decision to upgrade or switch to Linux.  As of right now, your only option is to use the tools provided by the drive manufacturers.  They didn't have to provide those tools either by the way.

It's also worth noting that SSDs are still relatively new consumer technology.  And like any new technology, the first adopters are always going to feel the growing pains.  So, you may feel like you're being forced into a decision, but this is what you signed on for whether you knew it or not.

Login or register to post comments
avatarSo it sounds like TRIM is

So it sounds like TRIM support is not on WindowsXP or Vista.  Do you know if there are any plans to add it to those systems?  Or are they just planning on forcing people to either update to Win7 or use a wiper.exe app on a regular basis?

Login or register to post comments
Connect with Maximum PC
Twitter | Facebook | Podcast" | Newsletter | RSS
This Month's Issue
FEATURE29 Essential PC SkillsFEATUREAndroid Power Users GuideHOW TOGet Linux Power of Your Windows PCFEATUREMotherboard ManiaWHITE PAPERIntel's Light Peak
Maximum PC on Facebook