« Amory Lovins on IT Conversations | Main | Don't Say This About My Product! »
Fixing MacBook Pro Sleep Problems
One of the things I loved about my Powerbook was that it slept—and woke—reliably. I would go weeks without rebooting my machine and I bragged about it often to the poor saps who had to use XP on their laptops. I haven’t been singing the praises of OS X stability as loudly lately because ever since I went to the Mac Book Pro (MBP), my machine has had issues with sleeping and waking to the point that it probably got rebooted once a day.
Well, no more! I tried something a few weeks ago that has made my MBP into a machine I can love again. Here’s what I did.
When Apple shipped the MBP, they changed how sleep works. What? Mess with perfection? Yup, that’s what they did, although they had a reason (I’m not saying it’s a good one). The old Powerbooks could tolerate a battery switch when they were asleep without losing state. The MBPs can’t. If you put your MBP to sleep, switch batteries, and then wake it, you’ll note you’ve see a whited-out screen and a progress bar at the bottom. The machine is waking from hibernation. If you pop a battery out of a sleeping MBP, it automatically hibernates.
In order support this automatic hibernation, the machine has to write the contents of RAM to disk every time it goes to sleep. This is called “SafeSleep” by Apple. I call it “SureDeath.” That’s why putting a MBP to sleep takes to long. For whatever reason, that process seemed to be causing problems for me. Maybe because I’ve frequently got almost 4Gb of RAM in use with virtual machines, and so on. Often my machine would refuse to sleep or never wake up once it got there.
Here’s the good news: Apple left the old mode in the OS and you can activate it if you want. You can also switch back to SafeSleep anytime you like. According to this MacWorld article, OS X supports five different sleep modes:
- 0 - Old style sleep mode, with RAM powered on while sleeping, safe sleep disabled, and super-fast wake.
- 1 - Hibernation mode, with RAM contents written to disk, system totally shut down while “sleeping,” and slower wake up, due to reading the contents of RAM off the hard drive.
- 3 - The default mode on machines introduced since about fall 2005. RAM is powered on while sleeping, but RAM contents are also written to disk before sleeping. In the event of total power loss, the system enters hibernation mode automatically.
- 5 - This is the same as mode 1, but it’s for those using secure virtual memory (in System Preferences -> Security).
- 7 - This is the same as mode 3, but it’s for those using secure virtual memory.
From Macworld: Mac OS X Hints: Set newer portable Macs’ sleep mode
Referenced Wed Oct 17 2007 09:58:31 GMT-0600 (MDT)
The first step is to check which mode you’re in now. Use this command from the terminal:
pmset -g | grep hibernatemode
Make a note of which mode it is (probably 3) so that you can return to it if you want.
Now, set your MBP to use mode 0:
sudo pmset -a hibernatemode 0
That’s it. I rebooted. Not sure it that’s necessary, but what the heck.
Now, you may be wondering…if my MBP was writing memory out to disk, is that stored somewhere, taking up precious disk space? Yes! Here’s how to recover it:
sudo rm /var/vm/sleepimage
My sleep image was 4Gb since that’s how much memory I have. Nice to have it back.
Now, a word of warning: if you change to sleep mode 0 on a MBP, you lose the ability to do a battery swap without plugging the machine in. I only do that occasionally, so I’m happy to forego the feature if my machine works more reliably every day.
As I said, I made this change two weeks ago and my machine has been as stable as my old Powerbook every since. I’m happy to have solved one of the annoyances of my computing life. As always…YMMV.
Update: Bryan Morse made me aware of this Tidbits article that contains a script you can run as a cron job that will put you in hibernate mode when your battery gets low. Some people have reported that occasionally OS X will switch the mode back to 3 so you have to check to make sure you’re still in 0 (and delete the sleepimage file). This script does that as well.
Posted by windley on October 17, 2007 10:08 AM




Comment from Hans at October 17, 2007 11:41 AM
I have not had this problem, but I have been having a different problem with my MacBook recently. It used to be, when I ran out of battery (and ignored the 5-minute warning) that it would go to sleep. When I plugged it in and hit a key it would wake up. Sometimes it would dehibernate, having obviously gone into hibernation because power was fully depleted.
Recently, though, if it gets to the point where it should go to sleep, I end up with a completely off computer. Even if I only miss plugging in in time by a few seconds, it is completely off. I press keys and nothing happens. I press power and it turns on as if it had been off all night. Obviously this is not what I'd like.
I checked, and I'm in mode 3 (which, unless I start having problems like yours, is fine by me).
Comment from Trent at October 17, 2007 10:02 PM
Nice I have been having this same problem and had started to blame it on firefox ... given this info my bet is it was just firefoxes memory footprint.
Comment from Steven Ng at October 17, 2007 10:08 PM
I have encountered the problem in mode 3, but only when I put the MacBook Pro to sleep when I'm running VMWare Fusion, which means if I want to avoid the problem, I have to remember to quit Fusion before I close the lid.
Comment from Jordan Brough at October 18, 2007 8:09 AM
Thanks for the tip Phil! Exactly what I needed for my MacBook. I'd much rather lose 30 minutes of work every few months (by not having hibernation) than waste 30 seconds on finger-tapping every single time I open my MacBook.
Comment from Dave at October 18, 2007 2:05 PM
This was a great tip - not just for the time saved, but for the 2GB I just got back from my MBP's hard drive!
Comment from daaku at October 18, 2007 4:48 PM
Its sometimes valuable to have safe sleep option turned on. A script like below can be used to toggle it on/off based on the current battery level (its 30 to on/50 to off in the script below).
This script can be setup via cron (or launchd if you prefer). Its setup to run as a non root user, and you need to make sure the commands used with sudo do not require a password.
http://pastie.caboo.se/108688
Comment from Troy Wilson at November 1, 2007 9:14 AM
Great tip! The sleep mode was driving me crazy! Thanks for the tip.
Comment from Adrian Ocneanu at November 7, 2007 1:17 AM
Fantastic tip! My MacPro (desktop) did not sleep even after 5 hours of tech support from AppleCare. Apparently only the very high level support people from Apple know Unix.
I did the trick IN REVERSE: the MacPro was by default in hibernatemode 0, and I put it on hibernatemode 1. I didn't need to restart.
It takes a while to wake up, but now IT SLEEPS!! (I have 3 monitors attached, and they will get dimmer over time if the backlight stays on all the time)
Many thanks
Leave a comment
I encourage you to leave a comment below. Your email address will not be displayed on Technometria, but allows me to communicate with you directly. Your email address won't be displayed, but will be used to compute a MicroID for your comment.