Created
July 9, 2013 09:33
-
-
Save anonymous/5956013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
start() { | |
exec awk ' | |
FILENAME == "/proc/cpuinfo" && ($1 == "processor" || $1 == "Processor") { | |
cpucount++ | |
next | |
} | |
FILENAME == "/proc/meminfo" && $1 == "MemTotal:" { | |
mem_total = int( $2 * 1024 / 2 ) | |
next | |
} | |
END { | |
mem_per_cpu = int(mem_total / cpucount) | |
system("modprobe zram num_devices=" 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment