gissf1 / zram-hibernate

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.
Apache License 2.0
35 stars 3 forks source link

script failing on bash 5.2.15 on Fedora 37 #3

Open gissf1 opened 1 year ago

gissf1 commented 1 year ago

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 https://github.com/gissf1/zram-hibernate/issues/1#issuecomment-1399200861

gissf1 commented 1 year ago

@gustavtemp:

I haven't tested this script on Fedora at all, but I imagine if it installs similarly to the AUR package I made, it should work since nothing about the script is really specific to Arch Linux.

It might be something with BASH or AWK differences on your Fedora install. All my Arch Linux systems are running BASH 5.1.x and AWK 5.2.x, and it's possible something changed upstream in newer versions that broke this script. Could you post your AWK version too just to be sure? (run: awk --version)

Could you try running this script again with -vvv to show more details and post that output?

I was able to get a similar message when attempting to do arithmetic on the command line using something like echo $(( 1.234 +0 )) where it responded with bash: 1.234 +0 : syntax error: invalid arithmetic operator (error token is ".234 +0 "), so it seems that's related. If that's the case though, it would mean that $SWAP_SIZE is set to a fractional value somehow, rather than rounded to the nearest KB.

Could you also describe your swap setup a bit: how big are your swap files/partitions and where are they?

gustavtemp commented 1 year ago

GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0-p13, GNU MP 6.2.1)

> swapon --show
NAME       TYPE       SIZE USED PRIO
/dev/dm-0  partition 19.5G   0B   -2
/dev/zram0 partition    8G   0B  100
> ./zram-hibernate -nvvv
[16894] removing stale lock...
[16894] creating tmpfile...
[16894] lock acquired.
ensureDiskSwap(): Initial swap status...
[14:51:59] Used=4936M MemFree=8302M SwapUsed=0K/27G Overcommit=0K
./zram-hibernate: line 658: 0.00683594: syntax error: invalid arithmetic operator (error token is ".00683594")
> echo $(( 1.234 +0 ))
bash: 1.234 +0 : syntax error: invalid arithmetic operator (error token is ".234 +0 ")
gissf1 commented 1 year ago

Do you have an /etc/fstab line for your swap /dev/dm-0? or better yet, can you provide the content of your /etc/fstab?

I tried spinning up a docker container of Fedora 37 and running the script as: ./zram-hibernate -vvvt

The only error I got was the missing /etc/fstab file, so it looks like it's probably not a general incompatibility with the script, but likely some configuration entry or environment difference that is triggering the issue.

I also noticed that you have the /dev/dm-0 swap already active. Typically the script intends to unmount zram and mount other swaps when hibernating. I thought it was worthwhile to provide a slight warning that if you intend to run it with your swap already mounted, that is a less-tested use case. I believe it should do the right thing (only affecting disk swaps if it needs to add one), but it may misbehave.

Perhaps try unmounting your /dev/dm-0 using something like sudo swapoff /dev/dm-0 before running the script to see it that affects your issue?

gissf1 commented 1 year ago

@gustavtemp If you found the issue, please let me know what it was so I can add a check to the script with some kind of direction to help future users.

milos7250 commented 1 year ago

Hi there,

I just bumped into the exact same issue. The output of zram-hibernate -tnvvv is

[2397] removing stale lock...
[2397] creating tmpfile...
[2397] lock acquired.
ensureDiskSwap(): Initial swap status...
[23:32:32] Used=2822M MemFree=2070M SwapUsed=0K/5872M Overcommit=0K
/usr/lib/systemd/system-sleep/zram-hibernate: line 658: 0.00683594: syntax error: invalid arithmetic operator (error token is ".00683594")

Output of zram-hibernate -tnd is

[2680] removing stale lock...
[2680] creating tmpfile...
[2680] lock acquired.
 ----- getMemInfo() ----------------------------------------
MemTotal=6014968
MemFree=2115448
MemAvailable=3123984
SwapTotal=6013948
SwapFree=6013948
 ----- getResumeInfo() ----------------------------------------
KERNEL_RESUME_RAW=/dev/mapper/luks-30a1683a-454b-44b4-9d28-e0f202a6445c
KERNEL_RESUME_DEVICE=/dev/mapper/luks-30a1683a-454b-44b4-9d28-e0f202a6445c
KERNEL_RESUME_UUID="76c628b3-46ec-4406-bfc0-dad35fc0875a"
KERNEL_RESUME_BLOCK_SIZE="4096"
KERNEL_RESUME_OFFSET=40949760
 ----- getActiveSwapInfo() ----------------------------------------
