How does TRIM Enabler work?
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)?
Solution 1:
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:
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
Solution 2:
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.
Solution 3:
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.