CentOS 6.x / RHCE 6 / RedHat 6 zram compression ( compressed swap residing in ram / over allocating memory )

A successor to compcache, zram is fully integrated in the Linux kernel and uses lzo compression. Compress memory on the fly to reduce swapping.
Uses a small amount of cpu, however the reduced i/o usage more than makes up for this.

Install

Requirements

zram System Script
/etc/init.d/zram

Start zram at boot

Start zram at boot

Restart to apply

Checking

——-
zram Compression Stats:
——-
/dev/zram0: 5851.42% (4096 -> 70)
/dev/zram1: 5851.42% (4096 -> 70)
/dev/zram2: 5851.42% (4096 -> 70)
/dev/zram3: 5851.42% (4096 -> 70)
——-
SWAP Stats:
——-
/dev/zram0 partition 480572 0 100
/dev/zram1 partition 480572 0 100
/dev/zram2 partition 480572 0 100
/dev/zram3 partition 480572 0 100
——-
Memory Stats:
——-
total used free shared buffers cached
Mem: 1877 752 1124 0 9 182
Low: 1877 752 1124
High: 0 0 0
-/+ buffers/cache: 560 1316
Swap: 3925 0 3925
Total: 5802 752 5049

4 replies
  1. John Smits
    John Smits says:

    There is a typo in line 25 of the zram System Script: there shouldn’t be spaces around the “=” character, since that results in errors. In essence, it doesn’t apply the 50% rule, resulting in allocating all available memory. Not really a problem if the swapped pages are compressible, but a real nuisance if they’re not.

    Great script, really helps me out with virtual machines on relatively low ram. 🙂

    Reply
  2. el_es
    el_es says:

    Something happened to the status calculation (where is it supposed to take original size from ? and the printing calls are gone too), other than that, seems it’s working great

    Reply
  3. el_es
    el_es says:

    oops sorry don’t know what happened I pasted it … hope you can fix

    status() {
    ls /sys/block/zram* > /dev/null 2>&1 || exit 0
    echo -e “——-nzram Compression Stats:n——-”
    for i in /sys/block/zram*; do
    compr=$(< $i/compr_data_size)
    orig=$(< $i/orig_data_size)
    echo “$i: original $orig compressed $compr ratio $(($orig*100/$compr)):1 ”
    done
    echo -e “——-nSWAP Stats:n——-”
    swapon -s | grep zram
    echo -e “——-nMemory Stats:n——-”
    free -m -l -t
    }

    Hope this comes out better (blockquote instead of code tag)

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *