2007年9月27日 星期四

Safe Sleep on the MBP

I Am Joe窶冱 Blog サ Blog Archive サ Safe Sleep addendum

I used to think that Macs don't have hibernate mode and apparantly I am wrong. The latest incarnation of Mac laptops all implemented hibernate mode, just that it is slightly different from the Windows counterpart.


The Windows implementation (example from my X31 w/ 2GB RAM) writes the memory into the hibernate file and shuts down the machine. When you power up the machine again, you will see the progress bar indicating the recovering process.
But, on a contemporary MacBook Pro, when one closes the lid, the system starts to write RAM image into /var/vm/sleepimage file, this is the part when the "breathing light" stays solid for about 10~20 secs (on my MBP). Then, the computer goes into "normal" sleep mode, which is STR, with the blinking "breathing light". Waking up the computer is standard recovery from STR. If during this period you lose power, the next restart will retrieve RAM image from the saved file instead of the normal cold boot procedure. This method is quite clever, combining the speed-to-recovery of STR and the fail-safeness of hibernation.
What if the 10~20 sec delay is still too long? What if you need to go on very long plane trips and want to store the computer over a long period without interrupting working session? Or, just the "I want my Windows hibernate back"? This link shows how to disable the "Safe Sleep" and go directly to "Deep Sleep" (which just means pure hibernate-and-shutdown). An even better approach is shown here . The script checks the battery status and auto-sets between Safe Sleep and Deep Sleep. With a charged battery, you can enjoy the instant sleep modes and still retain safety of data if the battery is low on juice. Put this in cron and you have a battery poller (Can we do this via kernel interfaces? I have no idea yet) that sets your mode based on juice left.
Personally, I don't find the 10-20 sec delay when lid closed annoying, so I'll probably leave it as it is for the time being. As a side-note, iStumbler has a bad habit of waking up the computer spontaneously even when the lid is closed, so you must check if iStumbler is running when trying to sleep.

沒有留言:

張貼留言