ACTIVESWAP0_Filename=/dev/zram0
ACTIVESWAP0_Type=partition
ACTIVESWAP0_Size=6013948
ACTIVESWAP0_Used=0
ACTIVESWAP0_Priority=100
ACTIVESWAPS=1
 ----- getFstabSwapInfo() ----------------------------------------
FSTABSWAPS=0
 ----- getSwapInfo() ----------------------------------------
KERNEL_RESUME_SWAP_IDX=0
SWAP0_ACTIVE=0
SWAP0_DEVICE=/dev/mapper/luks-30a1683a-454b-44b4-9d28-e0f202a6445c
SWAP0_IS_RESUME=1
SWAP0_OFFSET=40949760
SWAP0_PRIORITY=
SWAP0_RAW=/dev/mapper/luks-30a1683a-454b-44b4-9d28-e0f202a6445c
SWAP0_SIZE=0.00683594
SWAP0_USED=0
SWAP0_UUID=76c628b3-46ec-4406-bfc0-dad35fc0875a
SWAP1_ACTIVE=1
SWAP1_DEVICE=/dev/zram0
SWAP1_IS_RESUME=0
SWAP1_PRIORITY=100
SWAP1_SIZE=6013948
SWAP1_TYPE=partition
SWAP1_USED=0
SWAPS=2
UNKNOWN_SWAP_LINE_4=KERNEL_RESUME_BLOCK_SIZE="4096"
 ---------------------------------------------

This is in my grub config

GRUB_CMDLINE_LINUX_DEFAULT="cryptdevice=UUID=30a1683a-454b-44b4-9d28-e0f202a6445c:luks-30a1683a-454b-44b4-9d28-e0f202a6445c root=/dev/mapper/luks-30a1683a-454b-44b4-9d28-e0f202a6445c resume=/dev/mapper/luks-30a1683a-454b-44b4-9d28-e0f202a6445c resume_offset=40949760 loglevel=3"

I do not have the swap file in fstab, as I do not intend to use it for anything else other than hibernation. I created the swapfile using command sudo dd if=/dev/zero of=/swapfile bs=1M count=2456 status=progress, using the fact that cat /sys/power/image_size retrieved value 2438635520 and that is supposed to be sufficient size for swap file for hibernation. The details of the swapfile:

Filesystem type is: ef53
File size of /swapfile is 2575302656 (628736 blocks of 4096 bytes)
 ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        0..   32767:   40949760..  40982527:  32768:            
   1:    32768..  436223:   40982528..  41385983: 403456:            
   2:   436224..  440319:   40353792..  40357887:   4096:   41385984:
   3:   440320..  444415:   40366080..  40370175:   4096:   40357888:
   4:   444416..  450559:   23554048..  23560191:   6144:   40370176:
   5:   450560..  456703:    8153088..   8159231:   6144:   23560192:
   6:   456704..  462847:   37804032..  37810175:   6144:    8159232:
   7:   462848..  587775:   37812224..  37937151: 124928:   37810176:
   8:   587776..  620543:    3407872..   3440639:  32768:   37937152:
   9:   620544..  628735:    3014656..   3022847:   8192:    3440640: last,eof
/swapfile: 9 extents found

Let me know if there is anything else I can provide to help with this issue.

gissf1 commented 1 year ago

Thanks for the very detailed report! I don't see anything obviously bad in your report, but that UNKNOWN_SWAP_LINE_4= is a bit odd.

Interesting that your arithmetic error value is exactly the same as the OP. I would have expected some variance if it were an actual math problem. I'm thinking this may actually be a parse issue somewhere.

I'm a bit short on time this week, but I will get back to you on this when I can look into the issue with a bit more depth. In the meantime, let me know if you discover anything additional and I'll try to at least provide feedback in a timely fashion.

Littux-Dustux commented 1 year ago

Same issue on Manjaro (based off of Arch Linux)

ensureDiskSwap(): Initial swap status...
[21:50:38] Used=2158M MemFree=127M SwapUsed=773M/5119M Overcommit=303M
        zram0: 15.1% (773M/5119M) [32767]
/usr/local/bin/zram-hibernate: line 658: 0.00976562: syntax error: invalid arithmetic operator (error token is ".00976562")
Konfekt commented 11 months ago

Just to understand the issue, it lies in SWAP_SIZE being a floating point number when an integer is expected? What harm would be done if a floating point number would be accepted as well?