System can rarely hibernate

Hi,

I’ve been having a lot of issues getting my system to hibernate for a while now on my laptop. I originally had an installation of Manjaro and selected that I wanted to use hibernate when installing; that worked fine when using suspend-then-hibernate. At a later point, I swapped back to an old drive with Windows on it and setup a dual boot. I manually partitioned and made my swap partition roughly 2x my RAM.

Since then, I’ve had a lot of trouble hibernating. I now use hibernate immediately, since systemd changed the suspend-then-hibernate behavior and it hasn’t worked well with my system since then. When I hibernate, the laptop screen freezes up for a few seconds, then kicks me back to the login page. Sometimes it will work, but that’s probably 25% of the time at most.

Here’s what systemctl status systemd-hibernate.service looks like after a fresh restart and before attempting a hibernate:

○ systemd-hibernate.service - Hibernate
Loaded: loaded (/usr/lib/systemd/system/systemd-hibernate.service; static)
Active: inactive (dead)
Docs: man:systemd-hibernate.service(8)

After trying and failing, this is the output:

× systemd-hibernate.service - Hibernate
Loaded: loaded (/usr/lib/systemd/system/systemd-hibernate.service; static)
Active: failed (Result: exit-code) since Wed 2023-09-13 18:51:14 EDT; 21s ago
Docs: man:systemd-hibernate.service(8)
Process: 9640 ExecStart=/usr/lib/systemd/systemd-sleep hibernate (code=exited, status=1/FAILURE)
Main PID: 9640 (code=exited, status=1/FAILURE)
CPU: 15.338s
Sep 13 18:50:56 keylimepie systemd[1]: Starting Hibernate…
Sep 13 18:50:56 keylimepie systemd-sleep[9640]: Entering sleep state ‘hibernate’…
Sep 13 18:51:14 keylimepie systemd-sleep[9640]: Failed to put system to sleep. System resumed again: Cannot allocate memory
Sep 13 18:51:14 keylimepie systemd[1]: systemd-hibernate.service: Main process exited, code=exited, status=1/FAILURE
Sep 13 18:51:14 keylimepie systemd[1]: systemd-hibernate.service: Failed with result ‘exit-code’.
Sep 13 18:51:14 keylimepie systemd[1]: Failed to start Hibernate.
Sep 13 18:51:14 keylimepie systemd[1]: systemd-hibernate.service: Consumed 15.338s CPU time.

It took me a long journey of research to find out how to get to this memory allocation error log, but I don’t know what that means in this context or how it could happen. My system has about 10GB of usable RAM, 20GB swap partition, and about 7GB of RAM and 2GB of swap were in use at the time.

Please let me know if any other information would be useful and thank you in advance for any help.

Hi @ryoung10, and welcome!

I am in no way an expert, but I would suggest you work thorough this:

https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Troubleshooting

After having troubles with suspending not too long ago, this helped me very well, so I’d suggest it.

You need to follow 3 steps to make hibernation work:

  1. Create a swap partition that’s suitable to your RAM

  2. Add kernel parameter resume in /etc/default/grub like this:
    GRUB_CMDLINE_LINUX_DEFAULT="quiet udev.log_priority=3 acpi_backlight=native resume=UUID=666d47c6-ca11-4222-aeaa-7eac4d05b4f5"
    You can get that UUID by executing lsblk -f in terminal.

  3. Check that resume is added to HOOKS in /etc/mkinitcpio.conf like this:
    HOOKS=(base udev autodetect modconf kms keyboard keymap consolefont block filesystems resume fsck)
    then run sudo mkinitcpio -P

At the end, reboot two times. (first reboot needed to apply kernel parameter)

2 Likes

Hi, thank you for the replies. To clarify, my system can hibernate (I already did the three steps shown above), but it doesn’t do it consistently; there are no issues waking from hibernate.

I tried the steps in the linked troubleshooting page that seemed relevant, but I’m still having issues. I re-read the Manjaro wiki page on Swap which suggested changing my system’s swappiness. I set that to 10 which did seem to affect how often my swap is being used, but I’m still getting the same error about lack of memory.

Here’s some additional output I found in the journal:

Sep 19 18:27:24 keylimepie kernel: PM: hibernation: Error -12 creating image
Sep 19 18:27:24 keylimepie kernel: PM: hibernation: Not enough free memory
Sep 19 18:27:24 keylimepie kernel: PM: hibernation: Normal pages needed: 1451504 + 1024, available pages: 1153397
Sep 19 18:27:24 keylimepie kernel: PM: hibernation: Need to copy 1451504 pages
Sep 19 18:27:24 keylimepie kernel: PM: hibernation: Creating image:

I’m not really familiar enough with systemd/hibernation to know what the numbers are referring to. Are the pages referring to my RAM or swap space or something else?

The size of the swap device. As a rule, you should create a swap device twice the size of your RAM, because it needs to hold all that is in RAM plus all that’s already on the swap device.

1 Like

Here’s the output of free -h before attempting the hibernate which the journal logs come from:

-------- | total | used | free | shared | buff/cache | available |
Mem : | 7Gi | 7.7Gi | 1.8Gi | 71Mi | 531Mi | 2.0Gi |
Swap: | 19Gi | 7.4Gi | 12Gi |

Side note: The swap usage was around 1GB before I attempted a previous hibernate. When the hibernate failed and the system came back, the swap usage was roughly the RAM usage pre-hibernate.

There’s enough free swap to fit my entire RAM, but it still failed. Or am I missing something or not looking at the numbers the right way?