diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-08 22:51:41 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-08 22:51:41 +0200 |
commit | 1219bf8a90a7bf8cd3a5363551ef635d51e8fc8e (patch) | |
tree | a21a5fc103bb3bd65ecd85ed22be5228fc54e447 /meta-oe/recipes-extended/zram | |
download | meta-openembedded-1219bf8a90a7bf8cd3a5363551ef635d51e8fc8e.tar.gz |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta-oe/recipes-extended/zram')
-rw-r--r-- | meta-oe/recipes-extended/zram/zram/init | 85 | ||||
-rw-r--r-- | meta-oe/recipes-extended/zram/zram/zram.service | 12 | ||||
-rw-r--r-- | meta-oe/recipes-extended/zram/zram_0.1.bb | 33 |
3 files changed, 130 insertions, 0 deletions
diff --git a/meta-oe/recipes-extended/zram/zram/init b/meta-oe/recipes-extended/zram/zram/init new file mode 100644 index 000000000..d12616936 --- /dev/null +++ b/meta-oe/recipes-extended/zram/zram/init | |||
@@ -0,0 +1,85 @@ | |||
1 | #!/bin/bash | ||
2 | ### BEGIN INIT INFO | ||
3 | # Provides: zram | ||
4 | # Required-Start: | ||
5 | # Required-Stop: | ||
6 | # Default-Start: 2 3 4 5 | ||
7 | # Default-Stop: 0 1 6 | ||
8 | # Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM) | ||
9 | # Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram | ||
10 | # Included as part of antix-goodies package by anticapitalista <antiX@operamail.com> | ||
11 | # This script was written by tradetaxfree and is found at http://crunchbanglinux.org/forums/topic/15344/zram-a-good-idea/ | ||
12 | # Copy this script (as root) from /usr/local/bin to /etc/init.d and then #update-rc.d zram defaults | ||
13 | # After booting verify the module is loaded with: lsmod | grep zram | ||
14 | ### END INIT INFO | ||
15 | set -e | ||
16 | |||
17 | start() { | ||
18 | # get the number of CPUs | ||
19 | num_cpus=$(grep -c processor /proc/cpuinfo) | ||
20 | # if something goes wrong, assume we have 1 | ||
21 | [ "$num_cpus" != 0 ] || num_cpus=1 | ||
22 | |||
23 | # set decremented number of CPUs | ||
24 | last_cpu=$((num_cpus - 1)) | ||
25 | |||
26 | #default Factor % = 90 change this value here or create /etc/default/zram | ||
27 | FACTOR=90 | ||
28 | #& put the above single line in /etc/default/zram with the value you want | ||
29 | [ -f /etc/default/zram ] && source /etc/default/zram || true | ||
30 | factor=$FACTOR # percentage | ||
31 | |||
32 | # get the amount of memory in the machine | ||
33 | memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ') | ||
34 | mem_by_cpu=$(($memtotal/$num_cpus*$factor/100*1024)) | ||
35 | |||
36 | # load dependency modules | ||
37 | modprobe zram zram_num_devices=$num_cpus | ||
38 | echo "zram devices probed successfully" | ||
39 | |||
40 | # initialize the devices | ||
41 | for i in $(seq 0 $last_cpu); do | ||
42 | echo 1 > /sys/block/zram$i/reset | ||
43 | echo $mem_by_cpu > /sys/block/zram$i/disksize | ||
44 | # Creating swap filesystems | ||
45 | mkswap /dev/zram$i | ||
46 | # Switch the swaps on | ||
47 | swapon -p 100 /dev/zram$i | ||
48 | done | ||
49 | } | ||
50 | |||
51 | stop() { | ||
52 | # get the number of CPUs | ||
53 | num_cpus=$(grep -c processor /proc/cpuinfo) | ||
54 | |||
55 | # set decremented number of CPUs | ||
56 | last_cpu=$((num_cpus - 1)) | ||
57 | |||
58 | # Switching off swap | ||
59 | for i in $(seq 0 $last_cpu); do | ||
60 | if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then | ||
61 | swapoff /dev/zram$i | ||
62 | sleep 1 | ||
63 | fi | ||
64 | done | ||
65 | sleep 1 | ||
66 | rmmod zram | ||
67 | } | ||
68 | |||
69 | case "$1" in | ||
70 | start) | ||
71 | start | ||
72 | ;; | ||
73 | stop) | ||
74 | stop | ||
75 | ;; | ||
76 | restart) | ||
77 | stop | ||
78 | sleep 3 | ||
79 | start | ||
80 | ;; | ||
81 | *) | ||
82 | echo "Usage: $0 {start|stop|restart}" | ||
83 | RETVAL=1 | ||
84 | esac | ||
85 | exit $RETVAL | ||
diff --git a/meta-oe/recipes-extended/zram/zram/zram.service b/meta-oe/recipes-extended/zram/zram/zram.service new file mode 100644 index 000000000..4a19367d9 --- /dev/null +++ b/meta-oe/recipes-extended/zram/zram/zram.service | |||
@@ -0,0 +1,12 @@ | |||
1 | [Unit] | ||
2 | Description=Enable zram compressed in-memory swap. | ||
3 | After=multi-user.target | ||
4 | |||
5 | [Service] | ||
6 | RemainAfterExit=yes | ||
7 | ExecStart=/usr/bin/zram-load.sh --load | ||
8 | ExecStop=/usr/bin/zram-load.sh --unload | ||
9 | Type=oneshot | ||
10 | |||
11 | [Install] | ||
12 | WantedBy=multi-user.target | ||
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 000000000..e07f570d1 --- /dev/null +++ b/meta-oe/recipes-extended/zram/zram_0.1.bb | |||
@@ -0,0 +1,33 @@ | |||
1 | SUMMARY = "Linux zram compressed in-memory swap" | ||
2 | LICENSE = "MIT" | ||
3 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690" | ||
4 | |||
5 | inherit update-rc.d systemd | ||
6 | |||
7 | RDEPENDS_${PN} = "util-linux-swaponoff kmod" | ||
8 | RRECOMMENDS_${PN} = "kernel-module-zram" | ||
9 | |||
10 | PR = "r3" | ||
11 | |||
12 | SRC_URI = " \ | ||
13 | file://init \ | ||
14 | file://zram.service \ | ||
15 | " | ||
16 | |||
17 | do_install () { | ||
18 | # Sysvinit | ||
19 | install -d ${D}${sysconfdir}/init.d | ||
20 | install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/zram | ||
21 | |||
22 | install -d ${D}${systemd_unitdir}/system | ||
23 | install -m 0644 ${WORKDIR}/zram.service ${D}${systemd_unitdir}/system | ||
24 | } | ||
25 | |||
26 | FILES_${PN} = "${sysconfdir}" | ||
27 | INITSCRIPT_NAME = "zram" | ||
28 | INITSCRIPT_PARAMS = "start 05 2 3 4 5 . stop 22 0 1 6 ." | ||
29 | |||
30 | RPROVIDES_${PN} += "${PN}-systemd" | ||
31 | RREPLACES_${PN} += "${PN}-systemd" | ||
32 | RCONFLICTS_${PN} += "${PN}-systemd" | ||
33 | SYSTEMD_SERVICE_${PN} = "zram.service" | ||