Replicate TRIM with a Mac SSD
If you have an SSD on your Mac, listen up. You can replicate TRIM SSD functionality in Mac OS X by using this great tip from one of our readers, here’s Curt explaining: “I just got a MacBook Air and like many others I was surprised to learn Mac OS X doesn’t support TRIM. I found a workaround, here it is:”
Update 2: You can use a third party TRIM enabler tool for Mac OS X 10.6.7 or later, that actually enables TRIM rather than trying to replicate it.
Update / Warning: There have been reports that using this method slows down the SSD’s speed. Excessive writes to an SSD can also limit its lifespan. Until Mac OS X natively supports TRIM, your best bet may be to backup your files, reformat the drive, and then copy the files back to the drive (frustrating, I know). You may wish to read the comments below before trying this out on your own SSD drive. Proceed at your own risk and always have a complete file system backup handy!
- Launch Disk Utility, located in /Applications/Utilities/
- Select your SSD from the left side drive list
- Click on the “Erase” tab (don’t worry it won’t start formatting things)
- Look for and click on the “Erase Free Space” button near the bottom as seen in the screenshot
- Let the “Erase Free Space” function run
- Close Disk Utility when it’s finished
Curt describes how this work as follows: “What this does is write 0’s over previously deleted files, which makes it easier to later write to that block again, this is similar to the TRIM function. Here’s a simplification of how TRIM works for comparison; it clears deleted blocks on the SSD so that they are understood as empty when it’s time to write back to that block. I would recommend using this tip about once a month as a regular system maintenance plan, or after deleting a large amount of files from your SSD.”
We edited the instructions and provided a screenshot for clarity, but thanks for sending this great tip in Curt!
It’s a little strange to me that Mac OS X does not currently have TRIM support built in, despite Apple selling the MacBook Air with SSD and offering the SSD upgrade on most other Macs for sale. I don’t have an SSD to test this out but the theory behind it makes some sense.
I have a 2009 Macbook Air with no TRIM support. Tried the “tip” here and ran Xbench before erasing free space, after one run of erase free space and again after a second run of erase free space. I rebooted each time before doing erase free space, and then after that before running Xbench.
Xbench’s disk test reported no significant difference following each of the erase free space runs. My boot time has worsened by about five seconds.
This “tip” is not recommended from my tests.
I have the latest MBP 17″ MacBookPro8,3 and according to SystemProfiler
Trim support Yes
According to comments at this bit-tech article, the unformatted state of flash memory is a 1, not a 0:
http://www.bit-tech.net/hardware/apple/2010/07/01/mac-ssd-performance-trim-in-osx/comments/2
I haven’t verified this, but if it’s correct, then this tip may not accomplish anything, and may explain some decreased performance in some of the comments here. (I seem to vaguely remember this as being true, when working with controllers with flash memory.)
Very interesting Mecki, and others. I am seriously thinking of upgrading my 2010 Mac Mini with a OWC Mercury Extreme Pro SSD, used as boot and apps drive only. All other data will be transferred to an external drive. I have been wondering about this trim topic, and everywhere I look, it goes back and forth. Here is just one test that I stumbled across addressing the trim in macs versus windows. http://www.bit-tech.net/hardware/apple/2010/07/01/mac-ssd-performance-trim-in-osx/1
Most people here have not understood, why TRIM is needed in the first place. Okay, let me get this straight: There are two types of SSD drives, NAND drives and NOR drives. I will focus on NAND drives. A NAND drive consists of many tiny NAND gates, each gate stores one bit. Initially all gates have a value of 0 (zero). It is no problem to change the value of a gate to 1 (one) and this can be done on a PER BIT basis. So writing a block of data to an area so far unused just means to set gates to 1 where appropriate and leave the rest at 0. The problem is: It is not possible to go the other way round, changing a gate from 1 back to 0. Changing back to 0 can only be done for a BLOCK of gates. A block of gates can be any size, from a couple of KB to several MB. Now how can a SSD drive change a single byte of data within a block of data already in use? Easy, it has to read the whole BLOCK of data, where the byte is located, into its cache, erase the WHOLE block (all bits go back to 0), change the single byte in the cache, REWRITE the whole block. All this to change just one byte. Of course it doesn’t have to write the data back to the same cells it read them before, it can also copy the data from one block to another one, changing the byte on the fly during copy and finally erase the old block; works as good as the other solution.
So can this trick (erasing free space to 0) really work as a trim replacement? YES! Contrary to what people claim here, it can! But it depends a lot on how your SSD works.
E.g. if your SSD tries to be clever, it may not always rewrite a whole block, just because a single byte is changed. It may first look at the block, if the change is possible WITHOUT rewriting. E.g. changing the byte 192 to 206 is possible without rewriting. 192 has two bits set and 206 has the same two bits set + another three not set in 192. The SSD can just swap the three extra bit and that’s it. See above, changing bits from 0 to 1 is possible on a per bit basis, there is no need to rewrite a whole block, unless the “write operation” causes any bit to flip from 1 to 0; *ONLY* in that case a block has to be rewritten. So by setting blocks of free space to all zero, there is no write operation that would every force a block rewrite (a write operation will then be 0 -> 1 or 0 -> 0, but certainly not 1 -> 0). Only a rather dumb SSD would rewrite a whole block even though unnecessary (especially since this degrades the lifespan of the whole drive).
Another reason why this trick might work: As I said at the top, initially all bits are set to 0, remember? Well, if you make a write operation, that sets all bits of a block back to zero, how is this block different to a really “unused” block (one that has been marked unused by trim)? Correct answer: NOT AT ALL! So a clever SSD could automatically mark a block as unused (the same way TRIM does it) the moment it sees that all bytes of a block are now zero, since it makes no difference for the SSD, the controller or the OS; nobody would even notice this change (a kind of automatic TRIM).
BTW, it is rather funny that some people here claim, that overwriting a block by all zeros is bad, because it causes unnecessary write operations to SSD. What do you think does TRIM? It erases the BLOCK, that means it overwrites it with all zeros. The only difference is, that TRIM erases the block and then marks it as unused. Overwriting it with all zeros might cause the block to be erased (the very same thing that TRIM does) and not being marked as unused; but there is no extra write operation (changing a block from all zero to all zero is no write operation, it’s a NOP, a No Operation, just do nothing), there is only a single block erase, the same operation, either triggered by a WRITE or by a TRIM.
There are only three reasons why the trick will not work: First one, you have a cheap SSD that is dumb as toast, thus in won’t recognize all zero blocks and will perform unnecessary block rewrites. In that case don’t worry about you OS X missing TRIM, this SSD will probably die before a TRIM support would have shown an improvement. Second reason, who says that erase free space writes zeros? Ever clicked on security options? There you can select how DATA is to be overwritten and all zeros is just one option. However, these options say they are for erasing data (the Erase button, not the Erase Free Space button), so I have no idea how Erase Free Space actually overwrites the free space (where does it say it uses 0 for that?). Choosing anything but 0 will of course make things a lot worse. And finally, the thing most people like to forget: Your SSD may not be based on NAND, but on NOR gates. NOR gates have a value of 1 by default and can only be changed from 1 to 0; a change from 0 to 1 is only possible for a whole block again. If you have a NOR SSD, you had to overwrite all bytes with 255 and not with 0.
Of course TRIM support is great; the SSDs doesn’t have to be “that” smart anymore, the OS will assist it; there is no need to worry if NAND or NOR (TRIM always does it correctly) and so on. However, claiming that the trick described above cannot work, will not work, or is even bad for your SSD, is partially incorrect or even utterly nonsense. The trick is not guaranteed to work, since it depends on many factors, but it won’t harm your SSD or make things even worse, if they are are already really bad. If your feel you SSD performance has gone to crap, try this trick. Either it will make your SSD better again or it will do nothing.
I don’t know if anybody knows about this, but the hard drive controller that apple used for their SSDs for the new macbook airs said to support a TRIM like feature, while the device itself doesn’t.
To the drive, 0’s look like any other data. I’m afraid this will do nothing other than wear the drive out sooner. Apple needs to support TRIM to make their SSDs go faster.
Best,
John
Confirmed, it’s work for me: Intel X25 160gb
Only software for OSX to optimize SSD is disktester, which will recondition the drive.
http://diglloydtools.com/disktester.html
After speending hours for tweaks this blog was best i found.
1st link is follow up from previous post, you should read both links.
http://blogs.nullvision.com/?p=357
http://blogs.nullvision.com/?p=275
Good luck!!!
DUMB idea. I did this and this and yep, the zeros are data. Filled my SSD startup disk in no time. Then guess what… OS X would not boot… thanks for wasting 2 hours of my time fixing this, idget. Then again, who’s the bigger idget? The idget, or the idget who follows him? Take a break from good ideas for a few weeks.
Bad idea. Do not run. I did this on my MacBook Air 11.6″ and the process stopped working in Disk Manager. Left it for 2 hours but it hadn’t moved, so I had to quit Disk Manager.
I was left with 0KB free. Rebooted and OS X wouldn’t start – Startup Disk is Full. Had to boot into single user mode and delete stuff I would rather not have.
Why would this slow a drives performance? Shouldn’t it speed it up considering it is easier for a drive to write over 0’s than to write over existing data? Remember when you delete something by default, it’s not truly deleted it’s just marked as an area that can be written over. Maybe I have a misunderstanding of how SSD works, but I do not see how this could negatively impact performance, drive lifespan perhaps.
Regarding native TRIM support and necessity, with Apple moving in the direction of all flash-memory, if it was a needed feature don’t you think they would prioritize development? This is what makes me skeptical that it is needed at all.
Paul: Welcome glade to help!
douz: I’m not entirely sure why, I just know that zeroing out and a large “secure empty trash” slows my drive down.
Now what I think what it does is it creates a file of the exact same size of the free space and writes the zeroed out data to that, then saves it over the free space. So now the OS instead of recognizing the free space as an area to write over it has to contend with the zeroed out file. (This is just my theory of what goes on, I’d love to see an article with the specifics.)
I tried this for you guys because I was meaning to reformat anyway. Now instead of instant off I get a loading symbol for about 10 seconds before shutdown, also boot up went from 15sec to 46. Apps still seem snappy starting though. I pretty much expected this, oh well no harm done to me.
Anyone else I wouldn’t try it.
Everyone, thanks for the comments and suggestions.
Joseph, thanks for trying it out and reporting the results, I will update the article with a warning regarding your findings.
Roy, James, dougz, Peter:
* TRIM doesn’t spread writes across the drive. TRIM tells the drive that a given block is no longer in use by the file system. When a file is deleted, TRIM commands are sent to the drive for the blocks that the file used to occupy. Normally, the drive doesn’t know when a file is deleted, hence the invention of TRIM.
* All SSDs do wear-leveling, over-provisioning, and block-management. Enterprise drives do more over-provisioning, so as to increase lifespan/reliability. Over-provisioning means that (for example) your 100GB SSD has 120GB of flash inside it.
* OS X doesn’t support TRIM because Apple hasn’t gotten around to it. All (TRIM-enabled) SSD’s benefit from TRIM, but you may not notice the benefit unless you’re stressing (and benchmarking) the drive.
* You can test the effectiveness of TRIM (or this trick) without destroying a drive, in the same way you can test a disk defragmenter without destroying a drive. But yeah, every write to an SSD consumes some of its lifespan.
* Poor man’s TRIM consists of (1) back up the drive, (2) reformat the drive (it must receive the ATA format command), (3) restore the drive.
there is quite literally no way to test this or benchmark the performance without excessively wearing out a drive
i really dont see a point to do either, do this if you need to zero out data but don’t bother trying to benchmark to see if it behaves like TRIM would unless you want to prematurely shorten your SSD life due to the immense amount of read & write required to benchmarks
Kinda misleading calling this a TRIM substitute, I think what this fixes is the slowdown you get from deleting a large amount of files, or going from almost full to partially full. This is probably just a way to free up the blocks instead of re-formatting and reinstalling the OS.
What I want to know is: Isn’t secure delete the same thing? I know all too well not to do that on an SSD though.
Mac OS X doesn’t need TRIM, they would have included an update if it did.
So this trick is not necessary, and it only mimics the idea of TRIM and not the function itself. It is good for drive security however, making data very difficult to recover.
I would say if it’s needed Apple would include it.
You sir… are an idiot!
Many new SSD’s i.e. from Intel or OWC’s Mercury Extreme Pro (Sandforce chipset) no longer require TRIM support as the drive’s internal circuitry does it automatically independent of the OS. It’s called Wear Leveling and Block Management or Over Provisioning. OWC sells another SSD drive style called Mercury Extreme Pro RE that has 28% over provisioning intended for RAID SSD configurations. The normal OWC SSD only has 7% over provisioning.
Not so sure that zero’ing out the empty space is the same thing that TRIM does.
Nor do we know if Apple’s implementation for the new MacBook Air’s SSD includes wear leveling, block management or over provisioning.
This ‘tip’ is the last thing I’d do on an SSD drive.
TRIM minimize writes to SSD drives as well as spreading the areas it’s writing to over the entire SSD drive.
Doing the ‘Erase Free Space’ causes more writes to be performed to the SSD, which is exactly what you want to avoid.
Not recommended.
I allow, number of writes are counted, bad idea
Makes sense to me, but I am not sure how to test this beyond a lot of read/write and deletion
This tip likely does nothing.
TRIM tells the drive that there’s no data in a particular block. Erasing writes zeroes there, which the drive interprets as real data. Knowing the absence/presence of data is what makes TRIM work.
Has Curt verified that this tip works (via an experiment)?