summaryrefslogtreecommitdiff
path: root/pcr
diff options
context:
space:
mode:
Diffstat (limited to 'pcr')
-rw-r--r--pcr/zramswap/PKGBUILD24
-rwxr-xr-xpcr/zramswap/zramctrl50
-rw-r--r--pcr/zramswap/zramswap.service11
3 files changed, 85 insertions, 0 deletions
diff --git a/pcr/zramswap/PKGBUILD b/pcr/zramswap/PKGBUILD
new file mode 100644
index 000000000..db38ab084
--- /dev/null
+++ b/pcr/zramswap/PKGBUILD
@@ -0,0 +1,24 @@
+# Contributor (Arch): ifaigios <ifaigios_at_gmail_dot_com>
+# Contributor (Arch): Alyssa Hung <deciare@isisiew.org>
+# Contributor (Arch): Matt Brennan
+# Contributor (Arch): falconindy
+# Contributor (Arch): adee
+# Contributor (Arch): mystilleef
+
+pkgname=zramswap
+pkgver=1.1
+pkgrel=1
+pkgdesc="Sets up zram-based swap devices on boot"
+arch=('any')
+url="http://en.wikipedia.org/wiki/ZRam"
+license=('GPL')
+depends=('bash')
+source=("zramctrl"
+ "zramswap.service")
+md5sums=('709480a5f46fc4b6bea16800823240c1'
+ 'a6c029dc942c85704b0f6ac1ca078a24')
+
+package() {
+ install -Dm755 zramctrl $pkgdir/usr/lib/systemd/scripts/zramctrl
+ install -Dm644 zramswap.service $pkgdir/usr/lib/systemd/system/zramswap.service
+}
diff --git a/pcr/zramswap/zramctrl b/pcr/zramswap/zramctrl
new file mode 100755
index 000000000..0165e769c
--- /dev/null
+++ b/pcr/zramswap/zramctrl
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+
+start() {
+ exec awk -v ZRAM_SIZE=$ZRAM_SIZE -v ZRAM_PARM="$(modinfo zram | grep -E -o '(num_devices|zram_num_devices)')" '
+
+ FILENAME == "/proc/cpuinfo" && ($1 == "processor" || $1 == "Processor") {
+ cpucount++
+ next
+ }
+
+ FILENAME == "/proc/meminfo" && $1 == "MemTotal:" {
+ if (ZRAM_SIZE == "")
+ ZRAM_SIZE = 20
+ mem_total = int( (0 + $2) * 1024 * ( ZRAM_SIZE/100 ) )
+ next
+ }
+
+ END {
+ mem_per_cpu = int(mem_total / cpucount)
+
+ system("modprobe zram "ZRAM_PARM"=" cpucount)
+
+ for (i = 0; i < cpucount; i++) {
+ print mem_per_cpu > "/sys/block/zram" i "/disksize"
+ system("mkswap /dev/zram" i " -L zram" i)
+ swapdevs = swapdevs " /dev/zram" i
+ }
+
+ system("swapon -p 100" swapdevs)
+ }
+ ' /proc/cpuinfo /proc/meminfo
+}
+
+stop() {
+ exec awk '
+ FNR > 1 && $1 ~ /^\/dev\/zram[0-9]+$/ {
+ activeswaps = activeswaps " " $1
+ }
+
+ END {
+ system("swapoff" activeswaps)
+ system("rmmod zram")
+ }
+ ' /proc/swaps
+}
+
+case $1 in
+ start|stop) "$1" ;;
+esac \ No newline at end of file
diff --git a/pcr/zramswap/zramswap.service b/pcr/zramswap/zramswap.service
new file mode 100644
index 000000000..9c9cccd23
--- /dev/null
+++ b/pcr/zramswap/zramswap.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Zram-based swap (compressed RAM block devices)
+
+[Service]
+Type=oneshot
+ExecStart=/usr/lib/systemd/scripts/zramctrl start
+ExecStop=/usr/lib/systemd/scripts/zramctrl stop
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target \ No newline at end of file