The trouble with Safe Sleep: when Apple makes bad decisions by watching folk who like to hack

“Why does my machine sometimes reboot itself?” asked my wife one day. “I close it, then open it and it’s gone back to restart. Nothing’s wrong, but it just does it.”

A mystery, certainly: what was wrong with her Macbook? Here we are, having had Macs all the way back to a Wall Street model – that’s circa 1999 – when it had always been simple: close the lid, and it goes to sleep. Quickly. And you never open it to find that it’s rebooted itself. Ever.

I searched around for firmware updates and things like that, but none seemed right for the problem – which persisted.

But this turns out to be a case where Apple has copied something from Windows – apparently because some Apple folk have too much time on their hands and surfed around looking for things that Apple users thought they wanted. Which turned out to be things that Windows users had. Which turned out not to be good for Apple Mac users.

Back in November 2005, Andrew Escobar noted that Apple’s new Powerbooks (introduced in late 2005) did the same thing that Windows machines had done for ages: go for “safe sleep”, where the contents of RAM get written to disk when the lid is closed. He figured out how to do it for other machines. (His post has 300 responses.)

I don’t think though that Apple dreamed this up on its own; people had been talking about how Windows had “Safe Sleep” for ages and wondering if they could hack it. I’m sure I’d seen it discussed before. And why did Apple think it was worth doing?

You’d think that Apple had, by now, got over the “let’s copy things from Windows!” thinking. Sure, there was a little bit of it here and there in OS9, even early OSX, but someone there seems to have been seduced by the fact that some Apple hackers wanted to have their machines copy Windows machine by having a “hibernate” function. Except Apple went too far: instead of giving people the option, someone made “hibernation” – where the RAM contents are written to disk (using less battery) – the default. Not just the default, but unavoidable.

The result: my wife, who’s been a Mac laptop user all the way, found that sometimes she’d put her machine down, and when she picked it up again, it had crashed.

Others had had the same problem and been just as mystified, it emerged: Why does my MacBook occasionally restart when I close the lid to have it go to sleep?

And then the backlash, such as TinyApps: “Apple Safe Sleep sucks“.

Joe Kissell finally nailed it for us all with Stewing Over Safe Sleep: the reason is that when you close your laptop’s lid, it *starts* writing the RAM contents to disk. If you move your machine while it’s doing that, the motion sensor kicks in and parks the heads. Result: your RAM state isn’t written to disk. But the machine will try to start from that RAM image on the disk when you open it up.

It won’t find it – and so it restarts. Bye-bye, unsaved work! As Kissell points out, if you’ve got a lot of RAM, that can mean a wait of nearly one minute during which you mustn’t move your machine, on pain of losing everything, in your mobile environment.

Does that make sense? Surely the thing about laptops is that you’re likely to be jumping about with them. And did the Apple folk forget that we always used to laugh at Windows users, who had to start shutting down their machines 10 minutes before they wanted to go anywhere, while the Mac users would close-and-go? Clearly they did, because there’s no GUI to let you change this option.

It is possible – and Joe Kissell has done us all a service by pointing to the way to do it – but the reality is that this was a really bad call by Apple, seduced by Windows-y things that have no value.

What Apple should do is give people a GUI option to change this. You can have “normal Apple behaviour”, or “normal Windows behaviour”. (I wonder which most people would choose?) I’m only surprised that nobody has kicked together a little GUI tool to do this – Midnight might be the one, but it doesn’t seem like it works.

And just to show that serendipity has its uses, I actually discovered the fix for this after having completely failed to solve the problem, and while browsing John Gruber’s Daring Fireball Linked List. And there it was:

My wife’s MacBook was suffering from a problem where, once or twice a week, the machine would just shut down completely when she put it to sleep. She’d close the lid, and a few seconds later, the machine would just turn off or restart. The solution? Disable Safe Sleep. It hasn’t happened again even once.

So far we haven’t taken the step of trying to disable Safe Sleep, because that involves some hacking which I’d be happy to do on my machine (except it doesn’t do Safe Sleep, and I don’t want it) but am loth to do on my wife’s.

7 Comments

  1. Aloha, Charles! Thanks for the link… I don’t know how that post ended up posted to the web – it was a work in progress, and completely unformatted. I’ve done my best to clean it up a bit. Thanks again! Miles

  2. That’s interesting. I have a thinkpad which ought to behave in the same way, but doesn’t: it will hibernate, but I have never lost work in the way that you describe, because it doesn’t start to do so the moment I shut the lid (It does have a motion sensor on the hdd). I can set it to sleep first, and only hibernate if let alone for 20 minutes (or whatever). It is a useful feature. I am just surprised that Apple should have implemented it so clumsily. Perhaps they thought the options panel in a thinkpad was too complicated. Perhaps it is. But the behaviour you describe is no improvement.

  3. Yeah, someone needs to put together a preference pane that sorts out the script and the cron job and whatnot.

  4. I’d always thought that adding configuration options like that was something Apple didn’t do. Microsoft bends over backwards bolting in checkboxes and control panels and issuing PowerToys after the fact; the first thing that struck me about my Powerbook when I got it was Apple just don’t give you the choice. You do it their (usually quite elegant) way or not at all. Which is a bit annoying, though explicable.

  5. ***the reason is that when you close your laptopís lid, it *starts* writing the RAM contents to disk. If you move your machine while itís doing that, the motion sensor kicks in and parks the heads. Result: your RAM state isnít written to disk. But the machine will try to start from that RAM image on the disk when you open it up.***

    that doesn’t really explain anything yet, other than their hibernate being buggy. why wouldn’t the software be written so that it would wait for the hd to become unparked again and then finish up the writing. THATS the real solution to this, to write the hibernate clone properly, obviously it’s not properly written at the moment, hd getting parked should just make the whole process take longer, NOT cause a total failure. burning your battery keeping the 2 gigs of memory alive isn’t really a good thing to do, not in the long run anyways – which is the real reason why hibernate is _better_ than than just sleep(you don’t have to worry about battery running out, or losing work while changing battery).

  6. Lassi – as far as I can see it still keeps the memory active anyway (reopen the lid after safe-sleep and you’re instantly on – it doesn’t restore from disk – you can see when it does that and it takes 4-5 seconds to do so). So all it really saves you is when you have shut the lid and THEN run out of power.

  7. I have got random restarts in MBA with BootCamp. Several times a day. First I thought this is from overheating but no. It can happen after the MBA was in sleep on my desk for several hours, and completly cool, and I open the lid and bang it restarts. Never shutdowns. Just restarts. This makes the MBA useless for me. I am past the 1 year warranty. Funny it worked well for several months in BootCamp. These restarts do not happen with Leopard running, just Windows 7. Maybe I should reinstall BootCamp 3.1 once again. Any suggestions are welcome. If I work these days for more then one hour, it ominously restarts again. This is terrible.

Comments are closed.