F33 with BTRFS, Hybernation problem with SWAP on ZRAM

Hi,
I have a question.
I recently switched to F33 and ran the default installation with BTRFS. When I try to hibernate with systemctl hibernate command … I get
Failed to hibernate system via logind: Not enough swap space for hibernation
This the output of swapon -v and free

$ swapon -v
NAME       TYPE      SIZE USED PRIO
/dev/zram0 partition   4G   0B  100

$ free
              total        used        free      shared  buff/cache   available
Mem:       16226908     3261236     8341512      584048     4624160    12058424
Swap:       4194300           0     4194300

Actually, the size of the SWAP is not enough, since I have 16GB of RAM. But the SWAP in the default installation of F33 is not a SWAP FileSystem, but a SWAP on zram and no longer uses SWAP partitions by default.
This is my /etc/fstab

$ cat /etc/fstab 
UUID=ff78ce94-1bb0-403a-8973-21ae1efb8b8f /         btrfs   subvol=@,x-systemd.device-timeout=0,ssd,noatime,space_cache,commit=120,discard=async        0 0
UUID=099F-3A38                            /boot/efi vfat    umask=0077,shortname=winnt 0 2
UUID=ff78ce94-1bb0-403a-8973-21ae1efb8b8f /home     btrfs   subvol=@home,x-systemd.device-timeout=0,ssd,noatime,space_cache,commit=120,discard=async    0 0
UUID=ff78ce94-1bb0-403a-8973-21ae1efb8b8f /var      btrfs   subvol=var,x-systemd.device-timeout=0,ssd,noatime,space_cache,commit=120,discard=async      0 2

Reading here https://fedoraproject.org/wiki/Changes/SwapOnZRAM it is clear that …

The zram-generator + configuration file will trigger the setup and activation of swap-on-zram. This means hibernation isn’t possible, even on systems that could support it.

At this point, I wonder if (and how) it is possible to go back to using HIBERNATION with this type of configuration.

Thank you,
S.

1 Like

Not sure if there are official Fedora Docs on this topic.

There are some Internet tutorials, like this:

I suspect that if you created a disk-based swap partition as large as your ram that hibernation would work. But it has been noted that there are other swap errors introduced in a machine with heavy swap usage and the hybrid swap that would create.

Maybe the best of both worlds would be to disable zram and swap to SSD or NVME drive

I did some experiments …
…I took a cue from here https://superuser.com/questions/1581885/btrfs-luks-swapfile-how-to-hibernate-on-swapfile and I performed the following steps

-- Create and configure a swap-file the same size as the system memory
sudo touch /var/swapfile
sudo chattr +C /var/swapfile
sudo fallocate --length "$(grep MemTotal /proc/meminfo | awk '{print $2 * 1024}')" /var/swapfile
sudo chmod 600 /var/swapfile
sudo mkswap /var/swapfile
sudo swapon /var/swapfile
echo '/var/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
cat /etc/fstab 

-- Set the resume kernel parameters
wget "https://raw.githubusercontent.com/osandov/osandov-linux/61679ecd914d653bab14d0e752595e86b9f50513/scripts/btrfs_map_physical.c"
gcc -O2 -o btrfs_map_physical btrfs_map_physical.c
./btrfs_map_physical /var/swapfile | sed -n "2p" | awk "{print \$NF}" >/tmp/swap_physical_offset
sudo ./btrfs_map_physical /var/swapfile | sed -n "2p" | awk "{print \$NF}" >/tmp/swap_physical_offset
SWAP_PHYSICAL_OFFSET=$(cat /tmp/swap_physical_offset)
SWAP_OFFSET=$(echo "${SWAP_PHYSICAL_OFFSET} / $(getconf PAGESIZE)" | bc)
SWAP_UUID=$(findmnt -no UUID -T /var/swapfile)
RESUME_ARGS="resume=UUID=${SWAP_UUID} resume_offset=${SWAP_OFFSET}"
echo "${RESUME_ARGS}"
sudo grubby --update-kernel=ALL --args="${RESUME_ARGS}"

-- Disable systemd swap space check - To avoid false positive systemd errors about the swap size, if there's already an existing swap target (e.g. the default zram device).
sudo mkdir -p /etc/systemd/system/systemd-logind.service.d/
cat <<-EOF | sudo tee /etc/systemd/system/systemd-logind.service.d/override.conf
[Service]
Environment=SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1
EOF

sudo mkdir -p /etc/systemd/system/systemd-hibernate.service.d/
cat <<-EOF | sudo tee /etc/systemd/system/systemd-hibernate.service.d/override.conf
[Service]
Environment=SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1
EOF

I then rebooted and tested withsystemctl hibernate… but nothing to do, it does NOT work! The configurations are now as follows:

$ sudo blkid | grep swap
/dev/zram0: UUID="8164f084-3ac5-41f5-9b90-c2aa29c7dbcd" TYPE="swap"

$ swapon -s
Filename				Type		Size	Used	Priority
/dev/zram0                             	partition	4194300	0	100
/var/swapfile                          	file    	16226904	0	-2

$ cat /etc/fstab 
UUID=ff78ce94-1bb0-403a-8973-21ae1efb8b8f /         btrfs   subvol=@,x-systemd.device-timeout=0,ssd,noatime,space_cache,commit=120,discard=async        0 0
UUID=099F-3A38                            /boot/efi vfat    umask=0077,shortname=winnt 0 2
UUID=ff78ce94-1bb0-403a-8973-21ae1efb8b8f /home     btrfs   subvol=@home,x-systemd.device-timeout=0,ssd,noatime,space_cache,commit=120,discard=async    0 0
UUID=ff78ce94-1bb0-403a-8973-21ae1efb8b8f /var      btrfs   subvol=var,x-systemd.device-timeout=0,ssd,noatime,space_cache,commit=120,discard=async      0 2
/var/swapfile none swap sw 0 0

The hibernation process seems to work in the shutdown phase. On the restart, however, it performs a normal boot and does not perform the RESUME operation :frowning_face:

I’ve modified GRUB_CMDLINE_LINUX with resume= on first parameter
therefore, with

GRUB_CMDLINE_LINUX=“resume=UUID=ff78ce94-1bb0-403a-8973-21ae1efb8b8f rhgb quiet resume_offset=100144384”

instead of

GRUB_CMDLINE_LINUX=“rhgb quiet resume=UUID=ff78ce94-1bb0-403a-8973-21ae1efb8b8f resume_offset=100144384”

IT’S WORK FINE!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.