Ubuntu / Linux news and application reviews.

While trying to optimize the elementary OS performance, Sergey Davidoff stumbled upon a project called compcache that creates a RAM based block device which acts as a swap disk, but is compressed and stored in memory instead of swap disk (which is slow), allowing very fast I/O and increasing the amount of memory available before the system starts swapping to disk. compcache was later re-written under the name zRam and is now integrated into the Linux kernel.

I decided to give it a try, and the result on my desktop with a quad-core CPU and 2Gb of RAM was fantastic: instead of freezing after running out of RAM, the system worked like nothing happened. I didn't notice any difference at all. It looked just like adding more RAM! Surprisingly, I got almost the same results on a 6-year-old laptop with Pentium M and 1Gb of RAM! So, I've improved the script to automatically adapt to the amount of memory in the system and automatically scale across several CPUs or CPU cores, packaged it in .deb and uploaded to PPA.

- Sergey Davidoff

Sergey also mentions that the only thing that prevents this from being enabled by default in elementary OS Luna for now is the existence of Atom netbooks with fast SSDs for which he doesn't know if this would be useful or not.


This is especially useful for netbooks, old computers (or computers that don't have too much RAM), virtualization or embedded devices but of course, you can use it on any computer.


To install Sergey's script in Ubuntu 11.04 or 11.10, use the following commands:
sudo add-apt-repository ppa:shnatsel/zram
sudo apt-get update
sudo apt-get install zramswap-enabler

The script should work with Linux kernel 2.6.37.1+.

Update: there is now a zram-config package available in the official Ubuntu 12.04 and newer repositories, which does the same thing. Install it using:
sudo apt-get install zram-config

If you're not using Ubuntu, you can download the script from HERE or get the source from BZR. This is an Upstart script so you need to place the "zramswap.conf" file under /etc/init and then start it using "sudo start zramswap". Please note that Fedora 15 has replaced upstart with systemd.


Update:
  • For Fedora 15+ (which uses systemd instead of upstart), see: Enable Zram in Fedora
  • For Arch Linux, see THIS comment (script converted to rc.d).


More about compressed caching for Linux:

Many thanks to Sergey for the tip and all the info!