Skip to contentSkip to conversation

zram: Integrate an init script

PATCH In review Andrei Gherzan 1 participant 2 messages Sep 18, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zram: Integrate an init script

---
 meta-oe/recipes-extended/zram/zram/init   |   85 +++++++++++++++++++++++++++++
 meta-oe/recipes-extended/zram/zram_0.1.bb |   23 ++++++++
 2 files changed, 108 insertions(+)
 create mode 100644 meta-oe/recipes-extended/zram/zram/init
 create mode 100644 meta-oe/recipes-extended/zram/zram_0.1.bb
meta-oe/recipes-extended/zram/zram/init new file +85 -0
new file mode 100644
index 0000000..d126169
@@ -0,0 +1,85 @@
+#!/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)
+# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram
+# Included as part of antix-goodies package by anticapitalista <[email protected]>
+# This script was written by tradetaxfree and is found at http://crunchbanglinux.org/forums/topic/15344/zram-a-good-idea/
+# Copy this script (as root) from /usr/local/bin to /etc/init.d and then #update-rc.d zram defaults
+# After booting verify the module is loaded with: lsmod | grep zram
+### END INIT INFO
+set -e
+
+start() {
+    # get the number of CPUs
+    num_cpus=$(grep -c processor /proc/cpuinfo)
+    # if something goes wrong, assume we have 1
+    [ "$num_cpus" != 0 ] || num_cpus=1
+
+    # set decremented number of CPUs
+    last_cpu=$((num_cpus - 1))
+
+    #default Factor % = 90 change this value here or create /etc/default/zram
+    FACTOR=90
+    #& put the above single line in /etc/default/zram with the value you want
+    [ -f /etc/default/zram ] && source /etc/default/zram || true
+    factor=$FACTOR # percentage
+
+    # get the amount of memory in the machine
+    memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
+    mem_by_cpu=$(($memtotal/$num_cpus*$factor/100*1024))
+
+    # load dependency modules
+    modprobe zram zram_num_devices=$num_cpus
+    echo "zram devices probed successfully"
+
+    # initialize the devices
+    for i in $(seq 0 $last_cpu); do
+    	echo 1 > /sys/block/zram$i/reset
+    	echo $mem_by_cpu > /sys/block/zram$i/disksize
+    	# Creating swap filesystems
+    	mkswap /dev/zram$i
+    	# Switch the swaps on
+    	swapon -p 100 /dev/zram$i
+    done
+}
+
+stop() {
+    # get the number of CPUs
+    num_cpus=$(grep -c processor /proc/cpuinfo)
+
+    # set decremented number of CPUs
+    last_cpu=$((num_cpus - 1))
+
+    # Switching off swap
+    for i in $(seq 0 $last_cpu); do
+    	if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
+    		swapoff /dev/zram$i
+    		sleep 1
+    	fi
+    done
+    sleep 1
+    rmmod zram
+}
+
+case "$1" in
+    start)
+        start
+        ;;
+    stop)
+        stop
+        ;;
+    restart)
+        stop
+        sleep 3
+        start
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart}"
+        RETVAL=1
+esac
+exit $RETVAL
meta-oe/recipes-extended/zram/zram_0.1.bb new file +23 -0
new file mode 100644
index 0000000..8526264
@@ -0,0 +1,23 @@
+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 \
+          "
+
+do_install () {
+	# Sysvinit
+	install -d ${D}${sysconfdir}/init.d
+	install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/zram
+}
+
+FILES_${PN} = "${sysconfdir}/init.d"
+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

git send-email with --subject-prefix won't overwrite the subject. As well "man" says nothing about that flag. So i will resend with format-patch --subject-prefix... Probably this should be changed in README as well?

ag

Quoted 143 lines · Andrei Gherzan
---
 meta-oe/recipes-extended/zram/zram/init   |   85
+++++++++++++++++++++++++++++
 meta-oe/recipes-extended/zram/zram_0.1.bb |   23 ++++++++
 2 files changed, 108 insertions(+)
 create mode 100644 meta-oe/recipes-extended/zram/zram/init
 create mode 100644 meta-oe/recipes-extended/zram/zram_0.1.bb
meta-oe/recipes-extended/zram/zram/init new file +8 -0
new file mode 100644
index 0000000..d126169
@@ -0,0 +1,85 @@
+#!/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)
+# Description: Adapted from systemd scripts at
https://github.com/mystilleef/FedoraZram
+# Included as part of antix-goodies package by anticapitalista < [email protected]>
+# This script was written by tradetaxfree and is found at
http://crunchbanglinux.org/forums/topic/15344/zram-a-good-idea/
+# Copy this script (as root) from /usr/local/bin to /etc/init.d and then #update-rc.d zram defaults

meta-oe/recipes-extended/zram/zram/init new file +14 -0
+# After booting verify the module is loaded with: lsmod | grep zram
+### END INIT INFO
+set -e
+
+start() {
+    # get the number of CPUs
+    num_cpus=$(grep -c processor /proc/cpuinfo)
+    # if something goes wrong, assume we have 1
+    [ "$num_cpus" != 0 ] || num_cpus=1
+
+    # set decremented number of CPUs
+    last_cpu=$((num_cpus - 1))
+
+    #default Factor % = 90 change this value here or create

/etc/default/zram

meta-oe/recipes-extended/zram/zram/init new file +2 -0
+    FACTOR=90
+    #& put the above single line in /etc/default/zram with the value you

want

meta-oe/recipes-extended/zram/zram/init new file +57 -0
+    [ -f /etc/default/zram ] && source /etc/default/zram || true
+    factor=$FACTOR # percentage
+
+    # get the amount of memory in the machine
+    memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
+    mem_by_cpu=$(($memtotal/$num_cpus*$factor/100*1024))
+
+    # load dependency modules
+    modprobe zram zram_num_devices=$num_cpus
+    echo "zram devices probed successfully"
+
+    # initialize the devices
+    for i in $(seq 0 $last_cpu); do
+       echo 1 > /sys/block/zram$i/reset
+       echo $mem_by_cpu > /sys/block/zram$i/disksize
+       # Creating swap filesystems
+       mkswap /dev/zram$i
+       # Switch the swaps on
+       swapon -p 100 /dev/zram$i
+    done
+}
+
+stop() {
+    # get the number of CPUs
+    num_cpus=$(grep -c processor /proc/cpuinfo)
+
+    # set decremented number of CPUs
+    last_cpu=$((num_cpus - 1))
+
+    # Switching off swap
+    for i in $(seq 0 $last_cpu); do
+       if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
+               swapoff /dev/zram$i
+               sleep 1
+       fi
+    done
+    sleep 1
+    rmmod zram
+}
+
+case "$1" in
+    start)
+        start
+        ;;
+    stop)
+        stop
+        ;;
+    restart)
+        stop
+        sleep 3
+        start
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart}"
+        RETVAL=1
+esac
+exit $RETVAL
(quoted diff) +0 -0

zram_0.1.bb
new file mode 100644
index 0000000..8526264

meta-oe/recipes-extended/zram/zram_0.1.bb new file +3 -0
@@ -0,0 +1,23 @@
+DESCRIPTION = "Linux zram compressed in-memory swap"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM =

"file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"

meta-oe/recipes-extended/zram/zram_0.1.bb new file +20 -1
+
+inherit allarch update-rc.d
+
+RDEPENDS_${PN} = "util-linux-swaponoff kmod kernel-module-zram"
+
+PR = "r0"
+
+SRC_URI = " \
+           file://init \
+          "
+
+do_install () {
+       # Sysvinit
+       install -d ${D}${sysconfdir}/init.d
+       install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/zram
+}
+
+FILES_${PN} = "${sysconfdir}/init.d"
+INITSCRIPT_NAME = "zram"
+INITSCRIPT_PARAMS = "start 05 2 3 4 5 . stop 22 0 1 6 ."
--

1.7.9.5