You are not logged in.

#1 2020-02-08 23:44:00

jayache80
Member
Registered: 2015-11-19
Posts: 23

[SOLVED] hibernation using uswsusp with swapfile and btrfs

Hello,

I'm having trouble getting my Mid-2009 Macbook Pro 5,5 (with 4GB of memory) to hibernate by running the s2disk command.

When I run s2disk, here are the problems that occur:
1. I see a message that s2disk is "snapshotting" but the machine does not shutdown. Rather, it just goes to sleep. I then force the machine to shutdown with the power button.
2. When I start the machine up it does not resume from this "snapshot" state. It just boots up as normal.

Here are the things I've done to get to this point:
Created a swapfile:

truncate -s 0 /swapfile
chattr +C /swapfile
btrfs property set /swapfile compression none
fallocate -l 4.1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
>> /etc/fstab cat << EOD
/swapfile none swap defaults 0 0
EOD

I tested swap with a little tester program that allocates several gigabytes of RAM on the heap, and I saw that the swapfile gets correctly used.

/swapfile lives on the root partition, /dev/sda2, and I found its offset using

filefrag -v /swapfile

Incidentally, some internet research shows that finding the offset of a file on btrfs may require using this tool, however, I found that I got the same result with the filefrag tool.

Anywho, I found that offset to be 627358 and went on to install uswsusp from AUR. I set up /etc/suspend.conf as follows:

resume device = /dev/sda2
resume offset = 627358

Then, from what I understand, to get initramfs to do the resume, you have to modify /etc/mkinitcpio.conf to place uresume before filesystems as follows:

HOOKS=(base udev autodetect modconf block uresume filesystems keyboard fsck)

And then rebuild initramfs:

mkinitcpio -p linux

To tell systemd to run s2disk when I run systemctl hibernate I created this setting in /etc/systemd/system/systemd-hibernate.service.d/override.conf

[Service]
ExecStart=/usr/bin/s2disk

In an attempt to force the shutdown during hibernation, I added this to /etc/suspend.conf

shutdown method = shutdown

But it doesn't make a difference.

From what I understand, I shouldn't need to modify kernel boot parameters because this is the "userspace software suspension" thing. However, in a last ditch effort, I added in the resume and resume_offset boot parameters to /etc/default/grub as follows:

GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/sda2 resume_offset=627358 loglevel=3 quiet"

and rebuilt grub.cfg using

grub-mkconfig -o /boot/grub/grub.cfg

That didn't make a difference.

I don't see any messages in dmesg that indicate any attempt to resume.

Might anyone see a mistake I've made, or have any inkling what's going on? Appreciation in advance!

Some data points:

  • I'm running linux kernel 5.5.2

  • Hibernation has worked on this machine previously with MacOS El Capitan and Windows 7. 

  • This machine has only Arch linux installed. There are no other operating systems on it currently. 

  • This machine has a physical problem with the sleep switch in the lid mechanism. If the machine goes to sleep, it cannot wake up. This has forced me into a "just hibernate every time" workflow, which has worked fine on other operating systems. 

Last edited by jayache80 (2020-02-12 08:32:58)

Offline

#2 2020-02-09 10:55:30

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,680
Website

Re: [SOLVED] hibernation using uswsusp with swapfile and btrfs

Have you seen the note here? And this comment in the bug report?

And anyway swapfiles are a horrible hack, just use a swap partition instead.

Offline

#3 2020-02-09 22:21:46

jayache80
Member
Registered: 2015-11-19
Posts: 23

Re: [SOLVED] hibernation using uswsusp with swapfile and btrfs

Whoops! Thanks for pointing those out. I believe I came across that note in the power management/suspend and hibernate wiki, but somehow had the impression that the fix had been merged in. I guess I jumped the gun. I'll try the patch and see if it fixes my issues.

Can you please elaborate on your statement?

swapfiles are a horrible hack

From what I've read (speaking in general as I realize that support for swapfiles in btrfs is relatively new and previously unsupported) there's not much difference between a swap partition and a swapfile except that swapfiles have the ability to be easily resized if needed. The main requirement I found was that the swapfile needed to be allocated in contiguous disk space but the swapon utility should ensure that is the case or reject the swapfile.

Also, I'm using a SSD if that matters at all.

Offline

#4 2020-02-10 02:45:29

jayache80
Member
Registered: 2015-11-19
Posts: 23

Re: [SOLVED] hibernation using uswsusp with swapfile and btrfs

I built and installed the latest systemd-git per the following:

git clone https://aur.archlinux.org/systemd-git.git
cd systemd-git
# Edited PKGBUILD to reflect that this is version 245
makepkg
pacman -U systemd-*pkg.tar.xz

That should've had this fix in it, which should supposedly fix my issue. Alas, same result. I see no attempt to resume. Also, my computer still doesn't shutdown when I run s2disk.

