zram Usage as Default in Debian (?)
Hello,
I recently setup zram (for compressed swap space in RAM) on an older low RAM
machine. I was quite happy with the result and started now to do the same
setup also on my other machines. I am wondering if anybody is investigating,
if debian should do that by default when installing a new machine or even
better also when machines get upgraded.
Here is what I did:
(see http://crunchbanglinux.org/forums/post/150355/#p150355 for more details)
/etc/modules: add zram
add (num_devices=<number cpu cores>)
rd@blackbox:~$ cat /etc/modprobe.d/zram.conf
options zram num_devices=2
rd@blackbox:~$
/etc/init.d/zram
#!/bin/bash
### BEGIN INIT INFO
# Provides: zram
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Increased Performance In Linux With zRam (Virtual Swap
Compressed in RAM)
# Description: Adapted from systemd scripts at
https://github.com/mystilleef/FedoraZram
### END INIT INFO
start() {
# get the number of CPUs
num_cpus=$(grep -c processor /proc/cpuinfo)
# if something goes wrong, assume we have 1
[ "$num_cpus" != 0 ] || num_cpus=1
# set decremented number of CPUs
decr_num_cpus=$((num_cpus - 1))
# get the amount of memory in the machine
mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching
'[[:digit:]]+')
mem_total=$((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 $((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
}
stop() {
# get the number of CPUs
num_cpus=$(grep -c processor /proc/cpuinfo)
# set decremented number of CPUs
decr_num_cpus=$((num_cpus - 1))
# Switching off swap
for i in $(seq 0 $decr_num_cpus); do
if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
swapoff /dev/zram$i
sleep 1
fi
done
sleep 1
rmmod zram
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
################END##############
# update-rc.d zram defaults
Thanks,
Rainer
--
Rainer Dorsch
http://bokomoko.de/
Reply to: