[Update 15-Mar-08: Anyone wishing to modify their Mac’s safe sleep settings should use Patrick Stein’s SmartSleep preference pane instead of the script below; see “SmartSleep Solves Safe Sleep Situation,” 2008-03-15. -Joe Kissell]
Imagine that you’ve just bought a new car, and the car manufacturer has thoughtfully included a new piece of technology, a Dead Battery Preventer. In order for the DBP to work its magic, your car must continue to run for 49 seconds after you turn it off – every time you turn it off – during which time you can’t open the doors. But, as the car dealer reassures you, surely this is a small, barely noticeable inconvenience compared to the tremendous savings in grief you’ll experience on those occasions when you’d otherwise find yourself stuck, unable to go anywhere due to a dead battery. No waiting for a tow truck to arrive, no frantic calls to AAA. Just activate the DBP and drive away.
There’s no such thing as a DBP, but that’s the closest analogy I could come up with for a feature that has been built into all Apple laptops for the past couple of years. It’s called Safe Sleep, and it’s comparable to the hibernation mode typically found on Windows laptops. In this mode, your laptop uses no electricity whatsoever, and the entire contents of your RAM before entering Safe Sleep are safely stored on your hard disk. The main point of this feature is to protect you from a situation in which your computer has gone to sleep with an unsaved document, and then your battery, which can ordinarily sustain your computer’s RAM during sleep for hours or even days, has drained completely. When you plug in your laptop or replace the battery… Oh no! Your unsaved document is gone! But not with Safe Sleep: your computer automatically restores the contents of RAM from that file on disk, and you’re right back to where you were before. The cost for this safety net? A short delay whenever you put your computer to sleep so that your RAM can be copied to disk.
In most of the articles I’ve read about Safe Sleep, it has been hailed as a tremendously helpful feature. There are utilities and hacks to enable Safe Sleep on certain laptops where it wouldn’t otherwise be available, and you can download any of several free tools (such as Deep Sleep, Midnight, and SuspendNow) to force your laptop directly into Safe Sleep (as opposed to ordinary sleep). But I don’t like Safe Sleep one bit – at least not the way it’s currently implemented. I especially dislike the fact that Apple has not merely made it the default setting, but has omitted any graphical interface for turning it off – and the fact that if you use the command line to do so, chances are good that Safe Sleep will turn itself back on when you least expect it.
This is not merely a suboptimal or marginally infelicitous design decision. It’s a bad way of doing things that Apple should be actively ashamed of and should remedy immediately. To explain why I feel this way, I want to provide a bit more detail about Safe Sleep and how its current design falls far short of Apple’s ordinarily high usability standards.
Stages of Sleep — My trusty old titanium PowerBook G4 belongs to a generation of laptops before Safe Sleep existed. When I put my TiBook to sleep, it goes to sleep immediately. Right away, the power light begins pulsating gently, and right away I can put it in my bag, or back under my seat on the plane, secure in the knowledge that the hard disk is parked and therefore relatively immune to everyday shocks and jarring. When I open the lid again, everything immediately returns to its previous state. While the laptop is asleep, it uses a little bit of electricity – enough to maintain the contents of RAM and keep a few other key components minimally active – but I know from experience that the computer can stay asleep for some time. If the battery held close to a full charge before I put the computer to sleep, that period of time can be several days or longer, but even if it was close to empty, I know it will last for at least a few hours.
The situation is different on more recent Apple laptops – every portable model starting with the 15-inch and 17-inch Double-Layer SuperDrive models introduced in October 2005. These models do have an ordinary sleep mode, just as before. But Apple’s documentation warns you that when you put such a laptop to sleep (by closing the lid, for example), you must not move it until the power light has begun pulsating. During the first moments after you close the lid, when the light is on steadily, Mac OS X is busily copying the contents of your RAM to your hard disk in preparation for the possibility that your battery might later drain completely – forcing the computer into Safe Sleep mode. And during that time, when the disk is spinning, any untoward movement could cause damage to the hard drive mechanism. (You can also employ a command-line hack to force it to bypass the ordinary sleep mode and go directly into hibernation after saving the RAM, if you so desire; I discuss this a bit later.)
So far so good, but here’s where the problems start. It takes more than a “moment” for your computer to write this hibernation file to disk and go to sleep. The length of time it takes is proportional to the amount of RAM you have installed. On my new MacBook Pro with 4 GB of RAM, it takes 49 seconds for the computer to sleep when Safe Sleep is active; with Safe Sleep turned off, it takes only 4 seconds. That’s an enormous, and enormously annoying, difference.
Moreover, for each gigabyte of RAM you have, you effectively lose a gigabyte of storage space on your hard disk, because of the space required for this special RAM cache file. Given the higher cost and lower capacities of laptop hard drives, this space usage is a nontrivial issue. In essence, there’s now both a performance penalty and a storage space penalty for buying the latest hardware and maxing out your RAM!
Even so, the inconveniences of Safe Sleep would be slight if Apple offered an easy way to turn it off. But as things stand now, you have to do this in Terminal, using the same pmset program Glenn Fleishman had to employ to solve another sleep-related issue (see “Sleepless (and Latchless) in Seattle,” 2006-10-09). To disable Safe Sleep and delete the existing disk image used to hold the contents of your RAM, open Terminal and enter the following two commands:
sudo pmset -a hibernatemode 0
sudo rm /var/vm/sleepimage
The new settings take effect immediately; no restart is required. (To return Safe Sleep to its default setting, repeat just the first command, replacing the 0 with a 3. To change the behavior so that your computer always goes directly into Safe Sleep without waiting for the battery to die, replace the 0 with a 1. And if you have Use Secure Virtual Memory selected in the Security pane of System Preferences, replace the 1 or 3 with 5 or 7, respectively.)
Still, however, the problem hasn’t quite gone away: even after I did that on my computer, I found, more than once, that Safe Sleep had turned itself back on. I haven’t yet discovered why or when this happens. I do know that using the pmset program modifies the same file used by the Energy Saver pane of System Preferences: /Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist. At first I assumed that making any change to the Energy Saver preferences overwrites all the settings not explicitly shown in the preference pane with their default values, and that Safe Sleep had turned itself back on because I’d changed some other setting there. However, this is not the case; I’ve made changes to the Energy Saver preferences and verified, afterward, that the hibernatemode value in the preference file was still at 0, just as I’d left it. But something that happens periodically on my computer does reset that value to its default from time to time, and I realize this only when I attempt to put my computer to sleep and notice that it takes far too long to comply – invariably at the least convenient moment.
The Wrong Solution — I understand, of course, that software development involves a never-ending series of compromises. Sometimes elements of usability must be sacrificed for some greater good. But in this case, I believe that the good is not greater, and that Apple had other options available.
In the first place, consider the problem Safe Sleep is trying to solve. Safe Sleep is useful only when all three of the following circumstances exist:
- Your computer enters sleep mode with unsaved documents.
- Enough time passes (generally, multiple days) for the battery to drain completely.
- After inserting a charged battery or connecting an AC adapter, you expect your computer to return immediately to the state it was in before it went to sleep.
This set of circumstances never, ever exists for me. First, I habitually save my documents frequently, and allow any application with an auto-save feature to save files on its own every 10 minutes, if not more often. So, the maximum amount of work I could lose, if not using Safe Sleep, is 10 minutes. Second, I always travel with an AC adapter and a spare battery, so I’m never away from some source of power for longer than my computer can stay asleep. And finally, I don’t expect my computer to protect me from my own carelessness: if I’ve neither saved my work nor arranged for enough power to keep my laptop’s memory alive, I don’t assume that the computer will somehow magically forgive me.
But that’s me. You might have different habits or expectations; seemingly enough people do that Apple considered Safe Sleep important. And I don’t mind at all that Safe Sleep exists. As I said earlier, what I mind is that it’s on by default – a significant reduction in usability – without any obvious means of turning it off or getting it to stay turned off.
Apple could have done things differently. For example, they could have put a Safe Sleep control in Energy Saver Preferences so that you can turn it on or off, or adjust its behavior, if needed. But I think even that is unnecessary aggravation. You don’t have to stop jogging and wait for 49 seconds before your iPod will shut off. In fact, you don’t have to shut it off at all. The world’s zillions of iPod users wouldn’t tolerate such an inconvenience, and Apple quite reasonably designed the iPod in such a way that you never have to think about whether it’s in motion or perform some lengthy ritual to put it to sleep safely. I have to believe that Apple’s engineers are smart enough to figure out how to do something comparable for a laptop.
Interestingly (and ironically), all the Apple laptops that come with Safe Sleep enabled by default also include a Sudden Motion Sensor (SMS), a little device that detects when your computer might be moving too much and parks the hard drive to prevent damage. If the SMS works as advertised, it should be unnecessary to avoid moving your laptop when it’s busy caching your RAM; what should happen is that if your computer moves too much, the SMS steps in and keeps your hard drive safe. All this can and should be invisible to the user. And for all I know, maybe the SMS already works just fine if you jar your computer while it’s saving your RAM – but if so, there should be no need for all the warnings about keeping your laptop still, and no intermediate “not-quite-asleep” mode to know about.
Lights Out — I eventually worked around this problem, for myself, on my own MacBook Pro. It took me all of a few minutes to write a three-line shell script to turn off Safe Sleep and delete the RAM cache, if any – and then to set up a cron job (or I could just as easily have used Launch Services) to run this command with root privileges every hour, just in case I’ve inadvertently done something during that time to turn Safe Sleep back on. My script, by the way, was simply:
/usr/bin/pmset -a hibernatemode 0
But then, I’m a propellerhead. I don’t mind doing that sort of fiddling. Ordinary non-geeks shouldn’t be subjected to such silliness.
Asleep on the Job — I remember being in the audience for a Steve Jobs keynote several years ago in which he was demonstrating wireless streaming video. A PowerBook was playing a video clip that was being streamed over an AirPort connection from another Mac. To show how robust this capability was, Steve closed the PowerBook’s lid while the video was playing, putting the computer to sleep, and then, a few seconds later, opened it again to demonstrate how the video immediately picked up where it had left off. We all applauded: that’s how seamlessly things were supposed to work.
You can’t do that anymore – at least not without using an unsupported hack. You have to wait almost a minute before your laptop will sleep, during which time you should not be moving it around. Look, it’s 2007 and I’m a Mac user; if I can’t put my brand new computer to sleep and into its bag in less than 10 seconds, something is seriously wrong.