January 12, 2014

Zram Compressed Swap

Zram (previously called compcache) can create RAM based block devices which act as swap disks. It is an experimental (staging) module of the Linux kernel since 3.2.

Pages swapped to these disks are compressed and stored in memory itself.

Compressing pages and keeping them in RAM virtually increases its capacity. It can therefore hold more pages of memory in the compressed swap than the amount of actual memory used. Typically it compresses to a 3:1 ratio. This allows more applications to fit in given amount of memory. It is much quicker than swapping to a hard drive. If a system often falls back to swap, this could improve responsiveness.

Installation is simple : open Terminal and copy/paste
sudo apt-get install zram-config

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  zram-config
.........
.........
Unpacking zram-config (from .../zram-config_0.1_all.deb) ...
Processing triggers for ureadahead ...
Setting up zram-config (0.1) ...
zram-config start/running

No need for any configuration or reboot....

To see if swap has been added :
free -m
or
swapon -s




The recommended amount of devices for swap is 1 per cpu core ( dev/zram[0-3] ).
Total amount is 1/2 of RAM size ( see also file /etc/init/zram-config.conf ).

I previously used a swapfile ( see here ), but replaced it with zram.

Links :
http://en.wikipedia.org/wiki/Zram
http://gionn.net/2012/03/11/zram-on-debian-ubuntu-for-memory-overcommitment/
http://stackoverflow.com/questions/18437205/difference-between-zram-and-zswap
http://unix.stackexchange.com/questions/99580/zswap-zram-zcache-desktop-usage-scenarios

4 comments:

  1. How can I remove the normal swap file?

    ReplyDelete
  2. Search for the entry of the swap file inside /etc/fstab and comment it ( put a # at the beginning of that line ).

    ReplyDelete
  3. should be used or not swappiness?

    ReplyDelete
    Replies
    1. cat /proc/sys/vm/swappiness shows 60 on my computer, which is default. You can read this : https://lists.launchpad.net/lubuntu-qa/msg03962.html

      Delete

Note: Only a member of this blog may post a comment.