You are not logged in.

#1 2013-05-24 09:01:48

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Improving (making faster) hibernation

Hello,

Whenever I see someone using his or her Macbook I am quite impressed about the speed of the hibernation process. Apparently they just close the lid and the Macbook instantly goes into hibernation state. Same applies when opening the lid or pressing the power button, the Macbook instantly restores from hibernation.

When comparing that to the hibernation and restoration process on my Thinkpad X200T speed is very slow.

I do not use any kernel modifications at the moment and just the standard hibernation process invoked by Gnome. But is there any way to improve the process to some extent known from Mac OS X?

Offline

#2 2013-05-24 10:17:59

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Improving (making faster) hibernation

Macbook doesn't hibernate when you close the laptop's lid. It uses something similar to hibernate-to-both (hybrid-sleep), practically it suspends, and while it suspends, it hibernates. So, if the user opens the lid, it is as fast as a resume from ram, but if the macbook run out of battery, it still has saved everything, so you won't lost data.
This is, as far as I know, how it works...may be there is someone here who can explain better (it may also be i'm wrong).

Offline

#3 2013-05-24 10:18:49

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Improving (making faster) hibernation

Interesting. Can I use something similar to that hybrid on Linux?

Offline

#4 2013-05-24 10:38:11

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Improving (making faster) hibernation

systemctl hybrid-sleep

Offline

#5 2013-05-24 12:02:30

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Improving (making faster) hibernation

If that is the equivalent on Linux, then the results are poor.

- Hibernation and restoration are not significantly faster than normal hibernation. Especially on restoration it takes enormous time until my system is responsive again
- After hibernation my laptop is not completely shut down as indicated by the lucent standby icon.

Offline

#6 2013-05-24 12:13:07

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Improving (making faster) hibernation

1) i don't know, i don't use this kind of suspend, sorry
2) after "systemctl hybrid-sleep" system is suspended to ram, not to disk, so it isn't shutdown, it is only suspended. (and standby icon stays on)

Offline

#7 2013-05-24 12:19:36

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Improving (making faster) hibernation

But because you are suspended to RAM, waking up should be faster (than from plain hibernation). Is it also slow after a normal suspend? Entering hybrid-sleep could be slow (like hibernation) because it writes memory contents to disk first (i.e. the nice mac way may not (yet?) be implemented in the kernel, or only on specific hardware). Haven't tried it myself.

Offline

#8 2013-06-24 14:38:14

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Improving (making faster) hibernation

Hi Raynman,

Sorry for late response. To answer your question: no suspend to ram and restoration from the same is fast. I assume that for now there is nothing to do except waiting for more efficient implementations of hibernation in future kernel versions.

Offline

#9 2013-06-24 15:24:58

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Improving (making faster) hibernation

Closing a macbook's lid does not make it hibernate, only suspend to RAM.

Hibernation will always be quite slow as it depends on how fast your machine can POST and load the kernel.

Offline

#10 2013-06-24 15:29:18

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Improving (making faster) hibernation

depends on how fast your machine can POST and load the kernel.

So, in principle a matter of CPU power?

But thanks for the clarification on the macbook's lid action!

Offline

#11 2013-06-24 15:42:00

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Improving (making faster) hibernation

orschiro wrote:

So, in principle a matter of CPU power?

No, not really. I have a server with 64 cores which takes 10+ minutes to reboot because of the hardware initialization and memory testing that's performed at power on. Conversely, my desktop with 12 cores boots from power on to login in under 10 seconds.

Offline

#12 2013-06-24 16:55:03

boast
Member
Registered: 2010-09-28
Posts: 219

Re: Improving (making faster) hibernation

How does Chrome OS handle it? Is it slow on there as well?


Asus M4A785TD-V ;; Phenom II X4 @ 3.9GHz ;; Ripjaws 12GB DDR3-1600 ;; 128GB Samsung 830 ;; MSI GTX460 v2 w/ blob ;; Arch Linux + KDE 4.x

Offline

#13 2013-06-24 18:28:54

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Improving (making faster) hibernation

@boast, I don't know how ChromeOS handles it, but the original question here is flawed.  Orschiro just does not understand how OSX handles its sleep states, so trying to make Linux match a function that he doesn't really understand is going to be a fruitless endeavor. 

FWIW, falcondindy is right in that what orschiro thinks is hibernation is actually just suspend to ram.  Though the macbook can be configured to do a hybrid sleep that both suspends to ram as well as suspends to disk.  But in this case, it will take longer to go into sleep, just as normal hibernation would, but upon wake it would just be waking from the suspend to ram like usual.  Linux has actually implemented this functioanlity recently with hybrid sleep.  In fact, systemd has implemented the ability to use this with "systemctl hybrid-sleep" as mentioned by nierro above.

What OSX has that Linux does not is a really pretty wake when the system actually does wake from hibernation.  But you still have to go through a POST process and it still loads the kernel and does all the hardware initialization stuff.  But they have just given it a nice overlay so that you don't see all that crap going on.  But it is not by any means fast.

Offline

#14 2013-06-24 22:57:09

Strike0
Member
From: Germany
Registered: 2011-09-05
Posts: 1,429

Re: Improving (making faster) hibernation

I just tried it another way. If the system supports pm-suspend-hybrid one can

 cat /etc/pm/config.d/00-suspend-hybrid 
