Giter Site home page Giter Site logo

gissf1 / zram-hibernate Goto Github PK

View Code? Open in Web Editor NEW
33.0 33.0 2.0 120 KB

Allows dynamic swap changes to activate disk-based storage as swap for hibernation support when a system typically uses only zram swap during normal operation.

License: Apache License 2.0

Shell 100.00%

zram-hibernate's People

Contributors

gissf1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

zram-hibernate's Issues

hibernate on opensuse 15.5

I must be missing something because on Opensuse 15.5 hibernation with zramswap works as without it despite no magic happening in the package:

# /lib/systemd/system/zramswap.service
#
# Copyright (c) 2012-2018 Malcolm J Lewis <[email protected]>
#

[Unit]
Description=Service enabling compressing RAM with zRam
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/sbin/zramswapon
ExecStop=/usr/sbin/zramswapoff
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

with zswapon reading

#!/bin/bash

# get the amount of memory in the machine
mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
mem_total=$((mem_total_kb * 1024))

# load the dependency module
modprobe zram

# initialize the device with zstd compression algorithm
echo zstd > /sys/block/zram0/comp_algorithm;
echo $mem_total > /sys/block/zram0/disksize

# Creating the swap filesystem
mkswap /dev/zram0

# Switch the swaps on
swapon -p 100 /dev/zram0

When calling zram-hibernate the device with the correct ID of the swap drive cannot be found, so maybe something similar to what zram-hibernate does is already happening by default?

script doesn't work with mawk

mawk was preinstalled on my ubuntu 23.10 instead of gawk and this was the output after running the script with -d option

