Ubuntu: How to permanently enable compressed ram swap? What version to use?



Question:

EDIT: In precise there's now zram-config. It's an upstart job compressing up to half of your ram spread over $(number of CPU cores) swap devices. It didn't allways start at boot but issuing sudo service zram-config start works.

I enabled compcache="256 M" in /etc/initramfs-tools/initramfs.conf as described here (by me :P). This - I believe - creates /dev/ramzswap0 but it is never enabled as swap. It works only after mkswap && swapon.

Then there is the module zram that creates /dev/zram. Is it something else? It works the same way but /dev/ramzswap is created from the module ramzswap.

At the end of the day I wanna have a compressed swap in ram and use the better of the two and for that I need to know how to enable it permanently in a non hackish way. How is this done?

I wrote about ramzswap in Lucid here but things have changed in Natty. You can still enable ramzswap in initramfs.conf but it doesn't get activated.

P.S.:I scanned all udev rules in /lib and/etc but found nothing of interest.


Solution:1

There's now a PPA that installs a proper Upstart script for enabling zram at boot-time. It chooses the correct size and number of compressed swap devices for your system.

https://launchpad.net/~shnatsel/+archive/zram


Solution:2

I was struggling with the same problem.

Today I found an excellent blog post about it. http://weirdfellow.wordpress.com/2011/05/04/compressed-ram-with-zram/

Although "sudo start zramswap" didn't work, when I restarted my PC it solved my problem perfectly.

Try it.


Solution:3

Here's the cheap solution. Add the following line to /etc/rc.local, before the exit 0:

find /dev/ -maxdepth 1 -name 'ramzswap*' | while read dev; do      mkswap $dev      swapon -p 1000 $dev  done  


Solution:4

Straight from the Debian wiki. For me, this is the easiest.

First, copy and paste this code into /etc/init.d/zram

### BEGIN INIT INFO  # Provides:          zram  # Required-Start:    $local_fs  # Required-Stop:     $local_fs  # Default-Start:     S  # Default-Stop:      0 1 6  # Short-Description: Use compressed RAM as in-memory swap  # Description:       Use compressed RAM as in-memory swap  ### END INIT INFO    # Author: Antonio Galea <antonio.galea@gmail.com>  # Thanks to Przemysław Tomczyk for suggesting swapoff parallelization    FRACTION=75    MEMORY=`perl -ne'/^MemTotal:\s+(\d+)/ && print $1*1024;' < /proc/meminfo`  CPUS=`grep -c processor /proc/cpuinfo`  SIZE=$(( MEMORY * FRACTION / 100 / CPUS ))    case "$1" in    "start")      param=`modinfo zram|grep num_devices|cut -f2 -d:|tr -d ' '`      modprobe zram $param=$CPUS      for n in `seq $CPUS`; do        i=$((n - 1))        echo $SIZE > /sys/block/zram$i/disksize        mkswap /dev/zram$i        swapon /dev/zram$i -p 10      done      ;;    "stop")      for n in `seq $CPUS`; do        i=$((n - 1))        swapoff /dev/zram$i && echo "disabled disk $n of $CPUS" &      done      wait      sleep .5      modprobe -r zram      ;;    *)      echo "Usage: `basename $0` (start | stop)"      exit 1      ;;  esac  

Next, execute these two commands:

sudo chmod +x /etc/init.d/zram  sudo /etc/init.d/zram start  

Finally, to add zram at startup:

sudo update-rc.d zram defaults  

Done.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »