[oe] [meta-oe][PATCH][V2] zram: Integrate an init script
Andrei Gherzan
andrei at gherzan.ro
Tue Sep 18 19:35:07 UTC 2012
Signed-off-by: Andrei Gherzan <andrei at gherzan.ro>
---
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
diff --git a/meta-oe/recipes-extended/zram/zram/init 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 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"
+
+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 ."
--
1.7.9.5
More information about the Openembedded-devel
mailing list