January 15, 2011

Faster MacBook Sleep

On several occasions I've closed the lid on my MacBook Pro and dropped it into my backpack only to open it later and find it either toasty or worse, completely dead. It either hadn't gone to sleep properly or the lid had opened in transit, waking it.

By default, MacBooks are configured to back up the entire contents of RAM to disk before sleeping – this allows the state of a sleeping Mac to be restored, even if the battery has completely drained. OS X laptops are also configured to wake up automatically when the lid is open.

Entering this command into Terminal.app returns your OS X computer's current sleep mode, which by default is "3" for laptops:
pmset -g | grep hibernatemode
I changed my MacBook Pro from hibernatemode "3" to "0": sleep immediately and do not backup my 4GB worth of RAM to the hard drive. I also set my MacBook Pro not to wake on lid opening – no more accidental wake-ups in my backpack:
sudo pmset -a hibernatemode 0
sudo pmset -a lidwake 0
Bonus: 4 more GB of disk space
Because my MacBookPro no longer writes its RAM to disk, I removed the sleepimage file, freeing up 4GB of hard drive space:
sudo rm /var/vm/sleepimage
Now my MacBook Pro goes to sleep immediately on shutting the lid, and does not wake when I open the lid. Instead I just press any key.

SSD Drives
If your OS X laptop came with an SSD drive (e.g. MacBookAir), your Power Management settings are best left alone. If you have upgraded from a conventional hard drive to an SSD, refer to a discussion specifically on OS X SSD optimization, such as Fredrik Poller's below.