Saturday, December 10, 2011

TRIM For the masses

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. 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, the typical way in which operating systems handle operations like deletes and formats 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.

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 support TRIM, it has the associated drawbacks of increased write amplification and wear of the flash cells.

What’s it for?

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 flash cell to be marked as no longer valid. After that point the SSD knows not to relocate the data in those flash cells 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.

TRIM was firstly introduced to Windows users back in 2009 along with the release of Windows 7 and Windows Server 2008 R2.

If Windows detects the presence of an SSD drive, it should automatically disable several services in order to optimize performance. While this may be true, users keep argue about which settings should be changed to optimize performance.

Tips and tricks

After owning three SSD drives (two OCZ Vertex2 and an OCZ Agility3), I thought it might be a good idea to share some insights and some of my experience in configuring those settings.

1. Make sure you have the latest firmware – Drive vendors often don’t take any responsibility for data loss while upgrading firmware. Also, if you consider making the SSD your operating system drive bear in mind, you won’t be able to upgrade your firmware since this operation is not supported, so this should be the first thing to do. There are sometimes issues with the Intel Rapid Storage Managerso make sure you read the firmware release notes before making any changes, some versions are better and more compatible then others.

2. Set your disk controller to AHCI mode – AHCI stands for Advanced Host Controller Interface, allows using legacy IDE or ATA mode in SATA drives. Usually this prevents from installing proper disk controller drivers which in many cases will result in reduced performance, so this step is crucial.

3. Install the latest storage drivers – if your system includes an Intel SATA controller, you should use the most recent version of the Intel Rapid Storage Technology driver, which is located here

4. Install SSD Tweaker to automatically configure all related settings and optimize performance.

5. Although the TRIM command should work automatically with Windows 7, it sometimes can be a bit “lazy”. For those of you who have Windows 7 with SSD and feel the drive could use some freshen-up, check out a little app called ForceTrim. This tool is not supported with RAID.  ForceTrim will force the drive to go over all free flash cells and use the TRIM command on every cell that is marked for deletion. It should work on any vendor. Make sure you run ForceTrim as Administrator.

6. Monitor your drive’s health using a monitor tool such as CrystalDiskInfo

Final notes

If you’re like me, and want to keep the drive in ship-shape at all times, you can schedule the program to be launched every week from command line using:

schtasks /Create /SC WEEKLY /D SUN /TN ForceTrim /ST 00:00 /TR "C:\ForceTrim.exe C"

This will schedule ForceTrim to run every Sunday at midnight and optimize drive C

Cheers q[^_^]p


  1. I want to why we need to manually trim since windows 7 itself already built in TRIM function?

    1. Some controllers will wait until the free unTRIMed space is low and only then perform TRIM.
      Working with a large amount of data, Windows will sometimes wait until the controller is idle and only then perform send the TRIM command.
      From my experience, it's better to perform TRIM manually every once in a while for two main reasons:
      1. Performance - By not letting Windows determine when will the TRIM command, you decide when to operate the command
      2. Security - Launching the TRIM command will also erase all data, making the data recovery process a bit more difficult :)