Another Great Blog Using Perfmon in a Windows VM
Dec 14

OK. Not exactly related to virtualization but I thought I’d share this anyways. I am always on the move and I’m usually bringing my Mac with me. One of my favorite things about the Mac is that I can really just close the lid and walk to a meeting and open the lid and it’s ready to work instantly. That’s just incredible to me. Sure, a PC can sleep and even hibernate but neither makes the thing come alive quickly. The one painful thing for me has been waiting for my Mac to sleep. I run a lot of stuff all the time. Right now I have 21 different apps open plus a VM running in VMware Fusion. That means that when my Mac goes to sleep I have to wait for it to write most of the 4 GB of RAM to disk. A fellow engineer just showed me a faster way to make the Mac sleep – adjust the hibernatemode variable.

The innovation in Apple’s “Safe Sleep” is that it goes ahead and writes out the disk image, but then suspends to RAM. If you just resume, everything’s already in RAM and you can avoid the delay from resuming the image. If you lose power (or change battery), then it resumes from the disk image. By comparison, Windows offers both suspend-to-RAM and suspend-to-disk, but not at the same time.

You can change the Mac’s hibernate behavior using pmset; here’s the reference for it:

http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/pmset.1.html

“sudo pmset -a hibernatemode 0″ = suspend to RAM only (default on desktops)
“sudo pmset -a hibernatemode 1″ = suspend to disk only
“sudo pmset -a hibernatemode 3″ = suspend to disk + RAM (default on laptops)

To see your current hibernatemode: “pmset -g | grep hibernatemode”. Right now I have mine set to hibernatemode 0 and man do I love it. Instant sleep and instant recovery. This even works with 4 different VMs running in VMware Fusion with no hiccups. Can life get any sweeter?

I hope this helps some of you Mac lovers out there.

