Saturday, October 15, 2011

Optimizing Mac OS X for SSD drives (update: Safe Sleep tuning)

This article: http://poller.se/2010/08/optimizing-mac-os-x-for-ssd-drives/ recommends to reduce the writes on SSD drives to increase their lifespan. The proposed actions go in the direction of reducing un-necessary writes and disable legacy options linked to spinning hard drives.
I'm using: 1(with modified deepsleepdelay), 2, 3 and 4.

1. Alter the Sleeping mode 
By default, when closing the lid on a MacBook, the content of the ram (random-access memory) 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 so that ram content is not saved to disk.
$ sudo pmset -a hibernatemode 0 
This means that the laptop will never enter DeepSleep (or hibernation, that is the ram is always powered and in the event of a power loss the state is lost), and in this case the sleepimage /var/vm/sleepimage can also be removed.

• The default setting (SafeSleep) can be restored with: 
$ sudo pmset -a hibernatemode 3

• There is an intermediate behavior of SafeSleep, which delays the writing of the sleepimage for some time. This is controlled by the deepsleepdelay parameter (or standbydelay), by default set to 4200 seconds, meaning that the seleepimage is written 70 minutes after closing the lid. This may be too short.
To make it wait 12hs before writing the image to disk run:
$ sudo pmset -a deepsleepdelay 43200
or, on systems with OS X ≥ 10.6.8,
$ sudo pmset -a standbydelay 43200
during this time only the ram is powered and the wakeup is immediate. After 12 hours of sleep, the memory content is dumped to the sleepimage and the memory is powered off.
I'm currently trying this setting.

In conclusion, SafeSleep (hibernatemode 3) combined with deepsleepdelay <seconds> covers a wide range of sleepping/hibernating behaviors. It can even emulate the hibernatemode 0 (never save a sleepimage) just by setting a deepsleepdelay big enough.

2. Disable Hard drive sleep 
Putting SSD hard drives to sleep has no benefit. 
This can be disabled under System Preferences -> Energy Saver

3. Disable Sudden motion sensor 
$ 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,

5. Disable Spotlight 
$ sudo mdutil -a -i off

Sources and resources:
http://larvecode.tumblr.com/post/9622045759/osx-on-ssd
http://poller.se/2010/08/optimizing-mac-os-x-for-ssd-drives/
http://www.macworld.com/article/53471/2006/10/sleepmode.html
http://www.uponmyshoulder.com/blog/2011/deep-sleep-on-macbook-air-late-2010/
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/pmset.1.html

2 comments:

  1. hi...Im student from Informatics engineering nice article,
    thanks for sharing :)

    ReplyDelete
  2. There is a reason why I bought a Mac, it was not to be one of the cool kids that wanted the best of the best. No it was because of the music production I do on it. Hours and hours sitting in front of my Mac copying, pasting, moving, deleting, hour after hour just beating on my Mac in a endless assault to get my work done. That is the key part, my work. I work from home, it is great, but even if it is from home it is still work and it still needs to get done. So my Mac, I have it because it is fast, gets the job done and comes back for more.

    But what happens when it doesn't want to do those things anymore?

    I move around massive amounts of information and yes even on the almighty Mac this can cause a problem after a while. Things fragment, programs get corrupted issues come up. My light speed Mac slows down to a crawl and all of the sudden I simply can not get any work done. Because I work from home there is no IT guy to call and ask to come fix it. No instead I have to figure out what is wrong. I am lucky, I did, but not after trying everything under the sun first and wasting countless hours looking for one program that can do what I needed instead of ten programs. One program to lead them all….okay that was a lame Lord of the rings reference, but that program was/is Detox My Mac. A simple to use program that did not just fix my issues, it put my Mac on overdrive again. A few clicks and my Mac was clean and ready to rock and roll again.

    Read more here:- http://detox-my-mac.com?duhhf9265hskfhf98346

    ReplyDelete