Summary
Since a few months back, not quite sure when, my hibernation started to fail. By failing I mean that when executed using systemd it would initialize the lock screen, blacked the screen, only to come back to the lock screen instead of hibernating.
In order to be able to hibernate I would have to shutdown several programs, namely Spotify, until hibernation was successful.
The issue
This indicates that I had not enough swap space to hibernate, but that’s not the case, as I recently increased swap to 12 GiB and I only have 8 GiB of RAM. Swap should be empty as I have set swappiness to zero and haven’t got any memory intensive tasks running (however this is not the case there’s always residual swap in my system in the order of 100 MiB).
Since memory doesn’t seem to be a problem let’s check the failed hibernation attempt on journalctl
:
$ sudo journalctl -u systemd-hibernate.service
ago 12 02:03:23 UD-Legion systemd[1]: Starting Hibernate...
ago 12 02:03:23 UD-Legion systemd-sleep[42318]: [33] INFO: # Pre-suspend hook
ago 12 02:03:23 UD-Legion systemd-sleep[42318]: [33] INFO: Previous state was: {'type': 'done', 'switch_id': '20210811T113119', 'current_mode': 'integrated'}
ago 12 02:03:23 UD-Legion systemd-sleep[42318]: [37] INFO: Switching option: none
ago 12 02:03:23 UD-Legion systemd-sleep[42318]: [37] INFO: Turning Nvidia GPU back on
ago 12 02:03:23 UD-Legion systemd-sleep[42378]: modinfo: ERROR: Module bbswitch not found.
ago 12 02:03:23 UD-Legion systemd-sleep[42382]: modinfo: ERROR: Module acpi_call not found.
ago 12 02:03:24 UD-Legion systemd-sleep[42318]: [648] INFO: switching=none, nothing to do
ago 12 02:03:24 UD-Legion systemd-sleep[42318]: [649] INFO: Writing state {'type': 'pending_post_resume', 'switch_id': '20210811T113119', 'current_mode': 'integrated'}
ago 12 02:03:24 UD-Legion systemd-sleep[42318]: [649] INFO: Pre-suspend hook completed successfully.
ago 12 02:03:24 UD-Legion systemd-sleep[42315]: Suspending system...
ago 12 02:03:28 UD-Legion systemd-sleep[42315]: Failed to suspend system. System resumed again: Cannot allocate memory
ago 12 02:03:28 UD-Legion systemd-sleep[42571]: [18] INFO: # Post-resume hook
ago 12 02:03:28 UD-Legion systemd-sleep[42571]: [19] INFO: Previous state was: {'type': 'pending_post_resume', 'switch_id': '20210811T113119', 'current_mode': 'integrated'}
ago 12 02:03:28 UD-Legion systemd-sleep[42571]: [20] INFO: Turning Nvidia GPU off again
ago 12 02:03:29 UD-Legion systemd-sleep[42659]: modinfo: ERROR: Module bbswitch not found.
ago 12 02:03:29 UD-Legion systemd-sleep[42666]: modinfo: ERROR: Module acpi_call not found.
ago 12 02:03:29 UD-Legion systemd-sleep[42571]: [612] INFO: switching=none, nothing to do
ago 12 02:03:29 UD-Legion systemd-sleep[42571]: [613] INFO: Writing state {'type': 'done', 'switch_id': '20210811T113119', 'current_mode': 'integrated'}
ago 12 02:03:29 UD-Legion systemd-sleep[42571]: [613] INFO: Post-resume hook completed successfully.
ago 12 02:03:29 UD-Legion systemd[1]: systemd-hibernate.service: Main process exited, code=exited, status=1/FAILURE
ago 12 02:03:29 UD-Legion systemd[1]: systemd-hibernate.service: Failed with result 'exit-code'.
ago 12 02:03:29 UD-Legion systemd[1]: Failed to start Hibernate.
ago 12 02:03:29 UD-Legion systemd[1]: systemd-hibernate.service: Consumed 3.557s CPU time.
As you can see it does in fact state that it is not able to allocate memory, although it has plenty of space left!
After closing Spotify journalctl
shows a successful hibernation, even if with the same warnings related to the NVIDIA dGPU:
$ sudo journalctl -u systemd-hibernate.service
ago 12 02:03:56 UD-Legion systemd[1]: Starting Hibernate...
ago 12 02:03:56 UD-Legion systemd-sleep[43072]: [14] INFO: # Pre-suspend hook
ago 12 02:03:56 UD-Legion systemd-sleep[43072]: [14] INFO: Previous state was: {'type': 'done', 'switch_id': '20210811T113119', 'current_mode': 'integrated'}
ago 12 02:03:56 UD-Legion systemd-sleep[43072]: [15] INFO: Switching option: none
ago 12 02:03:56 UD-Legion systemd-sleep[43072]: [16] INFO: Turning Nvidia GPU back on
ago 12 02:03:56 UD-Legion systemd-sleep[43092]: modinfo: ERROR: Module bbswitch not found.
ago 12 02:03:56 UD-Legion systemd-sleep[43095]: modinfo: ERROR: Module acpi_call not found.
ago 12 02:03:56 UD-Legion systemd-sleep[43072]: [488] INFO: switching=none, nothing to do
ago 12 02:03:56 UD-Legion systemd-sleep[43072]: [488] INFO: Writing state {'type': 'pending_post_resume', 'switch_id': '20210811T113119', 'current_mode': 'integrated'}
ago 12 02:03:56 UD-Legion systemd-sleep[43072]: [488] INFO: Pre-suspend hook completed successfully.
ago 12 02:03:56 UD-Legion systemd-sleep[43069]: Suspending system...
Here’s the amount of memory (RAM + Swap) available on my system (after waking up from the latest hibernation attempt):
$ free -m
total used free shared buff/cache available
Mem: 7851 3095 2997 721 1757 3663
Swap: 12286 78 12208
Using systemd to check the status of the hibernation unit file reveals the following:
$ sudo systemctl status hibernate.target
○ hibernate.target - System Hibernation
Loaded: loaded (/usr/lib/systemd/system/hibernate.target; static)
Active: inactive (dead)
Docs: man:systemd.special(7)
ago 11 18:15:42 UD-Legion systemd[1]: Reached target System Hibernation.
ago 11 18:15:42 UD-Legion systemd[1]: Stopped target System Hibernation.
ago 11 22:50:34 UD-Legion systemd[1]: Reached target System Hibernation.
ago 11 22:50:34 UD-Legion systemd[1]: Stopped target System Hibernation.
ago 12 00:11:40 UD-Legion systemd[1]: Reached target System Hibernation.
ago 12 00:11:40 UD-Legion systemd[1]: Stopped target System Hibernation.
ago 12 02:03:29 UD-Legion systemd[1]: Dependency failed for System Hibernation.
ago 12 02:03:29 UD-Legion systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
ago 12 11:32:02 UD-Legion systemd[1]: Reached target System Hibernation.
ago 12 11:32:02 UD-Legion systemd[1]: Stopped target System Hibernation.
Which when the hibernation fails (check the timestamp) it says something about a dependency.
When looking into /usr/lib/systemd/system/hibernate.target
it says that it depends on hibernate.service
but I wasn’t able to find it.
Files in relevant directories
In the folder /usr/lib/systemd/system-sleep
I have 3 files, nvidia
, optimus-manager.py
and tlp
:
$ cat nvidia
#!/bin/sh
case "$1" in
post)
/usr/bin/nvidia-sleep.sh "resume"
;;
esac
$ cat optimus-manager.py
#!/usr/bin/env python3
import sys
from optimus_manager.hooks import pre_suspend, post_resume
def main():
try:
state = sys.argv[1] # pre or post
_mode = sys.argv[2] # suspend, hibernate or hybrid-sleep
except IndexError:
print("Not enough arguments")
sys.exit(1)
if state == "pre":
pre_suspend.main()
elif state == "post":
post_resume.main()
else:
print(f"Invalid first argument: {state}")
sys.exit(1)
if __name__ == "__main__":
main()
$ cat tlp
#!/bin/sh
# tlp - systemd suspend/resume hook
#
# Copyright (c) 2020 Thomas Koch <linrunner at gmx.net> and others.
# This software is licensed under the GPL v2 or later.
case $1 in
pre) tlp suspend ;;
post) tlp resume ;;
esac
In /etc/systemd/system/sleep.target.wants
I only have one file to initialize the lockscreen:
$ cat betterlockscreen@undercover.service
[Unit]
Description = Lock screen when going to sleep/suspend
Before=sleep.target
Before=suspend.target
[Service]
User=%I
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/betterlockscreen --lock
TimeoutSec=infinity
ExecStartPost=/usr/bin/sleep 0.25
[Install]
WantedBy=sleep.target
WantedBy=suspend.target
System specs
OS: Manjaro (installed from the Architect installer)
WM: i3
Kernel: 5.4.138-1 x64
GPU: iGPU (Intel) + dGPU (NVIDIA 1050Ti)
Swap is available on it’s own partition and mounted in /etc/fstab