summaryrefslogtreecommitdiffstats
path: root/recipes-core
diff options
context:
space:
mode:
authorDavid-John Willis <John.Willis@Distant-earth.com>2012-04-24 13:56:05 +0100
committerDavid-John Willis <John.Willis@Distant-earth.com>2012-04-24 13:56:05 +0100
commit03eef509e4aa5aae05326410fb9f9fdfcf433f48 (patch)
tree97a3494f64fa9ecc602935f0b373092a102fad7d /recipes-core
parent04f059923b89dad285847a02df88fad4ff612435 (diff)
downloadmeta-raspberrypi-03eef509e4aa5aae05326410fb9f9fdfcf433f48.tar.gz
rpi-zram-service: Add little systemd service to enable zram on the RPi.
* Needs to move to something more generic in time.
Diffstat (limited to 'recipes-core')
-rw-r--r--recipes-core/systemd/rpi-zram-service.bb30
-rw-r--r--recipes-core/systemd/rpi-zram-service/rpi-load-zram.sh36
-rw-r--r--recipes-core/systemd/rpi-zram-service/rpi-zram.service12
3 files changed, 78 insertions, 0 deletions
diff --git a/recipes-core/systemd/rpi-zram-service.bb b/recipes-core/systemd/rpi-zram-service.bb
new file mode 100644
index 0000000..f9e1e9c
--- /dev/null
+++ b/recipes-core/systemd/rpi-zram-service.bb
@@ -0,0 +1,30 @@
1DESCRIPTION = "Linux zram compressed in-memory swap systemd service"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
4
5inherit allarch systemd
6
7PR = "r0"
8
9SRC_URI = "file://rpi-zram.service \
10 file://rpi-load-zram.sh \
11 "
12
13do_compile() {
14 :
15}
16
17
18do_install () {
19 install -d ${D}/${bindir}
20
21 install -m 0755 ${WORKDIR}/rpi-load-zram.sh ${D}/${bindir}
22
23 install -d ${D}/${base_libdir}/systemd/system
24 install -m 0644 ${WORKDIR}/rpi-zram.service ${D}/${base_libdir}/systemd/system/
25}
26
27SYSTEMD_PACKAGES = "${PN}"
28SYSTEMD_SERVICE_${PN} = "rpi-zram.service"
29
30FILES_${PN} += "${base_libdir}/systemd"
diff --git a/recipes-core/systemd/rpi-zram-service/rpi-load-zram.sh b/recipes-core/systemd/rpi-zram-service/rpi-load-zram.sh
new file mode 100644
index 0000000..984dcd1
--- /dev/null
+++ b/recipes-core/systemd/rpi-zram-service/rpi-load-zram.sh
@@ -0,0 +1,36 @@
1#!/bin/sh
2
3num_cpus=$(grep -c processor /proc/cpuinfo)
4[ "$num_cpus" != 0 ] || num_cpus=1
5
6last_cpu=$((num_cpus - 1))
7
8mem_by_cpu=$(awk -v cpus=$num_cpus '/MemTotal/ { print (($2 * 1024) / cpus) }' /proc/meminfo)
9
10if [ "$1" = "--load" ] ; then
11 echo zram: Trying to load kernel module.
12
13 # Linux 3.2 workaround - value name changed :o.
14 # modprobe -q zram zram_num_devices=$num_cpus
15
16 # Linux < 3.2.
17 modprobe -q zram num_devices=$num_cpus
18
19 echo zram: Enable in-memory compressed swap of $mem_by_cpu bytes.
20 for i in $(seq 0 $last_cpu); do
21 echo $mem_by_cpu > /sys/block/zram$i/disksize
22 mkswap /dev/zram$i
23 swapon -p 100 /dev/zram$i
24 done
25fi
26
27if [ "$1" = "--unload" ] ; then
28 echo zram: Disable in-memory compressed swap.
29 for i in $(seq 0 $last_cpu); do
30 grep -q "/dev/zram$i" /proc/swaps && swapoff /dev/zram$i
31 done
32
33 sleep 1
34 echo zram: Unload kernel module.
35 rmmod zram
36fi
diff --git a/recipes-core/systemd/rpi-zram-service/rpi-zram.service b/recipes-core/systemd/rpi-zram-service/rpi-zram.service
new file mode 100644
index 0000000..007dfcc
--- /dev/null
+++ b/recipes-core/systemd/rpi-zram-service/rpi-zram.service
@@ -0,0 +1,12 @@
1[Unit]
2Description=Enable zram compressed in-memory swap.
3After=multi-user.target
4
5[Service]
6RemainAfterExit=yes
7ExecStart=/usr/bin/rpi-load-zram.sh --load
8ExecStop=/usr/bin/rpi-load-zram.sh --unload
9Type=oneshot
10
11[Install]
12WantedBy=multi-user.target