Monday, May 5, 2008

Unsafe Sleep

One thing I really liked about my PowerBook Pismo was its instant and super reliable sleep/wake functionality. In contrast the new MacBooks are slow as molasses and sometimes fail to wake up at all, at least for me.

One feature that is responsible for the MacBook to take a long time to sleep is SafeSleep. Basically, whenever you put your MacBook to sleep it saves the entire contents of its memory onto the hard drive, usually into /var/vm/sleepimage. It does so to ensure that no data gets lost even if the battery runs out while it is asleep. This hardly ever happens to me, and even if it did I wouldn't mind because I generally don't keep unsaved documents open. So, for me SafeSleep is a waste of time and energy, because it does cost battery to write all that memory to the hard drive, as well as disk space for the sleep image file.

If you haven't seen the wake up progress bar you might also be interested in turning off SafeSleep. But how? Apple decided not to repeat the Vista sleep fiasco and chose what would be the most useful functionality for 95% percent of their users; and not to confuse anyone, they decided against offering an obvious way to change it. That said, OS X is extremely modular and of course there's command line access to configure how you want your MacBook to sleep. Without further ado:


[499 ~] pmset -g
Active Profiles:
Battery Power -1
AC Power -1*
Currently in use:
sleep 60
sms 1
acwake 0
displaysleep 30
autorestart 0
hibernatefile /var/vm/sleepimage
hibernatemode 3
womp 1
halfdim 1
disksleep 10
lidwake 1
ttyskeepawake 1


You can see where it keeps the sleepimage and you can see that hibernate mode is set to 3, the default for new MacBooks. What I want is for my MacBook to never write its memory to disk.


[501 ~] sudo pmset hibernatemode 0
[502 ~] rm /var/vm/sleepimage


Now I have 2 gigs of disk space back, and I have near instant sleep; at the price of losing some work under circumstances which are unlikely for me.

More details and more fine-tuning possibilities are described here.

3 comments:

Jtf said...

Great tip Eric!

Anonymous said...

For the GUI lovers: http://www.jinx.de/SmartSleep.html

mark@aufflick.com said...

All Mac Laptops prior to the Powerbook Aluminium 12" (and possibly not including the PowerBook 100) had some sort of last-reserve backup battery or supercap so that if your battery did go totally flat or you removed it, ram contents would be saved.

This gave the benefit of safe sleep without the sleep delay.

It is really disappointing that this feature which helped Mac's secure a large portable market share in the 90s has been sliced in cost cutting.

Of course the distinction between ram and disk becomes a bit moot when you start talking about solid state drives.