Patchwork [meta-oe,V2] zram: Integrate an init script

login
register
mail settings
Submitter Andrei Gherzan
Date Sept. 18, 2012, 7:35 p.m.
Message ID <1347996907-22852-1-git-send-email-andrei@gherzan.ro>
Download mbox | patch
Permalink /patch/36845/
State Superseded
Headers show

Comments

Andrei Gherzan - Sept. 18, 2012, 7:35 p.m.
Signed-off-by: Andrei Gherzan <andrei@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
Koen Kooi - Sept. 20, 2012, 8:04 a.m.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Op 18-09-12 21:35, Andrei Gherzan schreef:
> Signed-off-by: Andrei Gherzan <andrei@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"

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

> + +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-----
Andrei Gherzan - Sept. 20, 2012, 8:17 a.m.
On Thu, Sep 20, 2012 at 11:04 AM, Koen Kooi <koen@dominion.thruhere.net>wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Op 18-09-12 21:35, Andrei Gherzan schreef:
> > Signed-off-by: Andrei Gherzan <andrei@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"
>
> 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. :)


> > + +PR = "r0"
>

Remove that
>
> Next patch coming.

ag

Patch

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 ."