Skip to contentSkip to conversation

zram: properly implement systemd service

PATCH In review Stefan Agner 3 participants 4 messages Oct 5, 2019 – Oct 7, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zram: properly implement systemd service

From: Stefan Agner <[email protected]>

The systemd service points ot a script which is not installed by zram or any of its dependencies. It seems that the service got migrated without the necessary script.

The sysvinit script seems rather dated and initializes multiple zram instances to support multiprocessor systems. This is no longer necessary with modern implementations as newer kernel version support multiple streams by default.

Create a modern implementation based on Fedoras zram package. Make use of systemd swap unit files instead of enabling swap directly.

This removes the need for util-linux-swaponoff (since swap is now handled by systemd, which presumably depends on swaponoff). However, it adds the dependency to util-linux for zramctl.

---
 .../recipes-extended/zram/zram/dev-zram0.swap | 10 ++++
 .../zram/zram/zram-swap-deinit                | 19 +++++++
 .../recipes-extended/zram/zram/zram-swap-init | 26 ++++++++++
 .../zram/zram/zram-swap.service               | 10 ++++
 .../recipes-extended/zram/zram/zram.service   | 12 -----
 meta-oe/recipes-extended/zram/zram/zramstop   |  5 ++
 meta-oe/recipes-extended/zram/zram_0.1.bb     | 33 -------------
 meta-oe/recipes-extended/zram/zram_0.2.bb     | 49 +++++++++++++++++++
 8 files changed, 119 insertions(+), 45 deletions(-)
 create mode 100644 meta-oe/recipes-extended/zram/zram/dev-zram0.swap
 create mode 100755 meta-oe/recipes-extended/zram/zram/zram-swap-deinit
 create mode 100755 meta-oe/recipes-extended/zram/zram/zram-swap-init
 create mode 100644 meta-oe/recipes-extended/zram/zram/zram-swap.service
 delete mode 100644 meta-oe/recipes-extended/zram/zram/zram.service
 create mode 100644 meta-oe/recipes-extended/zram/zram/zramstop
 delete mode 100644 meta-oe/recipes-extended/zram/zram_0.1.bb
 create mode 100644 meta-oe/recipes-extended/zram/zram_0.2.bb
meta-oe/recipes-extended/zram/zram/dev-zram0.swap new file +10 -0
new file mode 100644
index 000000000..05eae7eed
@@ -0,0 +1,10 @@
+[Unit]
+Description=Enable compressed swap in memory using zram
+Requires=zram-swap.service
+After=zram-swap.service
+
+[Swap]
+What=/dev/zram0
+
+[Install]
+WantedBy=swap.target
meta-oe/recipes-extended/zram/zram/zram-swap-deinit new file +19 -0
new file mode 100755
index 000000000..46248c401
@@ -0,0 +1,19 @@
+#!/bin/sh
+set -e
+
+device=$1
+if [ "$device" = "" ]; then
+    echo "Usage: zram-swap-deinit <device>"
+    exit 1
+fi
+
+sysblockdev=/sys/block/$(basename $device)
+if [ ! -d $sysblockdev ]; then
+    echo "Block device not found in sysfs"
+    exit 1
+fi
+
+# zramctl -r is not suitable as it also removes the actual device. Recreating
+# it is non-trivial, especially if not /dev/zram0 is used...
+echo 1 > ${sysblockdev}/reset
+
meta-oe/recipes-extended/zram/zram/zram-swap-init new file +26 -0
new file mode 100755
index 000000000..0643dbca2
@@ -0,0 +1,26 @@
+#!/bin/sh
+set -e
+
+device=$1
+if [ "$device" = "" ]; then
+    echo "Usage: zram-swap-init <device>"
+    exit 1
+fi
+
+# Allocate zram to be size of actual system memory
+# Note: zram is only allocated when used. When swapped pages compress with a
+# a 2:1 ratio zram will require 50% of system memory (while allowing to use
+# 150% memory).
+ZRAM_SIZE_PERCENT=100
+ZRAM_ALGORITHM=lz4
+
+[ -f /etc/default/zram ] && ./etc/default/zram || true
+
+memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
+memzram=$(($memtotal*${ZRAM_SIZE_PERCENT}/100))
+
+# Try loading zram module
+modprobe -q zram || true
+
+zramctl -a ${ZRAM_ALGORITHM} -s ${memzram}KB $device
+mkswap -L "zram-swap" $device
meta-oe/recipes-extended/zram/zram/zram-swap.service new file +10 -0
new file mode 100644
index 000000000..7bb9e0a45
@@ -0,0 +1,10 @@
+[Unit]
+Description=Create compressed swap in memory using zram
+DefaultDependencies=no
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+TimeoutStartSec=30sec
+ExecStart=/usr/libexec/zram-swap-init /dev/zram0
+ExecStop=/usr/libexec/zram-swap-deinit /dev/zram0
meta-oe/recipes-extended/zram/zram/zram.service deleted +0 -12
deleted file mode 100644
index 4a19367d9..000000000
@@ -1,12 +0,0 @@
-[Unit]
-Description=Enable zram compressed in-memory swap.
-After=multi-user.target
-
-[Service]
-RemainAfterExit=yes
-ExecStart=/usr/bin/zram-load.sh --load
-ExecStop=/usr/bin/zram-load.sh --unload
-Type=oneshot
-
-[Install]
-WantedBy=multi-user.target
meta-oe/recipes-extended/zram/zram/zramstop new file +5 -0
new file mode 100644
index 000000000..07777978e
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+for i in $(grep '^/dev/zram' /proc/swaps | awk '{ print $1 }'); do
+	swapoff "$i" && zramctl --reset "$i"
+done
meta-oe/recipes-extended/zram/zram_0.1.bb deleted +0 -33
deleted file mode 100644
index dfd75e71c..000000000
@@ -1,33 +0,0 @@
-SUMMARY = "Linux zram compressed in-memory swap"
-LICENSE = "MIT"
-LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
-
-inherit update-rc.d systemd
-
-RDEPENDS_${PN} = "util-linux-swaponoff kmod"
-RRECOMMENDS_${PN} = "kernel-module-zram"
-
-PR = "r3"
-
-SRC_URI = " \
-           file://init \
-           file://zram.service \
-"
-
-do_install () {
-    # Sysvinit
-    install -d ${D}${sysconfdir}/init.d
-    install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/zram
-
-    install -d ${D}${systemd_unitdir}/system
-    install -m 0644 ${WORKDIR}/zram.service ${D}${systemd_unitdir}/system
-}
-
-FILES_${PN} = "${sysconfdir}"
-INITSCRIPT_NAME = "zram"
-INITSCRIPT_PARAMS = "start 05 2 3 4 5 . stop 22 0 1 6 ."
-
-RPROVIDES_${PN} += "${PN}-systemd"
-RREPLACES_${PN} += "${PN}-systemd"
-RCONFLICTS_${PN} += "${PN}-systemd"
-SYSTEMD_SERVICE_${PN} = "zram.service"
meta-oe/recipes-extended/zram/zram_0.2.bb new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw

