AdSense Mobile Ad

Sunday, March 7, 2010

Apple Mac OS X' "Safe Sleep"

Safe sleep is no new kid on the block: at least as far as it concerns major operating systems such as Microsoft Windows, GNU/Linux or even Sun Microsystems' Solaris: never heard about Windows' hibernation or Solaris suspend and resume? I bet you have.

Apple has christened this functionality as "Safe Sleep" in its flagship OS, Mac OS/X. What's most "astonishing" about "Safe Sleep" is that you're not going to find any reference to it in your Finder menu or even in your System Preferences panes. You'll only find references to a "generic" sleep function.

Safe Sleep

During safe sleep the system will persist to disk all of the machine state (such as RAM's) so that it could be restored in the case all of the power is lost, for example during battery replacement. Under normal conditions, you'll hardly notice a resume from disk since the laptop battery power will maintain data on RAM even when the battery power has run real low. That's why during battery calibration Apple suggests to let the laptop sleep at least 5 hours. The next time you calibrate your battery, you should notice a slightly different boot screen when your laptop wakes up and reads its state from disk.

How to force a safe sleep?

Despite other implementations of a similar technology, Mac OS/X does not provide a way to force a system hibernation simply because every time your computer goes to sleep, it will persist its state to disk. This way you can let your battery discharge without worrying about your data. You could remove it, too. Next boot, it would simply read state from disk and restore it.

That's counterintuitive for who's accustomed to other OS where such a process should be explicitly triggered by the user. When using an Apple laptop, simply don't worry. You'll quickly get used to never, or very rarely, shutting down your system.

Handling your laptop while sleeping

When your laptop is sleeping, most of the hardware components will be completely off. That's the case of the hard disk: if you're laptop is equipped with a good old rotating hard drives, as soon as the computer state has been persisted, the disks will be switched off. The only evidence about this is the white led in front of your laptop: it will switch from a solid on state to a blinking state when the drives have been switched off.

Until complete disk shutdown, handle your laptop with care.

Once the laptop is sleeping, you can safely handle it as if it had been completely shut down. The real difference between a sleeping and a shut down laptop is RAM electrical state. As far as it concerns mechanical parts, there will be no difference at all. Hence:

No need to worry about hard disk heads landing on the platters. Put your sleeping laptop into your bag and safely transport it.

No need to emphasize the obvious, but I noticed a bit of misinformation about how safe sleep works and about the dos and don'ts. Indeed, safe sleep is the best way to forget about quit all applications and shut down. Reboots won't ever be faster.



2 comments:

Unknown said...

How about an iMac 27" that keeps on heating in sleep state like an iron? (I am really wondering if I can leave it on unattended in a small room in summer!) I want to force hibernation at will (or after a certain time automatically) to safe energy and time at startup. I am using "SafeSleepOnce" but it will produce an error with my non Apple Time Machine Disk if I don't properly "unmount" it prior.

Enrico M. Crisostomo said...

Hi Martin.

As far as I'm aware of, Safe Sleep is enable only on laptops. Basically, it's a defense against battery failures and incomplete shutdowns. Depending on what you're looking for, an UPS might be a better solution for a desktop system that, having no battery, is much more exposed to such problems than laptops.

That said, "Safe Sleep" hibernation mode can be forced using the following command:

sudo pmset -a hibernatemode [mode]

where mode can be one of the following:

0, to disable Safe Sleep.
1, to force safe sleep immediately without going into normal sleep before (what I suppose you're looking for)
3, to enable safe sleep (the default on laptops)
7, the same as 3 in the case you're using secure virtual memory.

I never tried

sudo pmset -a hibernatemode 1

on a desktop system like an iMac. If you try it, glad to hear feedback from you.

By the way, if you're iMac keeps on heating like an oven it seems to me that it hasn't even made it into normal sleep mode. Might there be some process preventing it to do so?

As far as it concerns Time Machine, I'm using as a disk an iSCSI target which isn't Apple's either. While Time Machine is running, the laptop won't sleep at all and it will only go into sleep when Time Machine has finished its job. Forcing a sleep, makes OS X and Time Machine complain sometimes.

Hope this helps,
Grey