Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Suspend / Hibernate broken when using genkernel initramfs
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
how_not_to_be_seen
n00b
n00b


Joined: 07 Nov 2021
Posts: 7
Location: Montreal, QC

PostPosted: Tue Dec 28, 2021 8:57 pm    Post subject: Suspend / Hibernate broken when using genkernel initramfs Reply with quote

Hello gentoo forums, first time caller here :)

I installed gentoo for the first time ever a few months ago on a new Thinkpad X1 Carbon Gen 9. For the most part I've been able to configure the system exactly to my liking, mostly thanks to this community--(thank you!!!!!)

There's been one small issue that's been hanging on my to do list for quite some time, and it has to do with the kernel. At the beginning of my install I used genkernel to generate my initramfs. However, ever since then, I've been hitting a consistent bug every now and then in which my machine will either freeze up and I'll need to restart it, or my machine will shut down I will have to reboot it. When this happens, it does not resume from the swap partition, it instead boots into a new session. If I keep the machine plugged into a charger, or if I keep a process running such as a playing a video or music, the issue does not occur.

My suspicion is that I'm running into an issue documented here, which has to do with a problem concerning suspend and hibernate when you generate your initramfs with genkernel. The initial user who posted about this bug provides the following solution...

Quote:

If you have no option but to use genkernel to generate the initramfs for swsusp

In /usr/share/genkernel/defaults/initrd.scripts