Offline

#5 2020-02-10 05:32:52

Ropid
Member
Registered: 2015-03-09
Posts: 1,069

Re: [SOLVED] hibernation using uswsusp with swapfile and btrfs

You write that filefrag and that "btrfs_map_physical.c" program both report the same numbers. Can you test that again? When I look at things here for me, I get different results on all files I'm trying to use for testing. I don't use a swapfile, so the files I used are just some random files.

Offline

#6 2020-02-10 06:56:43

jayache80
Member
Registered: 2015-11-19
Posts: 23

Re: [SOLVED] hibernation using uswsusp with swapfile and btrfs

Thank you for chiming in.

Using filefrag

$ sudo filefrag -v /swapfile 
Filesystem type is: 9123683e
File size of /swapfile is 4402341478 (1074791 blocks of 4096 bytes)
 ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        0..       0:     627358..    627358:      1:            
   1:        1..   65535:     627359..    692893:  65535:             unwritten
   2:    65536..  262143:    1681073..   1877680: 196608:     692894: unwritten
   3:   262144..  327679:    2339641..   2405176:  65536:    1877681: unwritten
   4:   327680.. 1074790:    2430208..   3177318: 747111:    2405177: last,unwritten,eof
/swapfile: 4 extents found

Which led me to choose 627358 (the first physical offset)

Using btrfs_map_physical.c

$ sudo ./btrfs_map_physical /swapfile 
FILE OFFSET	FILE SIZE	EXTENT OFFSET	EXTENT TYPE	LOGICAL SIZE	LOGICAL OFFSET	PHYSICAL SIZE	DEVID	PHYSICAL OFFSET
0	4096	0	regular	268435456	2569658368	268435456	1	2569658368
4096	268431360	4096	prealloc	268435456	2569658368	268435456	1	2569658368
268435456	268435456	0	prealloc	268435456	6885675008	268435456	1	6885675008
536870912	268435456	0	prealloc	268435456	7154110464	268435456	1	7154110464
805306368	268435456	0	prealloc	268435456	7422545920	268435456	1	7422545920
1073741824	268435456	0	prealloc	268435456	9583169536	268435456	1	9583169536
1342177280	268435456	0	prealloc	268435456	9954131968	268435456	1	9954131968
1610612736	268435456	0	prealloc	268435456	10222567424	268435456	1	10222567424
1879048192	268435456	0	prealloc	268435456	10491002880	268435456	1	10491002880
2147483648	268435456	0	prealloc	268435456	10759438336	268435456	1	10759438336
2415919104	268435456	0	prealloc	268435456	11027873792	268435456	1	11027873792
2684354560	268435456	0	prealloc	268435456	11296309248	268435456	1	11296309248
2952790016	268435456	0	prealloc	268435456	11564744704	268435456	1	11564744704
3221225472	268435456	0	prealloc	268435456	11833180160	268435456	1	11833180160
3489660928	268435456	0	prealloc	268435456	12101615616	268435456	1	12101615616
3758096384	268435456	0	prealloc	268435456	12370051072	268435456	1	12370051072
4026531840	268435456	0	prealloc	268435456	12638486528	268435456	1	12638486528
4294967296	107376640	0	prealloc	107376640	12906921984	107376640	1	12906921984

Which led me to choose 2569658368

...which then needs to be divided by the page size

echo "2569658368 / $(getconf PAGESIZE)" | bc
627358

I did the same song and dance on some other files and they all matched.

I'm not using LVM (if that matters).

Offline

#7 2020-02-10 07:35:20

jayache80
Member
Registered: 2015-11-19
Posts: 23

Re: [SOLVED] hibernation using uswsusp with swapfile and btrfs

I'm thinking that this is lower level than not being able to hibernate correctly with a swapfile. I think this has something to do with my system not suspending properly. In other words, I should be able to

systemctl suspend

and the computer go to sleep and be able to be woken up with the touch of a key (without closely my lid).

This doesn't happen. The machine actually is hanging at a black screen (which I misinterpreted as going to sleep).

I was following this which has me do the following:

Set pm_test to freezer, devices, platform, processors, or core, and see where you fail with a hibernation. For example

echo freezer > /sys/power/pm_test
echo platform > /sys/power/disk
echo disk > /sys/power/state

seems to succeed, as I find these kernel messages in journalctl:

