I’ve been reading a few articles lately about changes you can make that might help extend the life of a solid-state drive (specifically, a MacBook Air or MacBook Pro SSD). I’ve put together a list of some of the more useful tweaks I’ve found below, so maybe you can get some benefit from them too:
Disable the sleepimage
If you own an Apple laptop, every time you put it to sleep or close the lid, the contents of RAM get dumped straight onto the disk drive, into a file called /var/vm/sleepimage. The idea behind this is that if your battery dies while your laptop is sleeping, you won’t lose any of your work, because everything will already be persisted to disk.
This sleepimage file will be exactly as big as the amount of RAM you have, typically several gigabytes. If you have an SSD, where space is a premium, the sleepimage file can eat up quite a bit of your storage. Also, every time you put your laptop to sleep, you’re performing a huge disk write, and many think that this can wear away on the effective life of your SSD.
There are a couple of tweaks for this, so fire up Terminal and execute the following commands:
# this will deactivate the hibernate-to-disk behavior. be aware that by invoking this
# command, if your battery runs dry while your laptop is sleeping, any unsaved work
# will be lost
sudo pmset -a hibernatemode 0
# this removes the huge sleepimage file
sudo rm /var/vm/sleepimage
# setting hibernatemode to 0 doesn't seem to be foolproof after recent software
# updates, so this command will ensure that a sleepimage file is never written
sudo pmset -a hibernatefile /dev/null
Disable local Time Machine backups
If you use Time Machine for your backups, you may have noticed that OS X will still record filesystem changes, even if you don’t currently have a Time Machine connected. This gives you some peace of mind in that you can recover recently-lost files even if you haven’t backed up to Time Machine lately. The downside is that this can eat up a sizable chunk of disk space, and will also perform a lot of unneeded SSD writes. If you’re comfortable with your external backup plans, and want to save some disk space, execute:
# disable them local Time Machine backups
sudo tmutil disablelocal
# if you decide you want to turn them back on, just run this
sudo tmutil enablelocal
Use TmpDisk for fun and profit
TmpDisk is a nifty little utility I discovered a while back, but I struggled to find a real use for it. That is, until I read a blog post which suggested that you can improve your Chrome performance and spare your SSD some writes by having it cache to a RAM disk. So fire up TmpDisk, use it to carve out a chunk of your RAM and mount it as a disk, and then make the following changes in order to get Chrome to start caching there:
# navigate to where the actual Chrome binary lives
cd /Applications/Google Chrome.app/Contents/MacOS
# drop the following shell commands into a temp file
echo '#!/bin/sh' >> TEMPFILE
echo 'exec /Applications/Google\ Chrome.app/Contents/MacOS/chrome --disk-cache-dir="/Volumes/RAM/" $@' >> TEMPFILE
# rename the Chrome binary
mv Google\ Chrome chrome
# rename the temp file
mv TEMPFILE Google\ Chrome
# adjust the permissions
chmod a+x Google\ Chrome
Shoutouts
I read a lot of informative blog posts in order to put these tips together, so I’d be remiss if I didn’t mention them here: