Saturday, October 15, 2011

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

This article: 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" "">
<plist version="1.0">
This will execute mount -uwo noatime / upon system startup,

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

Sources and resources:

1 comment: