Script to enable zram
Posted: 6. Apr 2012, 00:00
With the Thinkpad 600E I'm currently posting from, zram (compressed swap space in RAM) is a huge deal. With a 128 MB zram disk, the computer is usable with Salix, Fluxbox and a bunch of light applications; without zram, it is not usable at all, unless you use a toy OS like Puppy.
To automate things, and since zram likes having the same number of ramdisks as CPU cores, I suggest a script like this (crappy, totally unprofessional) one be included somewhere in the next Salix release...
Assuming I did it right, this would create a number of ZRAM disks equal to the number of CPU cores, adding up to a maximum total of [edit]the entirety of physical memory. This should be okay, assuming you have any real swap space to fall back on.[/edit]
NB: I certainly don't suggest that anything like this be enabled by default... Just present in the install in case someone wants to run Salix on an old machine.
(Not that old machines with multiple cores are common, but who knows.)
Edit 05/17/2012: updated the script to be less brain damaged. Also note that, for 3.x kernels, you must use zram_num_devices rather than num_devices as the module parameter.
Edit 08/05/2012: modified the script so it doesn't bail out on computers with < 1 GB of memory. Duh!
To automate things, and since zram likes having the same number of ramdisks as CPU cores, I suggest a script like this (crappy, totally unprofessional) one be included somewhere in the next Salix release...
Code: Select all
# Number of CPU cores and bytes of physical memory
num_cpus=`grep -c processor /proc/cpuinfo`
mem_bytes=`free -b | grep Mem | tr -s " " | cut -f 2 -d " "`
# individual disk size is half of MEM_BYTES, divided by NUM_CPUS
zram_size=$(($mem_bytes / $num_cpus))
# Load zram and resize the disks
modprobe zram num_devices=$num_cpus
for i in /sys/block/zram*; do
echo $zram_size > $i/disksize
done
# Create the swap spaces and start swapping
for i in /dev/zram*; do
mkswap $i
swapon -p 32767 $i
done
NB: I certainly don't suggest that anything like this be enabled by default... Just present in the install in case someone wants to run Salix on an old machine.
(Not that old machines with multiple cores are common, but who knows.)
Edit 05/17/2012: updated the script to be less brain damaged. Also note that, for 3.x kernels, you must use zram_num_devices rather than num_devices as the module parameter.
Edit 08/05/2012: modified the script so it doesn't bail out on computers with < 1 GB of memory. Duh!