Score:0

How to debug slow hibernation

sd flag

I have several PCs/laptops running an up-to-date Ubuntu 20.04 with currently a 64bit kernel 5.4.0-74-generic as provided by default Ubuntu repos. One of them, a rather ordinary PC with an Intel i3 CPU, takes a bit more than 2 minutes to hibernate since I upgraded from 18.04 to 20.04.

Various resources I found about debugging hibernation mostly cover the wake-up or complete failure to suspend but not a suspend-to-disk that takes very long. The wake-up works fine and takes only seconds. How can I find out what takes so long to hibernate? Is there something like systemd-analyze blame for hibernation?

So far I added initcall_debug no_console_suspend to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub and it does show the console, however, nothing is shown that explains the long time. It shows "Detected Hardware Unit Hang" for the network interface. But this appears right at the beginning of hibernation, and I guess it is expected behavior.

I use systemctl hibernate to initiate it. It takes 2 minutes until poweroff even when run as root at the console with no other logged in users or user processes.

Score:0
sd flag

My advice:

  1. Decide to ask a question @ askubuntu.com and be serious about it ;) Collect data, reproduce issues with minimal setups, and be specific.

  2. Make sure there is enough swap space. The command free gives the amount of RAM ("Mem") and Swap. The total of swap should be larger than the total RAM. I realized that I had added RAM at some point but I did not increase the size of my swap partition. Edit(2021-06-07): The size difference was ~1GB. After increasing the size hibernation was repeatedly faster, but I still think that this was an artifact caused by a change of write speed of the SSD holding the swap partition. (See also next point.)

  3. How fast should hibernation be? Essentially, during suspend-to-disk all RAM is written to disk. The amount of RAM and the write speed of the disk determines the time needed. I looked for my swap partition and checked how long it takes to zero it using dd if=/dev/zero. dd reported a speed of 108 MB/s. Writing 7 GB took ~65s. My PC has 8 GB. So, I should expect hibernation to take at least a minute.

  4. Try to debug by removing parts of the system: Detach hardware that is not required. Hibernate right after a fresh boot, with or without logging in first.

  5. Add initcall_debug no_console_suspend to the kernel command line as described in the question.

For now, I guess the reasons for my experiencing slow hibernation are: I added RAM (so hibernation takes longer), I forgot to increase swap space to match the added RAM (I had 7G swap but 8G RAM), and the write speed of the SSD degraded over time (at least by a factor of 2).

Further and recommended reading:

sd flag
After adding a 2nd SATA SSD and using it for the swap partition hibernation takes only 10-15s.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.