Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] zram: properly implement systemd service
@ 2019-10-05 21:08 Stefan Agner
  2019-10-05 21:31 ` ✗ patchtest: failure for " Patchwork
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Agner @ 2019-10-05 21:08 UTC (permalink / raw)
  To: openembedded-core; +Cc: Stefan Agner

From: Stefan Agner <stefan.agner@toradex.com>

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.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
---
 .../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

diff --git a/meta-oe/recipes-extended/zram/zram/dev-zram0.swap b/meta-oe/recipes-extended/zram/zram/dev-zram0.swap
new file mode 100644
index 000000000..05eae7eed
--- /dev/null
+++ b/meta-oe/recipes-extended/zram/zram/dev-zram0.swap
@@ -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
diff --git a/meta-oe/recipes-extended/zram/zram/zram-swap-deinit b/meta-oe/recipes-extended/zram/zram/zram-swap-deinit
new file mode 100755
index 000000000..46248c401
--- /dev/null
+++ b/meta-oe/recipes-extended/zram/zram/zram-swap-deinit
@@ -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
+
diff --git a/meta-oe/recipes-extended/zram/zram/zram-swap-init b/meta-oe/recipes-extended/zram/zram/zram-swap-init
new file mode 100755
index 000000000..0643dbca2
--- /dev/null
+++ b/meta-oe/recipes-extended/zram/zram/zram-swap-init
@@ -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
diff --git a/meta-oe/recipes-extended/zram/zram/zram-swap.service b/meta-oe/recipes-extended/zram/zram/zram-swap.service
new file mode 100644
index 000000000..7bb9e0a45
--- /dev/null
+++ b/meta-oe/recipes-extended/zram/zram/zram-swap.service
@@ -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
diff --git a/meta-oe/recipes-extended/zram/zram/zram.service b/meta-oe/recipes-extended/zram/zram/zram.service
deleted file mode 100644
index 4a19367d9..000000000
--- a/meta-oe/recipes-extended/zram/zram/zram.service
+++ /dev/null
@@ -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
diff --git a/meta-oe/recipes-extended/zram/zram/zramstop b/meta-oe/recipes-extended/zram/zram/zramstop
new file mode 100644
index 000000000..07777978e
--- /dev/null
+++ b/meta-oe/recipes-extended/zram/zram/zramstop
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+for i in $(grep '^/dev/zram' /proc/swaps | awk '{ print $1 }'); do
+	swapoff "$i" && zramctl --reset "$i"
+done
diff --git a/meta-oe/recipes-extended/zram/zram_0.1.bb b/meta-oe/recipes-extended/zram/zram_0.1.bb
deleted file mode 100644
index dfd75e71c..000000000
--- a/meta-oe/recipes-extended/zram/zram_0.1.bb
+++ /dev/null
@@ -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"
diff --git a/meta-oe/recipes-extended/zram/zram_0.2.bb b/meta-oe/recipes-extended/zram/zram_0.2.bb
new file mode 100644
index 000000000..ca3b3b0c1
--- /dev/null
+++ b/meta-oe/recipes-extended/zram/zram_0.2.bb
@@ -0,0 +1,49 @@
+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} = "kmod \
+    ${@bb.utils.contains('DISTRO_FEATURES','systemd','util-linux','util-linux-swaponoff',d)}"
+RRECOMMENDS_${PN} = "kernel-module-zram"
+
+PR = "r3"
+
+SRC_URI = " \
+           file://init \
+           file://zram-swap-init \
+           file://zram-swap-deinit \
+           file://zram-swap.service \
+           file://dev-zram0.swap \
+"
+
+do_install () {
+    # Install systemd related configuration file
+    if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'true', 'false', d)}; then
+        install -d ${D}${sysconfdir}/init.d
+        install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/zram
+    fi
+
+    if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
+        install -d ${D}${libexecdir}
+        install -m 0755 ${WORKDIR}/zram-swap-init ${D}${libexecdir}
+        install -m 0755 ${WORKDIR}/zram-swap-deinit ${D}${libexecdir}
+        install -d ${D}${systemd_unitdir}/system
+        install -m 0644 ${WORKDIR}/zram-swap.service ${D}${systemd_unitdir}/system
+        install -m 0644 ${WORKDIR}/dev-zram0.swap ${D}${systemd_unitdir}/system
+    fi
+}
+
+FILES_${PN} = " \
+    ${sysconfdir} \
+    ${systemd_unitdir} \
+    ${libexecdir} \
+"
+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} = "dev-zram0.swap"
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* ✗ patchtest: failure for zram: properly implement systemd service
  2019-10-05 21:08 [PATCH] zram: properly implement systemd service Stefan Agner
@ 2019-10-05 21:31 ` Patchwork
  2019-10-05 22:20   ` Stefan Agner
  0 siblings, 1 reply; 4+ messages in thread
From: Patchwork @ 2019-10-05 21:31 UTC (permalink / raw)
  To: Stefan Agner; +Cc: openembedded-core

== 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     openembedded-devel@lists.openembedded.org [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 (openembedded-core@lists.openembedded.org) 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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ✗ patchtest: failure for zram: properly implement systemd service
  2019-10-05 21:31 ` ✗ patchtest: failure for " Patchwork
@ 2019-10-05 22:20   ` Stefan Agner
  2019-10-07 11:41     ` Ross Burton
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Agner @ 2019-10-05 22:20 UTC (permalink / raw)
  To: openembedded-core

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 openembedded-core@lists.openembedded.org. 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


On 2019-10-05 23:31, Patchwork wrote:
> == 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     openembedded-devel@lists.openembedded.org
> [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 (openembedded-core@lists.openembedded.org) 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ✗ patchtest: failure for zram: properly implement systemd service
  2019-10-05 22:20   ` Stefan Agner
@ 2019-10-07 11:41     ` Ross Burton
  0 siblings, 0 replies; 4+ messages in thread
From: Ross Burton @ 2019-10-07 11:41 UTC (permalink / raw)
  To: openembedded-core

On 05/10/2019 23:20, Stefan Agner wrote:
> 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 openembedded-core@lists.openembedded.org. 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 openembedded-core@lists.openembedded.org and for patches 
against meta-oe and many other layers the list is 
openembedded-devel@lists.openembedded.org. See Mailing lists for 
subscription and further details.
"""

Ross


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-07 11:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-05 21:08 [PATCH] zram: properly implement systemd service Stefan Agner
2019-10-05 21:31 ` ✗ patchtest: failure for " Patchwork
2019-10-05 22:20   ` Stefan Agner
2019-10-07 11:41     ` Ross Burton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox