Optimizing Mac OS X for SSD drives

Updated for Lion 2011-07-21

SSD drives are very good speed wise. If you have the money, upgrading from a regular hard drives makes a world of difference. There are however some drawbacks compared to spinning hard drives, mainly the limit on how many writes you can do before things get ugly. For most users, this isn’t a problem. But it doesn’t hurt to take some steps to minimize the disk writes.

These tweaks are for Mac OS X 10.6 (Snow Leopard) and 10.7 (Lion) and mainly for laptop users.

1. Sleeping mode
By default, when closing the lid on a MacBook, the content of the ram is saved to disk for safety. The ram is still powered on however, and is used when starting up again. The content saved on disk is only used in case of a power loss. This behavior can be changed, at the cost of some safety, so that memory content is not saved to disk. On the bright side, you also save some disk space (equal to the amount of your RAM).

We can start by checking the current setting, fire up Terminal.app and type the following.

$ sudo pmset -g | grep hibernatemode
hibernatemode	3

3 is the default mode, we want to change this to 0 to disable disk writes.

$ sudo pmset -a hibernatemode 0

Now we can remove the old sleepimage.

$ sudo rm /var/vm/sleepimage

macworld.com has more information on this.

2. Hard drive sleep
Putting SSD hard drives to sleep has no benefit, and some SSD drives has a history of freezing up when put to sleep. This can be disabled under System Preferences -> Energy Saver. Remember to disable it for both Battery and Power Adapter mode.

3. Sudden motion sensor
Having the Sudden motion sensor enabled for a SSD drive makes no sense, this can be disabled with the following command.

$ sudo pmset -a sms 0

4. Enable noatime for SSD filesystems
Every time a file is accessed its access time is modified to reflect it. This can be disabled to save additional writes. To do this for the local filesystem create the file /Library/LaunchDaemons/com.noatime.root.plist with the following content.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.noatime.root</string>
        <key>ProgramArguments</key>
        <array>
            <string>mount</string>
            <string>-uwo</string>
            <string>noatime</string>
            <string>/</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>

This will execute mount -uwo noatime / upon system startup, remounting the root filesystem with the noatime option. This can be verified after a reboot with the following command.

$ mount |grep noatime
/dev/disk0s2 on / (hfs, local, journaled, noatime)

Note on FileVault: The instructions below are for legacy FileVault only. FileVault 2 users (Lion) doesn’t have to do anything special except the instructions above. Please see Apple article HT4790 on how to upgrade from legacy FileVault to FileVault 2.

For FileVault users as myself it seems to be a little bit trickier. The FileVault filesystem can’t be remounted at startup, since it’s not mounted until the user logs in. We can however create a script and a login hook to be run at login.

Lets start by creating a script called /usr/local/bin/remount_noatime with the following content.

#!/bin/bash
/sbin/mount -uwo noatime /Users/$1

$1 will contain the username when the script is run. Make it executable and create the login hook.

$ sudo chmod +x /usr/local/bin/remount_noatime
$ sudo defaults write com.apple.loginwindow LoginHook /usr/local/bin/remount_noatime

The script is now run with root privileges when a user logs in.

5. Disable Spotlight
If you’re not using Spotlight you should consider disabling it by running this command.

$ sudo mdutil -a -i off

