Skip to contentSkip to conversation

zram: Integrate an init script

PATCH In review Andrei Gherzan 2 participants 3 messages Sep 18, 2012 – Sep 20, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 zram: Integrate an init script

---
 meta-oe/recipes-extended/zram/zram/init         |   28 +++++++++++++++++
 meta-oe/recipes-extended/zram/zram/zram-load.sh |   37 +++++++++++++++++++++++
 meta-oe/recipes-extended/zram/zram_0.1.bb       |   24 +++++++++++++++
 3 files changed, 89 insertions(+)
 create mode 100644 meta-oe/recipes-extended/zram/zram/init
 create mode 100644 meta-oe/recipes-extended/zram/zram/zram-load.sh
 create mode 100644 meta-oe/recipes-extended/zram/zram_0.1.bb
meta-oe/recipes-extended/zram/zram/init new file +28 -0
new file mode 100644
index 0000000..7bd8bcc
@@ -0,0 +1,28 @@
+#!/bin/bash
+### BEGIN INIT INFO
+# Provides: zram
+# Required-Start:
+# Required-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
+### END INIT INFO
+set -e
+
+case "$1" in
+    start)
+        zram-load.sh --load
+        ;;
+    stop)
+        zram-load.sh --unload
+        ;;
+    restart)
+        zram-load.sh --unload
+        sleep 3
+        zram-load.sh --load
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart}"
+        RETVAL=1
+esac
+exit $RETVAL
meta-oe/recipes-extended/zram/zram/zram-load.sh new file +37 -0
new file mode 100644
index 0000000..786cd0c
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+num_cpus=$(grep -c processor /proc/cpuinfo)
+[ "$num_cpus" != 0 ] || num_cpus=1
+
+last_cpu=$((num_cpus - 1))
+
+mem_by_cpu=$(awk -v cpus=$num_cpus '/MemTotal/ { print (($2 * 1024) / cpus) }' /proc/meminfo)
+
+if [ "$1" = "--load" ] ; then
+	echo zram: Trying to load kernel module.
+
+	# Linux 3.2 workaround - value name changed :o.
+	modprobe -q zram zram_num_devices=$num_cpus
+
+	# Linux < 3.2.
+	#modprobe -q zram num_devices=$num_cpus
+
+	echo zram: Enable in-memory compressed swap of $mem_by_cpu bytes.
+	for i in $(seq 0 $last_cpu); do
+		echo 1 > /sys/block/zram$i/reset
+		echo $mem_by_cpu > /sys/block/zram$i/disksize
+		mkswap /dev/zram$i
+		swapon -p 100 /dev/zram$i
+	done
+fi
+
+if [ "$1" = "--unload" ] ; then
+	echo zram: Disable in-memory compressed swap.
+	for i in $(seq 0 $last_cpu); do
+		grep -q "/dev/zram$i" /proc/swaps && swapoff /dev/zram$i
+	done
+
+	sleep 1
+	echo zram: Unload kernel module.
+	rmmod zram
+fi
meta-oe/recipes-extended/zram/zram_0.1.bb new file +24 -0
new file mode 100644
index 0000000..dd59784
@@ -0,0 +1,24 @@
+DESCRIPTION = "Linux zram compressed in-memory swap"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
+
+inherit allarch update-rc.d
+
+RDEPENDS_${PN} = "util-linux-swaponoff kmod kernel-module-zram"
+
+PR = "r0"
+
+SRC_URI = " \
+           file://init \
+           file://zram-load.sh \
+          "
+
+do_install () {
+	install -d ${D}/${bindir}
+	install -m 0755 ${WORKDIR}/zram-load.sh ${D}/${bindir}
+	install -d ${D}${sysconfdir}/init.d
+	install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/zram
+}
+
+INITSCRIPT_NAME = "zram"
+INITSCRIPT_PARAMS = "start 05 2 3 4 5 . stop 22 0 1 6 ."
Signature · 1 line
1.7.9.5
#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Op 18-09-12 21:35, Andrei Gherzan schreef:

