October 8th, 2007

Unsafe sleep: Macbook spontaneously rebooting.

Occasionally my MacBook reboots when I close the lid and drop it in my laptop bag, instead of properly going to sleep. I found this a bit odd, because my old Powerbook was absolutely 100% reliable at going to sleep, but I originally just chalked it up to unreliable firmware on the new architecture and thought it would likely just be fixed soon. But it wasn't. I did notice after a while that it only happened when I was putting my laptop in the bag. Hmmm.

Apparently, the "Safe Sleep" feature is interacting poorly with the "Sudden Motion Sensor" feature. On newer macs, instead of just saving state to RAM (which, in my opinion, was perfectly fine...), they also write the state to disk. This takes a minute or so to do. If you jolt your computer during this time enough to cause the SMS to park the drive, it just reboots, discarding all your state. Of course, the sensible thing for it to do would be to wait for the motion to stop, unpark the drive heads, and continue writing. Or even just forget about writing to disk, and just use the already-saved-to-RAM suspend state. But no, it reboots.

In all the time I've owned a laptop, I'm pretty sure I've never left my computer alone for long enough that the battery runs down and loses the RAM. So, I can't see any real use for Safe Sleep to begin with. But I've lost my state quite a few times now due to this bug. So, here's how to turn off "safe sleep" and go back to good ol' reliable RAM sleep mode.

To disable it temporarily (until reboot):
sudo rm /private/var/vm/sleepimage

To disable it permanently, do the above, and:
sudo pmset -a hibernatemode 0

For some more discussion on the topic, see another blog