Feb 09 23:12:06 archbox kernel: PM: hibernation entry
Feb 09 23:12:13 archbox kernel: Filesystems sync: 0.067 seconds
Feb 09 23:12:13 archbox kernel: Freezing user space processes ... (elapsed 0.002 seconds) done.
Feb 09 23:12:13 archbox kernel: OOM killer disabled.
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0x00000000-0x00000fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0x0008f000-0x0008ffff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0x000a0000-0x000fffff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xae6b7000-0xae6b7fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xae701000-0xae705fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xae712000-0xae712fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xae722000-0xae722fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xae72b000-0xae92bfff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xaefbd000-0xaefbdfff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xaf000000-0xbeffffff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf024000-0xbf024fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf0a8000-0xbf0a8fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf0af000-0xbf0b7fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf0bb000-0xbf0bbfff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf0c4000-0xbf0c5fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf0c8000-0xbf0c9fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf10e000-0xbf111fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf11a000-0xbf11cfff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf11f000-0xbf11ffff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf225000-0xbf225fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf227000-0xbf23cfff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf242000-0xbf242fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf265000-0xbf267fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf270000-0xbf274fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf277000-0xbf277fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf279000-0xbf27bfff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf280000-0xbf280fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf70a000-0xbf70afff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf715000-0xbf716fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbf719000-0xbf719fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbfe93000-0xbfe93fff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbfe9e000-0xbfe9efff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbfec5000-0xbfeeefff]
Feb 09 23:12:13 archbox kernel: PM: Marking nosave pages: [mem 0xbfef9000-0xffffffff]
Feb 09 23:12:13 archbox kernel: PM: Basic memory bitmaps created
Feb 09 23:12:13 archbox kernel: PM: Preallocating image memory... done (allocated 309270 pages)
Feb 09 23:12:13 archbox kernel: PM: Allocated 1237080 kbytes in 1.99 seconds (621.64 MB/s)
Feb 09 23:12:13 archbox kernel: Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
Feb 09 23:12:13 archbox kernel: PM: hibernation debug: Waiting for 5 seconds.
Feb 09 23:12:13 archbox kernel: Restarting kernel threads ... done.
Feb 09 23:12:13 archbox kernel: PM: Basic memory bitmaps freed
Feb 09 23:12:13 archbox kernel: OOM killer enabled.
Feb 09 23:12:13 archbox kernel: Restarting tasks ... done.
Feb 09 23:12:13 archbox kernel: PM: hibernation exit

But when I try with 'devices'

echo devices > /sys/power/pm_test
echo platform > /sys/power/disk
echo disk > /sys/power/state

I immediately hang. I do a hard restart of the machine, and on the next boot I check out the end of the system log of the previous session (that hung) with

journalctl -b -1

And the last thing in the log is

Feb 09 23:14:20 archbox kernel: PM: hibernation entry

I think I should take a step backward and try to figure out why a simple suspend isn't working.

Offline

#8 2020-02-10 18:34:32

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,680
Website

Re: [SOLVED] hibernation using uswsusp with swapfile and btrfs

jayache80 wrote:

Can you please elaborate on your statement?

Swap is designed to work with block devices, that's why it's taken so long for swap file support to be added to btrfs. Do you really need to resize your swap space? And anyway that can also be done with a swap partition.

jayache80 wrote:

The machine actually is hanging

That expression irritates the crap out of me but I should post about that in another thread.

Have you tried ssh'ing into the machine? Sounds like a graphics problem to me...

Offline

#9 2020-02-12 08:30:48

jayache80
Member
Registered: 2015-11-19
Posts: 23

Re: [SOLVED] hibernation using uswsusp with swapfile and btrfs

Head_on_a_Stick wrote:

Do you really need to resize your swap space?

Yes, I like to resize my swap space 2 or 3 times a day. For fun.

(just kidding)

Head_on_a_Stick wrote:

Have you tried ssh'ing into the machine?

I tried but no dice.

Head_on_a_Stick wrote:

Sounds like a graphics problem to me...

And you would be right.

I disabled booting into the graphical target by setting

systemctl set-default multi-user.target

Presented with just virtual terminals, doing a

systemctl suspend

works great. The machine sleeps as expected, the power indicator light swells as it's supposed to, and the system wakes up almost immediately with a key press.

Doing a

s2disk

worked great! I saw the snapshotting of the image to the swapfile, and the machine was properly shut down. When I started the machine back up, after initramfs I see the snapshot image being loaded in from the swapfile, and all my processes resumed. Success!

$ pacman -Q systemd
systemd-git 245.rc1.r47.g5f04f4e470-1

For my graphical issue, something about this combination is bad:

  • mid-2009 macbook pro 5,5 hardware (9400M graphics card)

  • nouveau graphics driver

  • lightdm

  • i3 windows manager

I'm using the nouveau driver, because I couldn't get nvidia-340xx drivers to work for the life of me. (nvidia-340xx are the legacy drivers that nvidia tells me should work with this graphics card, 9400m). This is an EFI boot (not hybrid EFI), which supposedly can cause problems between the PCIe bridge, the graphics device, and the driver at boot.

Since I can successfully sleep to a swapfile, this thread is solved, and I'll consult some help from Laptop issues.

Thank you for the help.

Last edited by jayache80 (2020-02-12 08:31:08)

Offline

Board footer

Powered by FluxBB