Quoted 41 lines
meta-oe/recipes-extended/zram/zram/init         |   28 +++++++++++++++++ 
meta-oe/recipes-extended/zram/zram/zram-load.sh |   37

+++++++++++++++++++++++ meta-oe/recipes-extended/zram/zram_0.1.bb |
24 +++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 meta-oe/recipes-extended/zram/zram/init create mode 100644 meta-oe/recipes-extended/zram/zram/zram-load.sh create mode 100644 meta-oe/recipes-extended/zram/zram_0.1.bb

(quoted diff) +0 -0

b/meta-oe/recipes-extended/zram/zram/init new file mode 100644 index 0000000..7bd8bcc --- /dev/null +++ b/meta-oe/recipes-extended/zram/zram/init @@ -0,0 +1,28 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: zram +# Required-Start: +#
Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +#
Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM) +### END INIT INFO +set -e + +case "$1" in +
start) + zram-load.sh --load + ;; + stop) +
zram-load.sh --unload + ;; + restart) + zram-load.sh
--unload + sleep 3 + zram-load.sh --load + ;; +
*) + echo "Usage: $0 {start|stop|restart}" + RETVAL=1
+esac +exit $RETVAL diff --git a/meta-oe/recipes-extended/zram/zram/zram-load.sh b/meta-oe/recipes-extended/zram/zram/zram-load.sh new file mode 100644 index 0000000..786cd0c --- /dev/null +++ b/meta-oe/recipes-extended/zram/zram/zram-load.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +num_cpus=$(grep -c processor /proc/cpuinfo) +[ "$num_cpus" != 0 ] || num_cpus=1 + +last_cpu=$((num_cpus - 1)) + +mem_by_cpu=$(awk -v cpus=$num_cpus '/MemTotal/ { print (($2 * 1024) / cpus) }'
/proc/meminfo) + +if [ "$1" = "--load" ] ; then + echo zram: Trying to
load kernel module. + + # Linux 3.2 workaround - value name changed :o. +
modprobe -q zram zram_num_devices=$num_cpus + + # Linux < 3.2. +
#modprobe -q zram num_devices=$num_cpus + + echo zram: Enable in-memory
compressed swap of $mem_by_cpu bytes. + for i in $(seq 0 $last_cpu); do +
echo 1 > /sys/block/zram$i/reset + echo $mem_by_cpu >
/sys/block/zram$i/disksize + mkswap /dev/zram$i + swapon -p 100
/dev/zram$i + done +fi + +if [ "$1" = "--unload" ] ; then + echo zram:
Disable in-memory compressed swap. + for i in $(seq 0 $last_cpu); do +
grep -q "/dev/zram$i" /proc/swaps && swapoff /dev/zram$i + done + + sleep
1 + echo zram: Unload kernel module. + rmmod zram +fi diff --git
a/meta-oe/recipes-extended/zram/zram_0.1.bb

Quoted 8 lines

b/meta-oe/recipes-extended/zram/zram_0.1.bb new file mode 100644 index 0000000..dd59784 --- /dev/null +++ b/meta-oe/recipes-extended/zram/zram_0.1.bb @@ -0,0 +1,24 @@ +DESCRIPTION = "Linux zram compressed in-memory swap" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58" + +inherit allarch update-rc.d + +RDEPENDS_${PN} = "util-linux-swaponoff kmod kernel-module-zram"

You are never allowed to RDEPEND on a kernel-module, imagine what happens when it's builtin. Also R* variables go below do_install

Quoted 1 line

+ +PR = "r0"

Remove that

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
Comment: GPGTools - http://gpgtools.org

iD8DBQFQWs4JMkyGM64RGpERArflAJ9et18piezL0x+DWynSvSvjFeKPDACeJ/N3 AYTy8UaWNsNAxNxw5ciDx74=
=ahxG
-----END PGP SIGNATURE-----

#2 lore raw
Quoted 55 lines · Koen Kooi

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Op 18-09-12 21:35, Andrei Gherzan schreef:

