Compressed swap RAM

11th February 2013 (11 years ago)

I've been trying zram recently and have found it keeps my laptop very responsive when I would otherwise run out of physical RAM. It seems distributions like Ubuntu are considering turning this on by default but the the support already exists in most recent kernels and there are scripts (and a package in Ubuntu) to set it up easily.

Zram is the successor to compcache and uses LZO for compression by default, making use of the processor to get faster throughput than writing/reading raw memory data to/from RAM/hard-disk/SSD. I use it on my laptop at the moment but figure it could be useful on virtual servers where ram pricing is high.

To install in Ubuntu:

sudo aptitude install zram-config`

(or if you don't use aptitude:)

`sudo apt-get install zram-config`

If zram has been started successfully you should be able to run...

cat /proc/swaps

...and you should see a zram line for each core of your CPUs to get maximum speed.

Filename                Type        Size    Used    Priority
/dev/dm-0                               partition    7970812    71048    -1
/dev/zram0                              partition    457988    0    5
/dev/zram1                              partition    457988    0    5
/dev/zram2                              partition    457988    0    5
/dev/zram3                              partition    457988    0    5</code>

By default zram-config creates an area in swap that is half the size of your physical RAM. This can be adjusted by editing /etc/init/zram-config.conf and restarting with sudo service zram-config restart.