[packages/zram-init] systemd_post with an off-by-default preset, kmod, module leak

arekm arekm at pld-linux.org
Mon Sep 14 17:21:32 CEST 2026


commit b1f73f034fe08c58765887c254fb58304a4fbe83
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Mon Sep 14 17:16:56 2026 +0200

    systemd_post with an off-by-default preset, kmod, module leak

 zram-init.init      |  8 +++++---
 zram-init.preset    |  7 +++++++
 zram-init.spec      | 10 +++++++---
 zram-init.sysconfig |  5 ++++-
 4 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/zram-init.spec b/zram-init.spec
index 8b56663..58139f7 100644
--- a/zram-init.spec
+++ b/zram-init.spec
@@ -9,12 +9,13 @@ Source0:	https://github.com/vaeth/zram-init/archive/v%{version}/%{name}-%{versio
 Source1:	%{name}.init
 Source2:	%{name}.sysconfig
 Source3:	%{name}.service
+Source4:	%{name}.preset
 URL:		https://github.com/vaeth/zram-init/
 BuildRequires:	gettext-tools
 BuildRequires:	rpmbuild(macros) >= 1.644
 Requires(post,preun):	/sbin/chkconfig
 Requires(post,preun,postun):	systemd-units
-Requires:	module-init-tools
+Requires:	kmod
 Requires:	rc-scripts
 Requires:	systemd-units
 Requires:	util-linux
@@ -51,7 +52,8 @@ SHEBANG='#!%{__sh}' \
 
 %install
 rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT/etc/{rc.d/init.d,sysconfig}
+install -d $RPM_BUILD_ROOT/etc/{rc.d/init.d,sysconfig} \
+	$RPM_BUILD_ROOT/lib/systemd/system-preset
 
 %{__make} install \
 	BINDIR=$RPM_BUILD_ROOT/sbin \
@@ -70,6 +72,7 @@ install -d $RPM_BUILD_ROOT/etc/{rc.d/init.d,sysconfig}
 install -p %{SOURCE1} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name}
 cp -p %{SOURCE2} $RPM_BUILD_ROOT/etc/sysconfig/%{name}
 cp -p %{SOURCE3} $RPM_BUILD_ROOT%{systemdunitdir}/%{name}.service
+cp -p %{SOURCE4} $RPM_BUILD_ROOT/lib/systemd/system-preset/90-%{name}.preset
 
 %find_lang %{name}
 
@@ -78,7 +81,7 @@ rm -rf $RPM_BUILD_ROOT
 
 %post
 /sbin/chkconfig --add %{name}
-%systemd_reload
+%systemd_post %{name}.service
 
 %preun
 if [ "$1" = "0" ]; then
@@ -98,6 +101,7 @@ fi
 %config(noreplace) %verify(not md5 mtime size) /etc/modprobe.d/zram.conf
 %config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/%{name}
 %{systemdunitdir}/%{name}.service
+/lib/systemd/system-preset/90-%{name}.preset
 %{systemdunitdir}/zram_btrfs.service
 %{systemdunitdir}/zram_swap.service
 %{systemdunitdir}/zram_tmp.service
diff --git a/zram-init.init b/zram-init.init
index be2ec6a..5d152e5 100755
--- a/zram-init.init
+++ b/zram-init.init
@@ -137,11 +137,14 @@ start() {
 		return
 	fi
 
+	started=0
+
 	if is_yes "$load_on_start"; then
 		show "Loading zram kernel module"
 		busy
 		if /sbin/modprobe zram num_devices="$num_devices"; then
 			ok
+			started=1
 		else
 			fail
 			RETVAL=1
@@ -150,7 +153,6 @@ start() {
 	fi
 
 	i=0
-	started=0
 	while [ $i -lt "$num_devices" ]; do
 		if zram_getconf $i; then
 			if zram_start_dev $i; then
@@ -162,8 +164,8 @@ start() {
 		i=$((i + 1))
 	done
 
-	# a device that came up has to be reachable by stop even when another
-	# one failed, or it stays allocated until reboot
+	# the lock means stop has state to undo - a loaded module, or a device
+	# that came up - so it is taken even when another device failed
 	[ $started -eq 0 ] || touch /var/lock/subsys/zram-init
 }
 
diff --git a/zram-init.preset b/zram-init.preset
new file mode 100644
index 0000000..7f798f4
--- /dev/null
+++ b/zram-init.preset
@@ -0,0 +1,7 @@
+# zram swap changes how the machine manages memory, so the package does not
+# turn it on by itself; the SysV side is off by default too (chkconfig: -).
+# Preset files are applied in lexicographic order of their filename across
+# all preset directories, so to enable it on install either drop
+# "enable zram-init.service" into a file in /etc/systemd/system-preset/
+# bearing this very name, or into one sorting before it.
+disable zram-init.service
diff --git a/zram-init.sysconfig b/zram-init.sysconfig
index 48946bd..33cc5c2 100644
--- a/zram-init.sysconfig
+++ b/zram-init.sysconfig
@@ -59,7 +59,10 @@ num_devices=1
 # iratN  bytes/inode ratio for ext2/ext4
 # inodN  inode count for ext2/ext4
 
-# swap on /dev/zram0, sized at half of the physical memory
+# swap on /dev/zram0, sized at half of the physical memory. That is a sane
+# starting point, not a tuned value: on a machine with a lot of RAM a fixed
+# size is usually the better answer, and mlim0 caps how much RAM the
+# compressed pages may take regardless of size0.
 type0=swap
 size0=$(awk '/^MemTotal:/ {print int($2 / 2048)}' /proc/meminfo)
 algo0=zstd
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/zram-init.git/commitdiff/b1f73f034fe08c58765887c254fb58304a4fbe83



More information about the pld-cvs-commit mailing list