public
anonymous / zramctrl
Created

  • Download Gist
zramctrl
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.