No TweetBacks yet. (Be the first to Tweet this post)
VN:F [1.7.8_1020]
Rating: 5.0/5 (21 votes cast)
VN:F [1.7.8_1020]
Rating: +1 (from 1 vote)
Wake Up Your Mac Faster5.0521

  • mine set to hibernatemode 0 and man do I love it. Instant sleep and instant recovery. This even works with 4 different VMs running in VMware Fusion with no hiccups. Can life get any sweeter?
  • Buckie
    Great tip! Just be careful that your battery doesn't run out while your Mac is asleep or you'll lose your current state (file changes, etc.), I haven't been ballsy enough to try this with my VM yet to see if it gets hosed.
  • Is it possible to make the Mac sleep in hibernatemode = 1 and having it on without needing the battery or the it still consumes energy while sleeping and having all stuff at the HD?
  • Mark
    I've been using the (free) dashboard widget Deep Sleep. http://deepsleep.free.fr/

    In addition to allowing to configure "smart vs fast sleep" from the widget (without going through the console), it also allows you to enter "deep sleep" (aka "hybernate then turn off") from the widget.

    So on those rare occasions when I want to swap batteries without rebooting, I can manually trigger "deep sleep" and wait for the machine to shut off. But otherwise, fast sleep is my mode of choice.
  • Martin
    Hi,


    I run a little script via cron every ten minutes. I think that's basically the way that SmartSleep works. I post it below, not shure how it will look since I cannot preview the post. And a disclaimer: I did not invent the script but found it somewhere online.


    #!/bin/sh
    MODE=`/usr/bin/pmset -g | awk '/hibernatemode/ { print $2 }'`
    LEFT=`/usr/bin/pmset -g batt | grep Internal | awk '{ print $2 }' | awk -F % '{ print $1 }'`

    if [ $LEFT -lt 25 ] && [ $MODE != 3 ] ; then
    {
    /usr/bin/logger -t "hibernatemode" "Battery level less than 25%; setting hibernatemode to 3"
    /usr/bin/pmset -a hibernatemode 3
    }
    elif [ $LEFT -gt 50 ] && [ $MODE != 0 ]; then
    {
    /usr/bin/logger -t "hibernatemode" "Battery level greater than 50%; setting hibernatemode to 0"
    /usr/bin/pmset -a hibernatemode 0
    rm /var/vm/sleepimage
    }
    fi
  • blah
    whoa... Fantastic! Thank you!
  • carbonsink
    Awesome, works perfect, thanks!
  • Andy Lee
    Shouldn't the title of this post be "Put Your Mac to Sleep Faster"?

    Nitpick aside, this tip made my day. Like you, I wait for the pulsing light before I put my laptop in my bag. Having to wait 45 seconds really detracted from the feeling of having an on-the-go machine.
  • That`s nice if you have a lot of the RAM occupied but otherwise it will be only couple of seconds for the mac to write RAM on disk. Still, really nice tipe.

    Just wondering if it makes any time differences when you open the lid, because on both options (0 and 3) the content is in the RAM and the Mac shoudn`t read the HD anyway. So, it`s instant recover on option 3 too, isn`t it?
  • It's definitely instant recovery both ways. You just don't have to wait for it to shut down. For me that's big. I have 4 GB of RAM in my MB Pro. I use most of it all the time since I'm always running tons of programs and at least 1 VM. It's made a huge difference in my life already not having to wait for it to suspend.
  • If you use encrypted virtual memory, there are some extra settings as well. I tend to use 5 for disk only. http://blog.stephanbuys.com/2008/02/protecting-...

    Also, there is a nice article on tuning the settings if you don't want to suspend to disk normally, but still want the protection of doing it when the battery gets low. http://www.radiotope.com/content/os-x-105-leopa...
  • A few times my macbook pro failed to actually suspend after I closed the lid. It almost started a fire one time when I closed the lid and put it into the padded laptop bag. When I took it out 2 hours later it was so hot it burnt my fingers.
    So from that point I always confirm the machine is suspended before packing it down. You just shorted my wait with 30-40 seconds, I thank you for that! :)
  • Funny you mention that. The same thing happened to me a couple of times. They do get REALLY hot in those bags. :)
  • Mr. Darcy
    I recommend SmartSleep, too. It gives you best of both "worlds" and seems to work pretty much as advertised.
  • Chris Bulow
    I don't recall changing any settings and mine is set to 0 already...
  • Awesome! Thanks for the tip. This always frustrated me, too, since they changed it. Glad we can get the RAM-only mode back.
  • Andrew Miller
    You've got to use SmartSleep (no relation to the developer, etc.).

    http://www.jinx.de/SmartSleep.html

    It makes what you're listing above much easier as well as can change the settings when your battery is low (which makes perfect sense).
  • I love smart readers with useful comments. Thanks for the link to that awesome little app!
  • Note that you CAN change your batteries with the Mac plugged in and sleeping without losing anything in mode 0. But if you can plug in, why are you running on batteries, I suppose?

    Anyone know of a way to tell the Mac to hibernate to disk just this once from the command line?
  • Bob Klaas
    Thanks for the sweet tip!
  • The one thing to note to your readers Mike is that if you change the settings to the hibernatemode 0, this means that you WILL lose work if you close the lid and then try changing the laptop battery.

    When I first got my Mac, I did this on a cross country flight without even thinking about it and then was amazed when the Mac restarted with all my apps (and data) still where I left them. Like most things, it's a trade off...but something that needs to be kept in mind.
  • I always always save my work before putting my mac to sleep. It's just general best practice to do that, IMO.
  • Absolutely be aware that you will loose your data if it's just in RAM. Like you I loved the fact that I could change out my battery in the middle of a long flight (I take lots of them). However, I found that I preferred the quick up and down times of changing the setting and then just knowing that I'll have to shut all the way down to swap batteries on those long flights. I might change my mind again now that Delta is starting to offer WIFI on the planes. We'll have to see how the old battery does then. If only they put power in all of the seats. One reason I still love trains.
  • Rob Uttley
    Wow. I've had 2 batteries for over a year for my 1st gen MBP and I never realised I could swap batteries like that. When the power gets very low, I've always saved/closed all my documents, shut the whole machine down properly, swapped the batteries, and then restarted, reloading my apps and reopening my documents etc.

    Knowing that I can put the machine to sleep and swap batteries is brilliant - thanks for making me aware of that!
  • Anonymous
    Vista has a similar feature called "Hybrid Sleep". Interestingly, it appears that the default behavior is the opposite of the Apple, using the logic that for a desktop without a battery backup like a laptop has, it is safer to suspend to disk + RAM.

    http://windowshelp.microsoft.com/Windows/en-us/...
blog comments powered by Disqus