[8868] creating tmpfile...
[8868] lock acquired.
----- getMemInfo() ----------------------------------------
MemTotal=15748204
MemFree=1535368
MemAvailable=11507292
SwapTotal=15748092
SwapFree=15748092
----- getResumeInfo() ----------------------------------------
KERNEL_RESUME_RAW=/swapfile
KERNEL_RESUME_DEVICE=/swapfile
KERNEL_RESUME_UUID="19843ba4-f7a4-45c9-b094-be49e259bf86"
KERNEL_RESUME_CONF='/etc/zram-hibernate.conf'
----- getActiveSwapInfo() ----------------------------------------
ACTIVESWAP0_Filename=/dev/zram0
ACTIVESWAP0_Type=partition
ACTIVESWAP0_Size=15748092
ACTIVESWAP0_Used=0
ACTIVESWAP0_Priority=100
ACTIVESWAPS=1
----- getFstabSwapInfo() ----------------------------------------
FSTABSWAPS=0
----- getSwapInfo() ----------------------------------------
awk: line 15: syntax error at or near ,
awk: line 20: syntax error at or near else
awk: line 23: syntax error at or near else
awk: line 26: syntax error at or near return
awk: line 30: syntax error at or near [
---------------------------------------------

installing gawk fixed the issue

Problem with LUKS (I think)

My setup is a swapfile in a btrfs filesystem under a LUKS volume. Normal hibernate without zram is working, but I can't get zram-hibernate to work.

zram is initialized using zram-generator. Distro is Gentoo Linux.

# zram-hibernate -nt
[584518] creating tmpfile...
[584518] lock acquired.
getResumeInfo() Not a valid block device: KERNEL_RESUME_DEVICE=
ensureDiskSwap(): Initial swap status...
[19:55:46] Used=37G MemFree=3320M SwapUsed=0K/67G Overcommit=0K
     swapfile:  0.0% (0K/63G) [-2]
        zram0:  0.0% (0K/4095M) [100]
WARNING: swap file on btrfs filesystem is not well tested and could be dangerous: /mnt/rootfs/swap/swapfile: on /dev/mapper/root
         Sleeping for 5 seconds... Press Ctrl+C to abort.
Testing underlying block device for: /mnt/rootfs/swap/swapfile: /dev/mapper/root
Unknown device type: /dev/mapper/root: 0:0 
FATAL: no valid swaps found. cannot suspend to disk.

# zram-hibernate -d
[585050] creating tmpfile...
[585050] lock acquired.
 ----- getMemInfo() ----------------------------------------
MemTotal=65496852
MemFree=3337088
MemAvailable=26165256
SwapTotal=71303160
SwapFree=71303160
 ----- getResumeInfo() ----------------------------------------
getResumeInfo() Not a valid block device: KERNEL_RESUME_DEVICE=
getResumeInfo() returned: 128
 ----- getActiveSwapInfo() ----------------------------------------
ACTIVESWAP0_Filename=/mnt/rootfs/swap/swapfile
ACTIVESWAP0_Type=file
ACTIVESWAP0_Size=67108860
ACTIVESWAP0_Used=0
ACTIVESWAP0_Priority=-2
ACTIVESWAP1_Filename=/dev/zram0
ACTIVESWAP1_Type=partition
ACTIVESWAP1_Size=4194300
ACTIVESWAP1_Used=0
ACTIVESWAP1_Priority=100
ACTIVESWAPS=2
 ----- getFstabSwapInfo() ----------------------------------------
FSTABSWAP0_DEVICE="/mnt/rootfs/swap/swapfile"
FSTABSWAP0_OPTIONS="defaults"
FSTABSWAP0_TYPE="swap"
FSTABSWAPS=1
 ----- getSwapInfo() ----------------------------------------
getResumeInfo() Not a valid block device: KERNEL_RESUME_DEVICE=
SWAP0_ACTIVE=1
SWAP0_DEVICE=/mnt/rootfs/swap/swapfile
SWAP0_IS_RESUME=0
SWAP0_OPTIONS=defaults
SWAP0_PRIORITY=-2
SWAP0_SIZE=67108860
SWAP0_TYPE=file
SWAP0_USED=0
SWAP1_ACTIVE=1
SWAP1_DEVICE=/dev/zram0
SWAP1_IS_RESUME=0
SWAP1_PRIORITY=100
SWAP1_SIZE=4194300
SWAP1_TYPE=partition
SWAP1_USED=0
SWAPS=2
 ---------------------------------------------

# lsblk
NAME       MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
zram0      252:0    0     4G  0 disk  
nvme0n1    259:0    0   1,8T  0 disk  
├─nvme0n1p1
│          259:1    0   512M  0 part  /boot
└─nvme0n1p2
           259:2    0   1,8T  0 part  
  └─root   253:0    0   1,8T  0 crypt /home
                                      /mnt/rootfs
                                      /

# swapon
NAME                      TYPE      SIZE USED PRIO
/mnt/rootfs/swap/swapfile file       64G   0B   -2
/dev/zram0                partition   4G   0B  100

# stat -c '%d    %Hr     %Lr'  /dev/mapper/root
5    0     0

# grep -Fx 'Block devices:' -A9999 /proc/devices | sed -r 's/^$//g ; T ; q'
Block devices:
  7 loop
  8 sd
  9 md
 11 sr
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
252 zram
253 device-mapper
254 mdp
259 blkext

# cat /proc/cmdline 
BOOT_IMAGE=/vmlinuz-2023-02-06-6.1.10-gentoo-x86_64 root=UUID=a47a317b-c56d-4977-a5fd-61e2aff852b8 ro rootflags=subvol=root crypt_root=UUID=cdb10de8-05d9-4fce-8e3b-31e51b13befc real_root=LABEL=priyadi-root rootfstype=btrfs rootflags=subvol=root root_keydev=/dev/disk/by-label/KEYCHAIN root_key=luks/priyadi-2023.gpg real_resume=LABEL=priyadi-root resume_offset=304948480 root_trim=yes usbcore.autosuspend=-1 i915.enable_guc=2 i915.enable_gvt=1 i915.enable_fbc=1 i915.fastboot=1 i915.enable_psr=1 zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4hc mem_sleep_default=deep intel_pstate=disable

script failing on bash 5.2.15 on Fedora 37

I try to run the script in bash (version 5.2.15) on Fedora 37. I guess it might be some basic thing I'm doing wrong. :)

ensureDiskSwap(): Initial swap status...
[08:32:59] Used=2675M MemFree=10G SwapUsed=0K/27G Overcommit=0K
./zram-hibernate: line 658: 0.00683594: syntax error: invalid arithmetic operator (error token is ".00683594")

Originally posted by @gustavtemp in #1 (comment)

Help with setting up `zram-hibernate`

It's probably a me problem tbh
When I run doas /usr/lib/systemd/system-sleep/zram-hibernate
it spit out this

[90315] creating tmpfile...
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
[90315] lock acquired.
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
getResumeInfo() Not a valid block device: KERNEL_RESUME_DEVICE=
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
ensureDiskSwap(): Initial swap status...
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
[19:24:08] Used=5426M MemFree=22G SwapUsed=0K/31G Overcommit=0K
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
        zram0:  0.0% (0K/31G) [100]
egrep: warning: egrep is obsolescent; using grep -E
fgrep: warning: fgrep is obsolescent; using grep -F
egrep: warning: egrep is obsolescent; using grep -E
FATAL: no valid swaps found. cannot suspend to disk.

I thought this script is supposed to make hibernating without swap but with zram possible?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.