✗ patchtest: failure for zram: properly implement systemd service

== Series Details ==

Series: zram: properly implement systemd service
Revision: 1
URL : https://patchwork.openembedded.org/series/20315/
State : failure

== Summary ==

Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:

* Issue Series sent to the wrong mailing list or some patches from the series correspond to different mailing lists [test_target_mailing_list]

  Suggested fix    Send the series again to the correct mailing list (ML)
  Suggested ML     [email protected] [http://git.openembedded.org/meta-openembedded/]
  Patch's path:    meta-oe/recipes-extended/zram/zram/dev-zram0.swap

* Issue Series does not apply on top of target branch [test_series_merge_on_head]
Suggested fix Rebase your series on top of targeted branch
Targeted branch master (currently at 520c6f30cd)

If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).

---

Guidelines:     https://www.openembedded.org/wiki/Commit_Patch_Message_Guidelines
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest
Test suite:     http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe
#2 lore raw

Re: ✗ patchtest: failure for zram: properly implement systemd service

Hi all,

As an on and off contributor I rely on the instructions in the OE wiki. Unfortunately the example for meta-oe is just next of an example using the [email protected]. Maybe the second example should contain the correct address for meta-oe as well?
http://www.openembedded.org/wiki/How_to_submit_a_patch_to_OpenEmbedded#Sending_patches

--
Stefan

Quoted 43 lines · Patchwork

== Series Details ==

Series: zram: properly implement systemd service
Revision: 1
URL : https://patchwork.openembedded.org/series/20315/
State : failure

== Summary ==

Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:

* Issue Series sent to the wrong mailing list or some
patches from the series correspond to different mailing lists [test_target_mailing_list]
Suggested fix Send the series again to the correct mailing list (ML)
Suggested ML [email protected]
[http://git.openembedded.org/meta-openembedded/]
Patch's path: meta-oe/recipes-extended/zram/zram/dev-zram0.swap

* Issue Series does not apply on top of target branch
[test_series_merge_on_head]
Suggested fix Rebase your series on top of targeted branch
Targeted branch master (currently at 520c6f30cd)

If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).

---
Guidelines:
https://www.openembedded.org/wiki/Commit_Patch_Message_Guidelines

Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest
Test suite:     http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe
#3 lore raw

Re: ✗ patchtest: failure for zram: properly implement systemd service

Quoted 5 lines · Stefan Agner

As an on and off contributor I rely on the instructions in the OE wiki. Unfortunately the example for meta-oe is just next of an example using the [email protected]. Maybe the second example should contain the correct address for meta-oe as well?
http://www.openembedded.org/wiki/How_to_submit_a_patch_to_OpenEmbedded#Sending_patches

That isn't a meta-oe specific example, but the typical OE-wide workflow unless the layer says otherwise.

Quoting from the page:

"""
You need to subscribe to the appropriate mailing-list in order to be able to send your patch(es) there; for patches against OE-Core the mailing list is [email protected] and for patches against meta-oe and many other layers the list is [email protected]. See Mailing lists for subscription and further details. """

Ross