# Use suspend_hybrid instead of suspend
if [ "$METHOD" = "suspend" ]; then
	METHOD=suspend_hybrid
fi
PM_HIBERNATE_DELAY=20  # time in seconds until hibernate occurs after suspend

With this the suspended notebook woke up after 20 seconds to go straight into hibernate. After the first try it was hanging with a dmesg of "Dazzed and confused. Are you using some strange powersaving?". Sweet and true. After disabling them, it resumes from suspend-hibernate. I still have to figure out which powersaving made it hang.

Imho a neat variation, because one can let the machine hibernate after, say an hour, automagically if it was not resumed from suspend meanwhile. You only want to do this on notebooks with a SSD for apparent reasons ..
If someone knows how to do such with systemd (or if it is coming), that would be great.

Offline

#15 2013-06-28 08:03:08

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Improving (making faster) hibernation

Nice ida Strike0!

Just let me ask some questions.

1. Here you are using pm-utils. Is this also possible with pure systemd?

2. Essentially, this will make the whole hibernation process faster (by first suspending and then silently hibernating, correct?). Time needed for resuming from hibernation, however, will be unchanged?

3. Why does this make no sense for non-SSD systems?

Offline

#16 2013-06-28 08:50:36

forumache
Member
From: Netherlands
Registered: 2011-09-02
Posts: 55

Re: Improving (making faster) hibernation

As nierro said "systemctl hybrid-sleep" is the one you are looking for.

It suspends to ram and writes to disk. Writing to disk takes time. Then it suspends.
When it restores, if there was now power cut or battery depleted events, it restores from standby.
If there was a power cut or battery depleted, then it will load its previous state from hibernation.

I tested and it works great. I don't have a Macbook to test, but my guess is either:
- it goes into standby and not hibernation when you close the lid (try to remove battery and put it back, if it was standby only, the state will be lost)
- it goes into hibernation but previously send a signal to hdd to turn off the led (just speculating here, but Apple tends to hide things for a worry free (in their opinnion) experience)

Offline

#17 2013-06-28 09:57:40

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,397

Re: Improving (making faster) hibernation

emptying buffer and caches before going to hibernation and using threads (uswsusp-git) when compressing the image will make your system hibernated really FAST.
Restoring the image will be FAST too, but you'll pay that by having a system that will be slow in the first minutes of use.


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#18 2013-06-28 09:59:26

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Improving (making faster) hibernation

kokoko3k wrote:

emptying buffer and caches before going to hibernation and using threads (uswsusp-git) when compressing the image will make your system hibernated really FAST.
Restoring the image will be FAST too, but you'll pay that by having a system that will be slow in the first minutes of use.

Can you please explain more detailed how to do this?

Offline

#19 2013-06-28 10:27:31

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,397

Re: Improving (making faster) hibernation

http://www.commandlinefu.com/commands/v … ffer-cache
https://wiki.archlinux.org/index.php/Us … figuration
For my hibernation purposes i use an hand written script filled with my hand-written quirks and i associate it with an hotkey, so i can't help you on how to automate it with (say) systemd.

On a side note, i avoid hybrid solutions as i care about battery health.
Blindly using hybrid sleep drains power uselessly and will make your battery useless over time.

Last edited by kokoko3k (2013-06-28 10:33:24)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#20 2013-06-28 10:39:42

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Improving (making faster) hibernation

Nevertheless I would be interested to see your script.

Offline

#21 2013-06-28 10:46:54

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,397

Re: Improving (making faster) hibernation

Is it nothing special and highly customized for the hardware, something like

#! /bin/bash
#remove modules that gives problem:
rmmod X
rmmod Y
rmmod Z

#umount network shares and eventually windows drives
umount A
umount B
umount C

sync #<-ensure that everything has been written to disk

echo 3 > /proc/sys/vm/drop_caches #<-i don't use it, but you may want, free as much as ram as possible

s2disk #<-we hibernate here

# so when the following is executed, we're awake again

#insert modules previously disabled
modprobe X
modprobe Y
modprobe Z
#remount previous mounts
mount A
mount B
mount C

Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#22 2013-06-28 11:41:14

Strike0
Member
From: Germany
Registered: 2011-09-05
Posts: 1,429

Re: Improving (making faster) hibernation

To your questions with the pm_utils quirk I posted oschiro:
1. I'm using systemd suspend/hibernate too and have not tried to fiddle it into the systemd setup. Mainly because I'm really happy with how stable suspend/hibernate works. Maybe someone else has input what would be necessary (or why it is not a good idea) for systemd.
2. Yes, it does not reduce time to hibernate/resume per se. The automatism just makes resuming faster when it did not hibernate already due to the time delay. Effectively this is the only advantage of it to the native systemd "hybrid-sleep" method as explained by nierro and forumache and therefore not fully on-spot for your thread-title.
3. You want to avoid carrying a suspended notebook around in a backpack and the machine suddenly resumes. It may be the final, eternal hibernate for the HDD platters ..

That said if your machine has a SSD only and you configure it to "systemd hybrid-sleep" as detailed above, nothing much is gained speedwise by the quirk I posted retrospectively. It would save battery though (on longer suspends).

Offline

Board footer

Powered by FluxBB