Quoted 4 lines
meta-oe/recipes-extended/zram/zram/init         |   28 +++++++++++++++++
meta-oe/recipes-extended/zram/zram/zram-load.sh |   37

+++++++++++++++++++++++ meta-oe/recipes-extended/zram/zram_0.1.bb

|

Quoted 18 lines

24 +++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 meta-oe/recipes-extended/zram/zram/init create mode 100644 meta-oe/recipes-extended/zram/zram/zram-load.sh create mode 100644 meta-oe/recipes-extended/zram/zram_0.1.bb

(quoted diff) +0 -0

b/meta-oe/recipes-extended/zram/zram/init new file mode 100644 index 0000000..7bd8bcc --- /dev/null +++ b/meta-oe/recipes-extended/zram/zram/init @@ -0,0 +1,28 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: zram +# Required-Start: +#
Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +#
Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM) +### END INIT INFO +set -e + +case "$1" in +
start) + zram-load.sh --load + ;; + stop) +
zram-load.sh --unload + ;; + restart) + zram-load.sh
--unload + sleep 3 + zram-load.sh --load + ;; +
*) + echo "Usage: $0 {start|stop|restart}" + RETVAL=1
+esac +exit $RETVAL diff --git

Quoted 8 lines

a/meta-oe/recipes-extended/zram/zram/zram-load.sh b/meta-oe/recipes-extended/zram/zram/zram-load.sh new file mode 100644 index 0000000..786cd0c --- /dev/null +++ b/meta-oe/recipes-extended/zram/zram/zram-load.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +num_cpus=$(grep -c processor /proc/cpuinfo) +[ "$num_cpus" != 0 ] || num_cpus=1 + +last_cpu=$((num_cpus - 1)) + +mem_by_cpu=$(awk -v cpus=$num_cpus '/MemTotal/ { print (($2 * 1024) / cpus) }'
/proc/meminfo) + +if [ "$1" = "--load" ] ; then + echo zram: Trying

to

Quoted 1 line

load kernel module. + + # Linux 3.2 workaround - value name

changed :o. +

Quoted 3 lines

modprobe -q zram zram_num_devices=$num_cpus + + # Linux < 3.2. +
#modprobe -q zram num_devices=$num_cpus + + echo zram: Enable in-memory
compressed swap of $mem_by_cpu bytes. + for i in $(seq 0

$last_cpu); do +

Quoted 2 lines

echo 1 > /sys/block/zram$i/reset + echo $mem_by_cpu >
/sys/block/zram$i/disksize + mkswap /dev/zram$i +

swapon -p 100

Quoted 3 lines

/dev/zram$i + done +fi + +if [ "$1" = "--unload" ] ; then + echo zram:
Disable in-memory compressed swap. + for i in $(seq 0 $last_cpu); do +
grep -q "/dev/zram$i" /proc/swaps && swapoff /dev/zram$i + done + +

sleep

Quoted 5 lines

1 + echo zram: Unload kernel module. + rmmod zram +fi diff --git
a/meta-oe/recipes-extended/zram/zram_0.1.bb b/meta-oe/recipes-extended/zram/zram_0.1.bb new file mode 100644 index 0000000..dd59784 --- /dev/null +++ b/meta-oe/recipes-extended/zram/zram_0.1.bb @@ -0,0 +1,24 @@

+DESCRIPTION

Quoted 10 lines
Quoted 5 lines

= "Linux zram compressed in-memory swap" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58" + +inherit allarch update-rc.d + +RDEPENDS_${PN} = "util-linux-swaponoff kmod kernel-module-zram"

You are never allowed to RDEPEND on a kernel-module, imagine what happens when it's builtin. Also R* variables go below do_install

Very true. About R* after do_install i didn't know that this was a rule. But i will obey. :)

Quoted 2 lines
Quoted 1 line

+ +PR = "r0"

Remove that

Quoted 2 lines

Next patch coming.

ag