Package: zram-tools
Version: 0.3.3.1-1.1
Severity: normal
Dear Maintainer,
I was testing an Ansible role that would setup zramswap, using a Vagrant-VM
backed by Virtualbox (image version "debian/bookworm64 (virtualbox,
12.20241217.1, (amd64))") in the Molecule test framework. Initial installation
of zramswap worked well, and after that, my system was running zramswap as
confirmed by `sudo zramctl` and `sudo systemctl status zramswap.service`.
```
$ sudo zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lz4 480.3M 4K 65B 4K 2 [SWAP]
sudo systemctl status zramswap.service
● zramswap.service - Linux zramswap setup
Loaded: loaded (/lib/systemd/system/zramswap.service; enabled; preset:
enabled)
Active: active (exited) since Tue 2025-01-14 15:37:14 UTC; 16h ago
Docs: man:zramswap(8)
Process: 2716 ExecStart=/usr/sbin/zramswap start (code=exited,
status=0/SUCCESS)
Main PID: 2716 (code=exited, status=0/SUCCESS)
CPU: 59ms
Jan 14 15:37:13 vm-runner-bookworm systemd[1]: Starting zramswap.service -
Linux zramswap setup...
Jan 14 15:37:13 vm-runner-bookworm root[2717]: Starting Zram
Jan 14 15:37:13 vm-runner-bookworm zramswap[2717]: <13>Jan 14 15:37:13 root:
Starting Zram
Jan 14 15:37:14 vm-runner-bookworm zramswap[2720]: Setting up swapspace version
1, size = 480.3 MiB (503595008 bytes)
Jan 14 15:37:14 vm-runner-bookworm zramswap[2720]: no label,
UUID=e256c7aa-e90b-47af-a2de-67850a34dd1b
Jan 14 15:37:14 vm-runner-bookworm systemd[1]: Finished zramswap.service -
Linux zramswap setup.
```
After changing the zwarmswap default config to what you can see below, I tried
to restart the `zramswap.service` SystemD service. To do that, ...
... I first triggered the restart using Ansible's
`ansible.builtin.systemd_service module` with `state: restarted`, but after
that failed,
... I tried to restart the service manually using `sudo systemctl restart
zramswap.service`, and when that also failed,
... I ran the `ExecStop=` stance from `zramswap.service`.
All of these variants do basically the same, so the result was the same as well:
```
sudo systemctl stop zramswap
sudo systemctl status zramswap
× zramswap.service - Linux zramswap setup
Loaded: loaded (/lib/systemd/system/zramswap.service; enabled; preset:
enabled)
Active: failed (Result: exit-code) since Wed 2025-01-15 09:30:19 CET; 6s
ago
Duration: 17h 7min 53.334s
Docs: man:zramswap(8)
Process: 606 ExecStart=/usr/sbin/zramswap start (code=exited,
status=0/SUCCESS)
Process: 48503 ExecStop=/usr/sbin/zramswap stop (code=exited,
status=1/FAILURE)
Main PID: 606 (code=exited, status=0/SUCCESS)
CPU: 11ms
Jan 15 09:30:19 sdvlzasubappamdev systemd[1]: Stopping zramswap.service - Linux
zramswap setup...
Jan 15 09:30:19 sdvlzasubappamdev zramswap[48504]: <13>Jan 15 09:30:19 root:
Stopping Zram
Jan 15 09:30:19 sdvlzasubappamdev root[48507]: disabling swap device: /dev/zram0
Jan 15 09:30:19 sdvlzasubappamdev zramswap[48507]: <13>Jan 15 09:30:19 root:
disabling swap device: /dev/zram0
Jan 15 09:30:19 sdvlzasubappamdev zramswap[48508]: modprobe: ERROR:
../libkmod/libkmod-module.c:856 kmod_module_remove_module() could not remove
'zram': Device or resource busy
Jan 15 09:30:19 sdvlzasubappamdev root[48509]: Error: removing zram module from
kernel
Jan 15 09:30:19 sdvlzasubappamdev zramswap[48509]: <13>Jan 15 09:30:19 root:
Error: removing zram module from kernel
Jan 15 09:30:19 sdvlzasubappamdev systemd[1]: zramswap.service: Control process
exited, code=exited, status=1/FAILURE
Jan 15 09:30:19 sdvlzasubappamdev systemd[1]: zramswap.service: Failed with
result 'exit-code'.
Jan 15 09:30:19 sdvlzasubappamdev systemd[1]: Stopped zramswap.service - Linux
zramswap setup.
```
The service is set to "failed" status, because the removal of the zram kernel
module failed. After that, I cannot start the zramswap service, and only a
reboot resolves the issue.
`/usr/sbin/zramswap` is a Bash script, so I took a look at the `stop()`
function that is called, but I can't see anything out of the ordinary. I
suspected that the commands are called in the wrong order, but everything seems
to make sense. The implemented algorithm is:
1. Test if "/dev/zram0" is a block device
2. Disable swap for that swap device, because it can only be removed when it's
empty.
3. Remove the zram kernel module.
I executed the steps manually and found that `swapoff` works as expected and
the zram device is no longer mounted, but `modprobe -r` doesn't:
```
$ sudo modprobe -r zram
Killed
$ echo $?
137
```
I'm not sure how to proceed here. One option would be to keep the Kernel module
loaded and rely on the fact that it will be unloaded together with the rest of
the Kernel during shutdown/reboot, but that's not very clean. Also, it would
require modifications in the `start()` function to first check if the `zram`
module is already loaded, and if it is, to skip the `modprobe` there as well.
Yeah, so, that's all I've got. If you need anything else to resolve this, I'll
try my best to help you out.
Thank you and have a nice day,
Jörg
-- System Information:
Debian Release: 12.8
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 6.1.0-27-amd64 (SMP w/2 CPU threads; PREEMPT)
Kernel taint flags: TAINT_WARN, TAINT_SOFTLOCKUP
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages zram-tools depends on:
ii bc 1.07.1-3+b1
zram-tools recommends no packages.
zram-tools suggests no packages.
-- Configuration Files:
/etc/default/zramswap changed:
ALGO=lz4
PERCENT=50
-- no debconf information