A successor to compcache, zram, has been already integrated in the Linux kernel for a while now. This means that no additional compilation nor tweaking is required to benefit from compressing memory on the fly and massively reduced swapping.
As with compache, I wanted to nicely integrate the solution into the Ubuntu Upstart deamon – hence this short article. After a couple of minutes of playing the configuration was ready.
/etc/init and put the following content in it.
description "Initializes zram swaping" start on runlevel  stop on runlevel [!2345] pre-start script # load dependency modules modprobe zram num_devices=2 # initialize the devices echo 1073741824 > /sys/block/zram0/disksize echo 1073741824 > /sys/block/zram1/disksize # Creating swap filesystems mkswap /dev/zram0 mkswap /dev/zram1 # Switch the swaps on swapon -p 5 /dev/zram0 swapon -p 5 /dev/zram1 end script post-stop script # Switching off swap swapoff /dev/zram0 swapoff /dev/zram1 rmmod zram end script
Now you can start the service with
sudo start zramswap (it will be automatically started on after the reboot as well).
You will benefit from 2x1GB swap files, which will be compressed and stored in the RAM. Tested on Ubuntu 11.04.