Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I recently bought a third part (OCZ) SSD and used Trim Enabler to, well, enable TRIM. I've noticed that some software updates can cause TRIM to be disabled, and have thus been curious about how TRIM Enabler works.

  • Does it replace some default KEXT with a custom one to support TRIM or does it simply toggle some PLIST setting?
  • Either way, is there a file that, when locked, can ensure that TRIM remains enabled (without any negative consequences)?
share|improve this question

3 Answers 3

up vote 8 down vote accepted

The Trim Enabler patches the following Kext-File

/System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

which checks if the ssd is a 3rd-party or Apple Branded SSD:

IOAHCI hex/ascii view

you can also enable trim manually by looking for all 'Apple' occurrences in the file and patching them in a hex-editor or via terminal:

##1. Backup old file
    $sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
/System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original

##2. Patch the file to enable TRIM support
    $sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\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

##3. Clear the system kernel extension cache

   $sudo kextcache -system-prelinked-kernel

   $sudo kextcache -system-caches
share|improve this answer
1  
How do you even find this stuff?! If I run TRIM Enabler to "patch" my IOAHCIBlockStorage file and then lock it (with admin privileges), would I suffer any adverse effects? Sure I wouldn't be able to support the new PCIe SSDs (which my MacBook doesn't even have), but would it prevent any future updates from reversing the patch? –  XAleXOwnZX Jun 16 '13 at 5:19
    
my best guess: even if you lock the file from editing.. the updater would just replace the file completely with a new file. You would had to remove write permission for root from the complete folder. In that specific case I assume the installer will fail as it can't write to the folder. In my opinion it's not worth the trouble. Just start Trim Enabler after an update and re-apply the patch. –  Chrisii Jun 16 '13 at 6:42
    
Okay, thanks for the advice! :) –  XAleXOwnZX Jun 16 '13 at 17:17
    
Great answer man. –  Woodstock Sep 15 '13 at 11:48
    
@Chrisii do you know if this will work in Yosemite? Does it change kext signing? –  thepen Jan 7 at 7:24

The only information I can find on this is from an FAQ / blogpost entry

A: Trim Enabler patches a native OSX Trim driver, which works in the background even when the app is closed or removed. This patch is reset on system updates, so it might be a good idea to keep the app however.

share|improve this answer
    
The path is usually reset on updates when Apple decides to update the mentioned kernel extensions for example to support new ssd drives (Thinking of the new ppcie ssds announced at WWDC). –  Chrisii Jun 16 '13 at 1:57

OCZ SSDs use a Sandforce controller which has built in foreground garbage collection that delays the need to erase blocks, reducing but not removing the need for TRIM support. Trim can be considered an aid to garbage collection.

Trim VS Garbage Collection

For the short explanation flash memory is organized in groups of pages where data can be written. Once a page is written, it cannot be rewritten until it is erased. But a page can only be erased within a group of typically 128 pages called a block. The complexity of writing data really starts to escalate in the case of random writes replacing previously written data. Random writes put the new data in previously erased pages elsewhere, peppering a block of valid data with “patches of invalid data.” In order to write new data to these patches, the whole block – all 128 pages – must be erased. But first all surrounding pages with valid data must be read and then rewritten to blank pages. The newly erased block of blank pages is then ready to save new data.

[…] All NAND Flash-based SSDs use GC. Some use foreground GC and some use background or idle-time GC. The difference between them is covered in my blog http://blog.lsi.com/dont-let-ssds-throw-away-your-gold/ . In simple terms background garbage collection will increase write amplification (WA) and wear out the SSD sooner. Foreground GC is harder to achieve and I believe only the SandForce controller is able to do it today

[…] TRIM is beneficial to all SSDs regardless of what kind of garbage collection is used. I talk about how TRIM came into existence and why it is necessary in my blog http://blog.lsi.com/did-you-know-hdds-do-not-have-a-del… . The TRIM command is sent by the OS to the SSD to identify what pages of data can be ignored during garbage collection. The SSD cannot tell what files have been deleted until the OS uses the same sectors to store new files, but by that time the SSD has already wasted cycles by garbage collecting data that was invalid, but known to the SS.

Did you know HDDs do not have a Delete command? That is why SSDs need TRIM

Keeping your SSD TRIM A number of years ago, the storage industry got together and developed a solution between the OS and the SSD by creating a new SATA command called TRIM. It is not a command that forces the SSD to immediately erase data like some people believe. Actually the TRIM command can be thought of as a message from the OS about what previously used addresses on the SSD are no longer holding valid data. The SSD takes those addresses and updates its own internal map of its flash memory to mark those locations as invalid. With this information, the SSD no longer moves that invalid data during the GC process, eliminating wasted time rewriting invalid data to new flash pages. It also reduces the number of write cycles on the flash, increasing the SSDs endurance. Another benefit of the TRIM command is that more space is available for dynamic OP.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.