Enabling TRIM Support on OSX

Getting an SSD is probably the single most amazing thing that ever happened to my personal computing experience. It made my Mid-2010 MacBook Pro 13" something from an OK experience, to a 1st class experience. The system boots fast, Applications load faster, and I'm much more productive.

One thing that's important in the SSD life is TRIM support. TRIM, in short, is the garbage collecting that is needed to clear deleted data on your SSD.

To go into more detail, When the operating system deletes data off of the hard drive, the SSD doesn't actually clear the bits for that data, it just removes it from the allocation table. The TRIM command is sent from the Operating system to eventually clear those bits and make them ready to be written to again.

If TRIM wasn't available from the operating system, eventually the SSD will be slow because the SSD would need to find free bits, and then clear them.

Wikipedia article on TRIM

Fortunately most modern Operating Systems do support TRIM, (Windows 7, and OSX 10.7). The problem with OSX is that its not enabled by default, unless it was an apple branded SSD.

I got an OCZ Vertex 2 120 GB SSD, and when I went to check for TRIM support after a re-install, TRIM was not supported (You can see this by going into About this Mac > More Info > System Report > Serial-ATA). You can enable this but it requires a reboot and some terminal work.

There is a good article from this website.

They point to a document but there was an issue with the way the quotes work, so Ill post the commands here, but just for the sake of completeness you can find the document here.

First backup the file in question:

sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /IOAHCIBlockStorage.original

Now time to use perl to modify the file:

sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00).{9}(\x00\x51)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

Clear the kext caches:

sudo kextcache -system-prelinked-kernel

sudo kextcache -system-caches

Now reboot your Mac.

Now you should see TRIM support as Yes.