You need to change the line that reads (it's within swsusp_resume() )

Code:
Code:
[ -f /sys/power/resume ] && echo "${device}" > /sys/power/resume


to read

Code:
Code:
[ -f /sys/power/resume ] && echo "${device}" > /sys/power/resume && /sbin/resume


And you need to find a way to get /sbin/resume (located at /usr/lib/suspend/resume on your gentoo install) and /etc/suspend.conf into the initramfs.

I just included the commands to copy those files into a part of gen_initramfs.sh that I know gets executed on my machine.(was too lazy to do it the "right way")

But I think it might be possible to use the --initramfs-overlay= option of genkernel to achieve the same results.


So my question is, has anyone else modified their initramfs too and can provide a more detailed walkthrough on how to fix? I'm just curious what the "right way" might be[/b][/quote][/url] to fix this, for instance using --initramfs-overlay=

Please let me know if I can provide any logs or additional info. Any help is so much appreciated
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23104

PostPosted: Tue Dec 28, 2021 10:03 pm    Post subject: Reply with quote

Welcome to the forums.

If you shutdown the machine, then on next power-on, it cannot resume from swap, because there is nothing to be resumed. You must use hibernate before you can resume from hibernation. When you successfully resume from hibernation, the hibernation image in the swap area is purged. You cannot resume twice from the same hibernation image. You must create a new hibernation image if you want to resume a second time.

I would not put much faith in that thread. It is 8 years old. It received no responses confirming or rejecting its suggested change. The user you quoted has been a member since 2004, and accumulated only 33 posts since then. That is not the mark of an active user. That doesn't mean the user cannot be an expert in an area, but I'd be more inclined to trust advice from someone who is routinely active offering correct answers to other users.

As I understand that thread, without the change, the system could never resume from hibernation. As I understand your thread, resume from hibernate works when there is an image to resume. Therefore, I think you have a different problem than that poster. Assuming that poster's analysis and solution were correct, the issue was that the system was using suspend-tools to hibernate, but not using the resume program from suspend-tools to recover. Hibernation and resume must be done using the same toolset. If you hibernate using the in-kernel hibernation, you must resume from the in-kernel hibernation.

Please confirm that if you properly hibernate the system, it can resume cleanly later. If yes, you don't have the same problem as that thread.
Back to top
View user's profile Send private message
how_not_to_be_seen
n00b
n00b


Joined: 07 Nov 2021
Posts: 7
Location: Montreal, QC

PostPosted: Wed Dec 29, 2021 4:01 am    Post subject: Reply with quote

Thanks for the help. I just ran sudo loginctl hibernate and the machine turns off. When I reboot however, I do not resume where I left off, in other words all previous windows are closed, etc. I get a suspicious error message as well while booting...

Code:

* Checking local filesystems ...
* /dev/nvme0n1p4: clean, 1562469/15114240 files, 13416945/60440918 blocks
fsck.fat 4.2 (2021-01-31)
Dirty bit is set. Fs was not properly unmounted and some data may be corrupted.
   Automatically removing dirty bit.

*** Filesystem was changes ***
Writing changes
/dev/nvme0n1p2: 368 files, 36946/65399 clusters
* Filesystems repaired


Additionally here's some output from running dmesg that seems to be related to hibernatoin

Code:

[    0.044566] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.044582] PM: hibernation: Registered nosave memory: [mem 0x00000000-0x00000fff]
[    0.044584] PM: hibernation: Registered nosave memory: [mem 0x0009f000-0x000fffff]
[    0.044585] PM: hibernation: Registered nosave memory: [mem 0x89f25000-0x89fb5fff]
[    0.044587] PM: hibernation: Registered nosave memory: [mem 0x8b606000-0x8b606fff]
[    0.044588] PM: hibernation: Registered nosave memory: [mem 0x8ef6f000-0x8f03efff]
[    0.044589] PM: hibernation: Registered nosave memory: [mem 0x8f03f000-0x93f2efff]
[    0.044590] PM: hibernation: Registered nosave memory: [mem 0x93f2f000-0x94b2efff]
[    0.044591] PM: hibernation: Registered nosave memory: [mem 0x94b2f000-0x94bfefff]
[    0.044592] PM: hibernation: Registered nosave memory: [mem 0x94c00000-0x991fffff]
[    0.044593] PM: hibernation: Registered nosave memory: [mem 0x99200000-0x999fffff]
[    0.044594] PM: hibernation: Registered nosave memory: [mem 0x99a00000-0xa07fffff]
[    0.044595] PM: hibernation: Registered nosave memory: [mem 0xa0800000-0xbfffffff]
[    0.044596] PM: hibernation: Registered nosave memory: [mem 0xc0000000-0xcfffffff]
[    0.044596] PM: hibernation: Registered nosave memory: [mem 0xd0000000-0xfed1ffff]
[    0.044597] PM: hibernation: Registered nosave memory: [mem 0xfed20000-0xfed7ffff]
[    0.044598] PM: hibernation: Registered nosave memory: [mem 0xfed80000-0xffffffff]
[    0.044600] [mem 0xd0000000-0xfed1ffff] available for PCI devices
[    0.044601] Booting paravirtualized kernel on bare hardware
[    0.044604] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 6370452778343963 ns
[    0.049447] setup_percpu: NR_CPUS:8192 nr_cpumask_bits:8 nr_cpu_ids:8 nr_node_ids:1
[    0.049656] percpu: Embedded 56 pages/cpu s192512 r8192 d28672 u262144
[    0.049662] pcpu-alloc: s192512 r8192 d28672 u262144 alloc=1*2097152
[    0.049663] pcpu-alloc: [0] 0 1 2 3 4 5 6 7
[    0.049690] Built 1 zonelists, mobility grouping on.  Total pages: 4057942
[    0.049691] Policy zone: Normal
[    0.049693] Kernel command line: BOOT_IMAGE=/vmlinuz-5.10.61-gentoo-x86_64 root=UUID=c9e7cbff-8a48-4d0f-83d1-198fd08e483e ro
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23104

PostPosted: Wed Dec 29, 2021 4:23 am    Post subject: Reply with quote

You should not need sudo here.

Which method do you use to enter hibernate: tuxonice, uswusp, or in-kernel swsusp? How does your machine know to resume on boot? I don't see a resume= line in the kernel command line, so the initramfs would need to instruct the kernel to resume. Does it?
Back to top
View user's profile Send private message
how_not_to_be_seen
n00b
n00b


Joined: 07 Nov 2021
Posts: 7
Location: Montreal, QC

PostPosted: Wed Dec 29, 2021 3:09 pm    Post subject: Reply with quote