I’ve been using the above settings (except #5) for about 6 months now without any issues.

  • Adam Hulin

    Using sleep on a SSD actually lower its power consumption quite a bit, the Intel X25-M draws less than half during sleep. It also doesn’t need a lot of time to spin itself up again like a regular harddrive.

    Still the difference in power consumption may not be worth to talk about when it’s just ~100mw ;)

  • http://www.emilvikstrom.se/ Emil Vikström

    noatime can be safely disabled on all writable drives, both SSD and HDD. It’s almost always pointless to do a disk write each time you open a file – it slows down the computer without any benefit.

  • http://twitter.com/andriijas Andreas

    If you have optibay and ssd+hdd you can put the sleepimage on your hdd instead.

    I use spotlight only for apps – have disabled it for everything else. find & grep ftw.

  • Drew

    Andreas, moving the sleepimage to my HD is exactly what I’d like to do – got a pointer on ow to do that?

  • Fredrik Poller

    @Drew I’m guessing the following should work

    sudo pmset -a hibernatemode 0
    sudo rm /var/vm/sleepimage
    sudo touch /Volumes/HDD/.sleepimage
    sudo ln -s /Volumes/HDD/.sleepimage /var/vm/sleepimage
    sudo pmset -a hibernatemode 3

    Replace HDD with the name of your other hard drive. This will create a link to the new hybernation file.

  • Rob

    hi and thanks for this guide. one question:
    I have two separate partitions for / and /home.
    I applied this tweak for / and it works, but I can not get it to work with /home :(
    Any suggestions?
    I just created another plist file in LaunchDaemons where I changed the string “/” in “/Volumes/Rob”, like this:

    original..
    -uwo
    noatime
    /

    modified..
    -uwo
    noatime
    /Volumes/Rob

    but after putting the second file in LaunchDaemons and rebooting, than if I run “mount” from terminal “noatime” disappear also from the root partition!!

    please help, thanks :)

  • Bigvoice

    Hi Fredrik,
    Thanks for the tips! I’ve recently installed an OWC SSD in my MBP and I get kernel panics when trying to wake from ‘hibernation.’ When I try to change this in Terminal with TIp number 1 above, I enter: “$ sudo pmset -g | grep hibernatemode”
    “I get: “$: Command not found.”
    Any ideas?
    I am not very familiar with Terminal.
    Thanks!

  • Paul Bourneau

    $ sudo pmset -a sms 0

    =

    -bash: $: command not found

  • http://poller.se/ Fredrik Poller

    Hello!

    Does ‘/usr/bin/pmset -g | /usr/bin/grep hibernatemode’ work? What does ‘echo $PATH’ report?

  • mark james

    Tried this out, and it is too extreme. I will report back after more testing. First, my machine now takes 30 seconds to sleep. And, it now kernel panics when I remove a disk from a mirror for travel. Most users do not mirror their laptops, but for those that do, ouch. ;-) I am guessing disabling VMRAM causes the slow sleep. Surprised no one mentioned this already.

  • http://poller.se/ Fredrik Poller

    @markjames

    In hibernatemode 0 the ram is kept powered on during sleep
    In hibernatemode 3 the ram is kept powered on during sleep AND the ram content is saved to disk

    If anything, changing hibernatemode to 0 should speed things up.

    For the mirror issue; you’re on your own mate ;-)

  • Ian Kennedy

    Don’t enter the $ it’s not part of the command.

  • http://poller.se/ Fredrik Poller

    You’re right, good catch

  • Pingback: OCZ Vertex 2 SSD « tlohg | gholt

  • Silent Knight

    Thanks for the info. But just in case something really wrong happens, can you please also post how to reverse this? Sorry! A newbie obviously.

  • Silent Knight

    Hi Fredrik,

    I’m having some trouble here since after I did No. 2 (Sleep), No. 3 (Sudden Motion Sensor), and No. 5 (Disable Spotlight), I’ve been having kernel panics. So I tried to reverse it by changing No. 2 in Systems Preferences, No. 3 with “sudo pmset -a sms 1, and No. 5 with “sudo mdutil -a -i on”. Now things have gone from bad to worse as I can’t boot into my computer. As soon as it gets to the desktop, MacOSX does the curtain down thingy and asks me to Hold Onto the Power Button to Shutdown. I’m a newbie here so I practically guessed how to reverse the above 3 commands. Did I do it wrong? Thanks a million!

    Silent Knight

  • http://poller.se/ Fredrik Poller

    I’m sorry this didn’t work out for you. If you did reverse the settings and are still getting errors, I’m not sure what to do.

  • Pingback: links for 2011-02-02 « Bloggitation

  • Anonymous

    so is it correct that the “recent files” feature of OSX does NOT use this time?

  • SRGB

    I’m currently awaiting an OWC 120GB SSD from the States, so these tips are great. Two questions regarding the sleepimage: you replied earlier that those with the optibay should be able to move the sleepimage to the HDD rather than the SSD – can anyone confirm this works? I’ve read (I think at MacOSXHints.com) that the sleepimage MUST be on the system drive for it to work. If it does work with the optibay mod and an HDD, can anyone confirm whether it works (or would work) with an Express/34-based SSD? I’m thinking of using a cheap flash storage device (SD card probably) for temporary data such as caches and the sleepimage.
    Thanks! :)

  • http://twitter.com/agarwal_anuj Anuj Agarwal

    Thanks for the tips. On my Macbook Air boot time went up from 14 seconds to 21 seconds when i made these changes.

    I suspected the increase was due to the extra launchdaemon to turn on noatime so i deleted that plist file and boot time went back to 14 seconds.

  • Darthvim

    i have got an optibay. so i’ve got one ssd and hdd. how can one deactivate the second hdd to wake up after sleep , does anybody know ?

  • Johan

    Hi! I bought a MacBook Pro a year ago where told the store, after they recommended it if I wanted a faster system but still a lot of disc space (that I asked for!) aoptibay and a SSD.
    From the start I had problems that when the battery started to be used up: the computer went to sleep mode to late. before it had written over the RAM it went dead and everything was lost. Sometimes I actually lost everything. And two times I even had to reinstall the system since it wouldn’t start again – ut was only the questionmark.
    Very frustrating!
    The first three times I went back to the store they said they couldn’t find anything wrong. The last time I stood there and showed them the problem since that’s what they obviously needed to see.
    They then changed the place of the HDD and the SSD.
    now it works a little, little better: it alteast goes down to hibernation-mode. But it take a while to start it up, and it frooze big time yesterday.
    Since they can’t help me, I hope you can: How can I make the computer to (without closing it) to go to sleep earlier so the say when it’s 3% left of the battery instead of 1% 0ch 0% so it have the time to save the RAM before the battery dies. In that way I hopefully have more then my 10 seconds to find a charger or maybe lose all the windows I have open and need to restart it once again.
    That would be so helpfull.
    Tack!

  • Pingback: Simon Fredsted» Blog Archive » MacBook Pro SSD and Optibay experiences

  • http://poller.se/ Fredrik Poller

    I’m sorry, I have no idea how to accomplish this. But if you change hibernatemode to 0 (don’t write to disk), the sleep process should be much faster.

  • Guest

    Disabling spotlight caused my Appstore not to work, took me some time to figure this out. I won’t be using that tweak anymore ;)

  • http://poller.se/ Fredrik Poller

    In that case I wouldn’t recommend this tweak either :)

  • Pingback: noatime for SSD? - Mac-Forums.com

  • Pingback: Tips to manage OSX in a SSD/HD setup - MacNN Forums

  • Pingback: links for 2011-07-21 | neunzehn82

  • Klide545

    I absolutely cannot get noatime to enable and I’m not using filevault.

    I have a .plist file in Library/LaunchDaemons called com.noatime.root.plist

    within that file there is the following code -

    Label
    com.noatime.root
    ProgramArguments
    /Library/LaunchDaemons/com.noatime.root.plist
    mount
    -uwo
    noatime
    /

    RunAtLoad

    And as some sites suggested I assigned read and write privileges for everyone on this file and ran the following in terminal -

    sudo chown root:wheel /Library/LaunchDaemons/com.noatime.root.plist 

    after restarting, when I submit the command: mount , I receive the following 

    /dev/disk0s2 on / (hfs, local, journaled)
    devfs on /dev (devfs, local, nobrowse)
    map -hosts on /net (autofs, nosuid, automounted, nobrowse)
    map auto_home on /home (autofs, automounted, nobrowse)

    I am running this SSD on a 13″ MBP 2011. It is the sole drive with OSX version 10.6.8, fully updated. The SSD is an OCZ Agility 3.

    Any help would be greatly appreciated,
    Thanks

  • Edjenn1998

    will noatime mess with time machine? I was told that time machine works off of time date stamps and by doing noatime it won’t be able to work right. 

  • http://poller.se/ Fredrik Poller

    I think Time Machine only looks at modification time. If anything, noatime should speed up Time Machine backups.

    I haven’t tested so I can’t say for sure, if it doesn’t work you can always revert the changes.

  • Edjenn1998

    Ok. I’m willing to try it, but every time I try to create the file os x say I don’t have permission. code 5000 or something.  Can you give a step by step guide. Because nothing I’ve tried has worked.  what are you using to create the file? I tried text wrangler and it wouldn’t work. ca n you please help?

  • http://poller.se/ Fredrik Poller

    You can try the following

    Create the file on your desktop and run the following commands in Terminal.App

    sudo mv ~/Desktop/com.noatime.root.plist /Library/LaunchDaemons/
    sudo chown root:wheel /Library/LaunchDaemons/com.noatime.root.plist

    Enter your password when prompted.

  • verngall

    I have an SSD in the optibay and a HD in the main bay
    can I enable your recommended settings for the SSD only (and keep SMART and the motion sensor enabled for the HDD) ?

  • http://poller.se/ Fredrik Poller

    I recommend that you keep the SMS enabled.

  • Aaron Stewart

    The “$” is the command prompt.  Exclude it when running the command.

    I would strongly recommend that unless you have a real understanding of what these commands do and how to properly use the terminal that you don’t try it.  pmset and other commands above can cause some real issues with your system, so be warned.

  • davidb

    I have the same issue with an OCZ SSD, do you have any further information about that ?

  • Frédéric M

    Note that you must activate the TRIM if you replaced an HD by an SSD.
    Regarding spotlight, and native, and sleeping mode there is no relationship with SSD …!
    sms won’t change anything, so I would prefer leaving it as default. I would be interesting to know this parameter for mac shipped with SSD.

  • Pingback: noelboss » Blog Archive » SSD Festplatten in Lion

  • Pingback: Einbau einer SSD in ein MacBook Pro | Unix-World

  • Ayumi

    Hello, I read this and setup, I seend changes form Momentus XT to Crucial M4 are about 30 seconds, then with trim on and no wait, it’s almost 40 seconds difference in the boot up time. I have made the video so that this settings will work… http://www.youtube.com/watch?v=JcX92KvP1sQ

  • http://www.facebook.com/kschwerin Keith Schwerin

    I have the same problem. as above.

  • KRMax

    Another item that can be very useful is moving the swapfiles to a different partition / disk on the system as described here:
    http://superuser.com/questions/28414/moving-the-swapfiles-to-a-dedicated-partition-in-snow-leopard

  • Anonymous

    The only useful tips here are #1 and #2. The rest won’t make a noticeable difference in the performance or lifespan of SSD. You guys have to remember that most 3rd party SSD are warranted for 3-5 years, and are (conservatively) estimated to endure on the order of 5-10 years of write cycles.

    Buy a good SSD with excellent built-in Garbage Collection, skip the TRIM nonsense (which is really a crutch for older-gen SSDs with crappy GC), disable hibernation and drive sleep *IF YOU ARE HAVING PROBLEMS*, and call it good.

    The rest of this is superstition and nonsense.

  • pluckedfromthinair

    When confronted with a post containing such derision and barely-veiled anger, especially in the context of a genuine attempt to allow SSD users to make informed decisions regarding maintaining their newly-purchased devices, one can’t help but feel pity for the poster – are you so unused to having people listen to your opinions that you can’t even offer the decency of a properly-formulated comment detailing exactly why you feel the way you do?  Fredrik Poller offers a simple and common-sense reason for implementing each and every one of the tips he offers here (except for #5, which I think perhaps he should remedy – is it necessary when you’ve already implemented #4?) – why can’t you do Fredrik (and those of us who have come across this page) the courtesy of explaining why you disagree with his conclusions?
    Ironically, by failing to post any such explanations, you ask others to believe you simply by dint of your derision and ridicule – which is less of a reason than is offered for many a superstition, a concept of which you are so scornful.
    Swallow your anger, accept that people might be willing to listen to a reasoned response bereft of emotional mud-slinging, and let us move on from that less-hostile position.

  • Anonymous

    I think you’re reading into my post emotions which aren’t there. I gave a reason why only 1 and 2 are really useful tips (and they truly are, and thanks to Frederik for posting them): the rest won’t make a noticeable difference in either performance or lifespan of the SSD.

    TRIM is absolutely a crutch for crappy SSDs that don’t manage GC themselves. This has nothing to do with Frederik’s post, and is just a general statement based on engineering design principles.

    By “TRIM nonsense” I just meant the general hassle of implementing TRIM for non-Apple SSDs. In fact, the only reason that Apple uses TRIM for their own-branded drives is because they are Toshiba drives in disguise (Samsung on the MBA) and are pretty low-quality when compared to most 3rd-party SSD of current generation (SATA3). The Toshiba drives in particular lack good Garbage Collection, and the Samsung drives aren’t a whole lot better. This has to do with the controller used and the type of NAND flash that comprises the drive.

    I wasn’t implying that Frederik’s post was nonsense. Sorry if you misinterpreted that. Seems like you have some anger issues of your own to resolve.

  • pluckedfromthinair

    “I wasn’t implying that Frederik’s post was nonsense.”  No, that’s true – in fact, you flat-out stated it explicitly: “The only useful tips here are #1 and #2. […] The rest of this is superstition and nonsense.”  Pretty aggressive in my mind, and I suspect in the minds of most of those who would read such a comment.  If you disagree, then perhaps you ought to consider reflecting on what you write before posting it – you may be channelling emotions that you aren’t fully aware of.  Or perhaps you’re just so accustomed to being rude, it comes naturally.  A third alternative is that you really don’t have a good grasp of the English language – or at least of the aspects of the English language you employed here.  
    The proper way to end your original comment (rather than with a pair of insults) would have been to address each of the tips you disagreed with one by one, explaining clearly (and in a similarly understandable fashion as Fredrik has used) how you come to that conclusion.By the way, thank you for apologising for my potential inability to properly comprehend what you wrote.  If you’re incapable of understanding that, “Sorry if you misinterpreted that,” is no apology at all, then you really ought to spend more time in decent social circles.You’re a coward and a proud man, in my opinion – be brave; admit you acted foolishly and apologise properly.I shall not respond again, out of respect for Fredrik and others who navigate here to seek tips on using their SSDs.

  • Anonymous

    You’ll not respond again because your argument has devolved into personal attacks, leaving you nowhere else really to go.

    You did misinterpret my post. Pure and simple. I came here from another forum pointing to Frederik’s list of advice, and as I stated, some of it is useful, and some of it is not. I even state why, though not in some long-winded explanation. The fact that you read aggression into my post seems to indicate you’re projecting your own aggression, and the fact that you can’t seem to let this go confirms it. You wanted to pick a fight over something you misunderstood, and now you’ve got nothing left to do but call me a coward and attack me.

    I don’t owe you an apology, and neither was I trying to give you one.

  • Pingback: neophob.com » SSD Disk AGILITY3 on MacBook, Link Speed issues

  • Pingback: What you really need to know when adding a SSD to your Macbook Pro! « ElectricSproket

  • Birthday

    You are in some serious need of professional counseling! The posters reply was not inflammatory in any way. Windroid, thank you for your response, it is exactly as I have foumd the present state of SSD development.

  • Pingback: Optimize osx | Imagevan

  • SpeedDemon

    After you deleted the plist file, there’s no terminal command to run? I wish to eliminate it, also.

  • Pingback: MAC Book Pro Umbau auf SSD » Webnfoto.com - Andreas Hafenscher - Portrait, Event, Architektur und Tourismus Fotograf in Eisenstadt/Austria

  • Bruce Edge

    Note that disabling spotlight will kill outlook’s search function.

  • cinaeco

    I’d like to add notes about the noatime plist, since it looks like no one’s mentioned it. If you find it’s not working, it could well be a malformed plist, especially if it has been copied from a website.

    First check if the plist is valid using ‘plutil -lint /Library/LaunchDaemons/com.noatime.root.plist’

    If there are any errors, fix them, and try to make launchd load the plist, using ‘launchctl load /Library/LaunchDaemons/com.noatime.root.plist’.

    To check if the loading worked, you can run ‘mount’ or ‘launchctl list’ (which should show com.noatime.root somewhere)

  • http://twitter.com/joshfofer Josh

    Check out SmartSleep, it will solve your issues: http://www.jinx.de/SmartSleep.html

  • http://www.facebook.com/david.apariciocampos David Aparicio Campos

    In case you keep the HDD disk in addition to the SDD disk (with OWC DataDoubler or similar), I found that I can create a symlink of the swap file in the SDD that points to the file in the HDD, and then I keep the smart sleeping mode 3 while saving my SDD from writings…

    I personally see useful 4 (the most one by far) and tweaked 1 in case you have HDD available in your system. 2 is not very useful in my case as I keep the HDD and do not want to keep spinning always… I am lucky my SDD works with the spin down command.

  • http://tartley.com Jonathan Hartley

    This could be resolved by measurement. If someone’s claiming a particular tip makes a difference, then they should be able to post measured numbers to back that up (e.g. difference in time taken to boot, or compile a kernel)

    If they can’t do that then the tip kinda-sorta *is* superstition, no matter how educated the reasons allegedly justifying it are.

    Publishing such measurements also gives readers the chance to evaluate whether the magnitude difference the tip makes is big enough for them to care about. e.g. If it’s a 50% increase in speed, I’d consider messing with my computer. If it’s a 10% difference, then it’s not worth messing with the defaults in case it has other side-effects.

    I appreciate that the longetivity tips are harder to measure than the performance ones. That doesn’t invalidate the point that without numbers, they are just stirring the pot and guesswork.

  • http://tartley.com Jonathan Hartley

    Thanks for these pointers. I still don’t see noatime in the output of ‘mount’. The “plutil -lint” produced “ok”. The “launchctl load” command completes silently, and the “launchctl list | grep noatime” does produce “com.nullvision.noatime”. But mount does not show “noatime”, and catting a file does update the atime stamp (as reported by stat) Any other clues?

    I’m on OSX 10.6.8, on a non-SSD MacBook Pro.

  • http://tartley.com Jonathan Hartley

    Aha! Figured my problem: The content of my xml file (which I copied from elsewhere) didn’t match the filename (which I copied from here.) Now the two are in sync and noatime is working.

    It’s made absolutely bugger all difference to the runtime of my disk-heavy process though.

  • Rob D.

    I did this to my system too.  Works great.  My SSD has only 15gb used right now and I have all my junk on it already.

  • Pingback: Optimizing MacOS X Lion for SSD » Martin's Weekend Coding

  • http://zoltankarpati.co.uk/ yoli

    Hi Fredrik, does this work in Lion?

  • http://zoltankarpati.co.uk/ yoli

    Hi David! Can I ask how exactly did you do that? Are you using Lion?

  • Blah

    Just go to /var and delete/rename the `vm` directory. Then create a symlink `ln -s` for the vm directory to your other drive.

  • http://zoltankarpati.co.uk/ yoli

    Okay, I’m a bit dummy for this, could you be more specific what do you mean by  ”create a symlink `ln -s` for the vm directory to your other drive.”? Especially how do I symlink it if delete it..?

  • Pingback: SSD: come mantenere il disco

  • Pingback: Anonymous

  • Pingback: Het voordeel van SSD - Pagina 4 - homerecording.be forum