summaryrefslogtreecommitdiff
path: root/pcr/zramswap/zramctrl
diff options
context:
space:
mode:
authorAndré Fabian Silva Delgado <emulatorman@parabola.nu>2016-02-15 11:05:30 -0300
committerAndré Fabian Silva Delgado <emulatorman@parabola.nu>2016-02-15 11:05:30 -0300
commitc83fbf48335526dfdf2aecae68dc64e1afee782c (patch)
tree946c498e19bfb622f18b7cfa97007d7920916801 /pcr/zramswap/zramctrl
parent3c7a285743ba82cd77dcaa3256ae49664a46358d (diff)
downloadabslibre-c83fbf48335526dfdf2aecae68dc64e1afee782c.tar.gz
abslibre-c83fbf48335526dfdf2aecae68dc64e1afee782c.tar.bz2
abslibre-c83fbf48335526dfdf2aecae68dc64e1afee782c.zip
zramswap: add new package to [pcr]
Diffstat (limited to 'pcr/zramswap/zramctrl')
-rwxr-xr-xpcr/zramswap/zramctrl50
1 files changed, 50 insertions, 0 deletions
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