How to Check and Enable TRIM on a Mac SSD
You probably know that solid state drives (SSD) differ from Hard Disk Drives (HDD) in how they store information, and you may have heard that something called TRIM can maintain their performance.
In this tutorial, I’ll not only show you how you can enable TRIM support for your SSDs, but also understand what the term means and how it fits into the functionality of solid state storage.
Screencast
How to Check and Enable TRIM on a Mac SSD
SSDs vs. HDDs
You’ve probably heard that SSDs have a lifespan, and that you can prolong that lifespan by enabling something called TRIM. This is broadly true, and I will show you how to check for and enable TRIM support on your drives, but first it’s important to take a step back and understand what we’re talking about.
An HDD encodes data onto a magnetic coating on a spinning disk inside the drive.
An SSD, on the other hand, is just a network of flash memory cells assembled into a drive enclosure, meaning it has no moving parts. It’s like having a series of very high performance USB keys squished into a box.



The advantages of SSDs are clear: they’re exponentially faster, they’re entirely silent, they’re more durable, and they’re immune from issues like fragmentation.
As with any new technology, they were fairly rare until recently because of their high prices. But now that those prices are dropping, SSDs come standard on most new computers, and even more people are replacing their old hard drives with modern solid state alternatives.
Expiry Data
This leads me to address the elephant in the room, which is longevity. Because flash memory cells can only be written to a certain number of times, solid state drives technically have a limited lifespan, moreso than their disk drive predecessors.
This is often blown way out of proportion though, so if you’re feeling panicky about this, consider the following: even with heavy usage, it would take you more than ten years to wear out your average solid state drive. You’re far more likely to replace your computer first.
Nevertheless, there are ways to maximize that lifespan, and that’s where TRIM comes in.
To understand what TRIM actually does, you first need to understand just a bit about how solid state drives actually store information.
Pages and Blocks
Any file on your computer is just a collection of data, and a solid state drive writes that data onto a series of pages, each of which is assembled into a number of blocks. Blocks and pages are the fundamental structure of data storage on SSDs.



Every file on your computer has a number of these blocks reserved for its use. The problem is that SSDs can only write new data to empty regions—they can’t overwrite data directly like hard disk drives can.
Further, SSDs are unable to delete individual pages of data. They can write new information at the page level, but old data can only be deleted at the block level.
It works a lot like an Etch-a-Sketch. You can doodle wherever you want on the Etch-A-Sketch when it’s blank, and keep doodling until the screen is full. But at that point, if you want to draw something new, you have to shake the Etch-a-Sketch and erase the entire screen—the Etch-a-Sketch is like a block of data on your SSD.
This means that when only some of the data pages in a block become outdated, they can’t be selectively deleted. Instead, the SSD moves all the good pages into a brand new block and the old block is erased, making room for future data.
Taking Out the Trash
Running a computer means lots of writing and rewriting of data, so SSDs have to constantly move blocks around to consolidate the valid data, and delete invalid blocks to keep plenty of empty space available for when it’s needed. This process is known as Garbage Collection.
When you delete a file on your computer, the operating system doesn’t actually remove any data, it simply removes the virtual link between the former file and where its data was stored on the drive. This is how a basic deletion and creation of files works on an SSD.
Stage 1



This hypothetical situation starts out with four files on your harddrive.
As far as you’re concerned, they could be any kind of file at all, of any size. From the SSD’s perspective, each file is just a series of data pages that are written together within a single data block. In most real-world cases, files are large enough that each one takes up multiple blocks, but this is a simplified view.
The pink cells at the bottom of the data block are empty, meaning that new data could be written to those pages. Now delete File C.
Stage 2



On my Mac, File C is now gone—I can’t see it anymore. The data on the SSD remains entirely unchanged though.
File C’s data is still written to the same pages, and the only thing that’s different is that the operating system’s reference for where to find File C’s data has been deleted. The data itself is now useless, but the SSD remains oblivious and keeps it there.
At each stage in this process, you need to remember that the drive is performing Garbage Collection periodically. Each time a Garbage Collection cycle runs, the SSD takes the entire data block and re-writes it in a different area of the drive in an effort to keep valid data consolidated and empty space available in large chunks.
In other words, the block is copied exactly as is and pasted to a different part of the drive. Then its original location is erased, ready for new data.
Because the drive has no idea that File C’s data is now invalid, it copies all of those useless pages as well. Now I’m going to make a new file.
Stage 3



At this point, I have created File X.
Now that File X has taken the place of File C in the operating system, the SSD knows that File C’s data has become invalid and it marks those pages for Garbage Collection.
Meanwhile, two of the free pages in the block have been used to write the data for File X. When the next Garbage Collection cycle runs, the data will be copied to a new block as usual, but this time the pages where File C used to live won’t be moved, and the data for File X will take their place.
The actual data for File C will finally be erased as the original block location is wiped clean.