I'm not entirely sure how to find out which of those three hibernation methods I'm using. But perhaps that's because I never even configured any of them to function, since that resume= line is missing from reboot :oops:. Would this be something I need to edit in my grub config? The docs list the following...

Code:

GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=<UUID_of_partition> resume_offset=<offset_of_swapfile>"
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23104

PostPosted: Wed Dec 29, 2021 5:21 pm    Post subject: Reply with quote

A resume= line is not mandatory if your kernel is configured with a default. However, a resume= is commonly used. Since tuxonice is not in mainline, you are probably not using that. I do not know which method loginctl uses by default, as I do not use loginctl to suspend. I find it to be a very bad idea that any of my processes can suspend the system. That seems like a designed-in security problem.

You will need to determine what method loginctl uses, then configure resume accordingly. You could guess that it uses in-kernel swsusp, and set a resume= line pointing to your unencrypted swap device. If that guess is right, then this should start working. If it is wrong, it will probably not be any worse than the failed resumes you have had so far.
Back to top
View user's profile Send private message
how_not_to_be_seen
n00b
n00b


Joined: 07 Nov 2021
Posts: 7
Location: Montreal, QC

PostPosted: Sun Jan 02, 2022 7:33 pm    Post subject: Reply with quote

Hu, thanks so much for your help. I'm now under the impression that my problem might not be related to hibernate at all.

I rebuilt my kernel to disable support for hibernation, so now when I force run loginctl hibernate nothing happens. Suspend still works as expected.

However, my laptop is still shutting off periodically at unexpected times unless I have a charger plugged in or a consistent process running such as playing audio or video. Are there any logs that I might be able to post other than dmesg that might be helpful to indicate what might be the problem? Some other software I'm using that I suspect might be related to this issue are acpi and laptop_mode.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23104

PostPosted: Sun Jan 02, 2022 7:39 pm    Post subject: Reply with quote

That seems like semi-expected / desirable behavior. It's common for laptop users to want a laptop to gracefully hibernate/halt if it is not "busy" and is on battery power, so that it can halt gracefully instead of crashing when power runs out. Is it doing this even when you are active at the console and using it, such that a screenlocker would not be appropriate? That would be undesirable and annoying. However, if it only halts when left alone, that seems like a power-saving feature in action. I would start by examining laptop_mode and related tools to see if they are configured to do this on purpose.
Back to top
View user's profile Send private message
how_not_to_be_seen
n00b
n00b


Joined: 07 Nov 2021
Posts: 7
Location: Montreal, QC

PostPosted: Sun Jan 02, 2022 7:50 pm    Post subject: Reply with quote

Yes, there have been quite a few times where it shuts down just seconds after giving the console input or editing text in vim, which seems to be like undesirable behavior. And it continues to do this even though hibernate is disabled.

Agreed, checking laptop mode and other power saving tools I have is a good idea, I'm going to investigate some options in there and see if anything changes over the next week. I'll post any updates I have as they come.
Back to top
View user's profile Send private message
how_not_to_be_seen
n00b
n00b


Joined: 07 Nov 2021
Posts: 7
Location: Montreal, QC

PostPosted: Sun Jan 09, 2022 3:01 pm    Post subject: Reply with quote

Ok, it's been about a week and I think I'm finally getting to the bottom of this...

After fiddling with the settings in my Thinkpad's BIOS, I eventually turned something called "CPU Power Management" from on to off. The description of this setting says...

Enables or disables the power saving feature that stop the microprocessor clock automatically when there are no system activities. Normally, it's not necessary to change this setting

I've been using my laptop for about a week with this setting turned off, and I can confirm there are no more sudden shutdowns, yay!

However, two side affects have manifested. The first, obviously, is that my computer drains its battery ridiculously fast when in suspend mode. The other is that my laptop gets very warm, and I sometimes begin using huge amounts of CPU even when doing simple things like using a text editor.

Are there areas of the kernel / external packages[/i] where I might be able to mimic this "CPU Power Management" feature?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum