Created
January 8, 2012 21:00
-
-
Save nagisa/1579690 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/bash | |
. /etc/rc.conf | |
. /etc/rc.d/functions | |
# get the number of CPUs | |
num_cpus=`grep -c processor /proc/cpuinfo` | |
# set decremented number of CPUs | |
decr_num_cpus=`expr $num_cpus - 1` | |
case "$1" in | |
start) | |
stat_busy "Enabling zRam" | |
# get the amount of memory in the machine | |
mem_total_kb=`grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+'` | |
mem_total=`expr $mem_total_kb \* 1024` | |
# load dependency modules | |
modprobe zram num_devices=$num_cpus | |
# initialize the devices | |
for i in `seq 0 $decr_num_cpus`; do | |
echo `expr $mem_total / $num_cpus` > /sys/block/zram$i/disksize | |
done | |
# Creating swap filesystems | |
for i in `seq 0 $decr_num_cpus`; do | |
mkswap /dev/zram$i | |
done | |
# Switch the swaps on | |
for i in `seq 0 $decr_num_cpus`; do | |
swapon -p 100 /dev/zram$i | |
done | |
stat_done | |
;; | |
stop) | |
stat_busy "Switching off zRam" | |
# Switching off swap | |
for i in `seq 0 $decr_num_cpus`; do | |
if [ "`grep /dev/zram$i /proc/swaps`" != "" ]; then | |
swapoff /dev/zram$i | |
fi | |
done | |
rmmod zram | |
stat_done | |
;; | |
*) | |
echo "usage: $0 {start|stop}" | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment