MacOS – How does TRIM Enabler work

macosssdthird-partytrim

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)?

Best Answer

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