Introducing TRIM
As you can see, the inability of SSDs to directly overwrite anything makes it more complicated for them to manage data.
Without knowing when old file data becomes invalid, SSDs expend a lot of write cycles ferrying useless data around. This not only causes normal file operations to slow down, it also means more reading and writing to the flash cells, diminishing their lifespan unnecessarily.
Tip: You may have noticed that even though you buy SSDs of a certain capacity, you have much less space actually available to use. A typical 256GB SSD will have only about 240GB available for use, for instance.
The reason is that SSD manufacturers set aside a percentage of the drive’s space for the firmware to use as a buffer for Garbage Collection and other maintenance tasks. This is called Over-Provisioning and it’s necessary for making sure that the drive’s performance doesn’t degrade significantly as it fills up.
As a general rule, the more free space there is on an SSD, the better it will perform.
By default, SSDs have no way of knowing when files become invalid, and this is where TRIM comes to the rescue.
TRIM is a command that the operating system sends to the SSD telling it which data has become invalid. Using this information, the SSD can perform its Garbage Collection more efficiently, and reduce the strain on the hardware.
Using my example from before, this is an illustration of the same file management scenario, except with TRIM enabled this time around.
Stage 1



Everything begins the exact same as before, with four generic files being written into pages of a data block on the SSD.
Stage 2



This time around, as soon as I delete File C, the operating system tells the SSD that those data pages have become invalid, so they’re marked for Garbage Collection immediately.
Stage 3



As a result, by the time I write File X to the drive, Garbage Collection has already cleaned out the slots where File C used to be and I’ve saved the SSD some needless writing and rewriting.
Making it Work for You
If it seems like a relatively small improvement, just remember that my example is a simplification of the full process and that SSDs have to deal with millions of data blocks shuffling around—it adds up quickly!
Now that you have a sense of what TRIM does and how it can help prolong your solid state drive’s lifespan, ensure it’s actually working on your machine.
If you bought a Mac with an SSD installed from the factory, then TRIM is enabled by default and you’re all set—nothing to worry about.
If, on the other hand, you later added a third-party SSD to your system, then TRIM will be disabled by default. If you aren’t sure, the best thing to do is double-check
Step 1: Check TRIM Status
To see whether or not your SSD has TRIM enabled, you need to access a tool called System Information (also known as System Profiler on older versions of OS X).
The easiest way to access it is to click the Apple menu while holding down the Option key on your keyboard.
Find the SATA section in the menu and locate the hard drive you want to enable TRIM on. In the description, you’ll see a line telling you whether TRIM support is present or not.



Step 2: The TRIM Enabler Utility
If yours says no, then it’s time to open Safari and download a utility that allows TRIM to be easily turned on and off. You’ll find it at
http://www.groths.org/software/trimenabler/
The free version is all you need, so download and install it as you would any other app.



Step 3: Turn it On
Once you’ve installed it, open it up and simply flip the switch from Off to On. Once you’ve done that, you’ll need to reboot your computer, after which TRIM will be enabled on your drive!

To make sure it worked, open up the system report again and verify that the TRIM Support line now reads Yes.
The Hard Way
If you’re wondering, it is possible to do this by hand using the Terminal, but the commands are a little frightening. Essentially what you’re doing during this process is patching a low-level system file to allow TRIM to function with your SSD.
Step 1: Safety Net
Just to be on the safe side, back up the file we’ll be modifying. Copy the following into a new Terminal window and hit Return (the Enter key).
1 |
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 |
You’ll be prompted to enter your administrative password, so type it in and press Return once more. Note that Terminal will give you no indication that it’s registering your key presses as you type your password, but it is listening so don’t worry.
Step 2: Patch the File
With the file safely protected in case of mishaps, it’s time to use the following command to modify the kernel extension in a way that activates TRIM.
1 |
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage |
Step 3: Refresh the Kernel Extension Cache
To make the changes take effect, you should manually refresh the kernel extension cache.
1 |
sudo touch /System/Library/Extensions/ |
Once that’s done, quit Terminal and reboot your Mac. When it restarts, you should be all set.
Conclusion
If you plan on adding more SSDs to your system, you should keep the TRIM Enabler utility installed so you can easily activate TRIM on them. Otherwise, you can feel free to delete it as it isn’t required for TRIM to stay active.
Nowadays, TRIM is only one of several methods that manufacturers use to keep SSDs running at peak efficiency. It may not be necessary to have on, but it doesn't hurt, and the more optimized the data is the better your SSD will perform, so it's almost always worth keeping on.
Now you not only know how solid state drives work, you also understand how TRIM helps them run at peak performance for longer!
References
- Terminal instructions sourced from DigitalDJ, written by Grant Pannell