Topic: Zram: A good idea?

Hi, I saw this post on webupd8 and thought I'd give it chance:
Increased performance in linux with zram. I downloaded the deb but here's the thing:

it requires I remove live-config, live-config-sysvinit, live-initramfs and sysvinit. Also install libnih-dbus1, libnih1 & upstart. Here's my question:

Is this a good idea? I don't know how much I need those packages, or if this replaces them just fine. Zram seems like a great project (it's covered on the #! forums here as well, but that's with Ubuntu in '09 so I figured the current #! (which is what I have) might work differently), but if it's going to break me then I don't want to do it.

So does anyone know if this is a good idea? I am all ears.

Leave the gun. Take the cannoli.

Re: Zram: A good idea?

mahatman2 wrote:

Is this a good idea? I don't know how much I need those packages, or if this replaces them just fine.

It's a great idea, if you're very adventurous, or suicidal. init is the first proces the kernel starts, and is responsible for starting everything else. Every script in /etc/init.d is configured to run with sysvinit, and while upstart (Ubuntu's replacement for sysvinit in Debian) has compatibility with the sysvinit config, it's not quite so straightforward. You need to know really well what you're doing, basically. Also, I'm not sure the version of the program is geared to Debian's upstart package.

Last edited by el_koraco (2011-10-02 23:51:41)

Re: Zram: A good idea?

^ Thanks for that info! I am adventurous, but not quite suicidal tongue SO since I am in school right now (for which a computer is very important tongue ), I think I'll hold off testing this package until later....maybe much later!

Thanks again for the quick feedback! smile

Last edited by mahatman2 (2011-10-03 04:19:00)

Leave the gun. Take the cannoli.

Re: Zram: A good idea?

I managed to get ZRAM working on Wheezy with Liquorix kernel 3.0.0-4.dmz.2

***** EDIT - to make this work with kernels 3.1 & higher line 26 of this script needs to be: ******

modprobe zram zram_num_devices=$num_cpus

(zram_num_devices as the modprobe parameter NOT num_devices)

RAM usage seems to be a bit lower after booting & virtualbox is a lot more responsive while lots of other applications are running, no longer freezing with too many other things running. Office XP & 2007 open faster than before, larger applications feel snappier.

To check if your kernel includes the ZRAM Module:

modprobe -nv zram

If it does add the following in /etc/init.d/zram

#!/bin/bash
### BEGIN INIT INFO
# Provides: zram
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram
### END INIT INFO

start() {
    # get the number of CPUs
    num_cpus=$(grep -c processor /proc/cpuinfo)
    # if something goes wrong, assume we have 1
    [ "$num_cpus" != 0 ] || num_cpus=1

    # set decremented number of CPUs
    decr_num_cpus=$((num_cpus - 1))

    # get the amount of memory in the machine
    mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
    mem_total=$((mem_total_kb * 1024))

    # load dependency modules
    modprobe zram num_devices=$num_cpus

    # initialize the devices
    for i in $(seq 0 $decr_num_cpus); do
    echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize
    done

    # Creating swap filesystems
    for i in $(seq 0 $decr_num_cpus); do
    mkswap /dev/zram$i
    done

    # Switch the swaps on
    for i in $(seq 0 $decr_num_cpus); do
    swapon -p 100 /dev/zram$i
    done
}

stop() {
    # get the number of CPUs
    num_cpus=$(grep -c processor /proc/cpuinfo)

    # set decremented number of CPUs
    decr_num_cpus=$((num_cpus - 1))

    # Switching off swap
    for i in $(seq 0 $decr_num_cpus); do
    if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
    swapoff /dev/zram$i
    sleep 1
    fi
    done

    sleep 1
    rmmod zram
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 3
        start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        RETVAL=1
esac
exit $RETVAL

Make the script executable & add it to default run levels:

sudo chmod +x /etc/init.d/zram
sudo update-rc.d zram defaults

After booting verify the module is loaded with:

lsmod | grep zram

Last edited by tradetaxfree (2012-02-04 21:42:53)

Re: Zram: A good idea?

I really don't get the benefit of zRam or compcache. Instead of filling your swap with data, you put a compressed swap on ram?
But if you run without swap, you won't get any benefits unless you are tight on ram? Or if you run a system with swappiness set to 0.

Re: Zram: A good idea?

With 2 gig RAM I run without swap as it hardly ever got used. I also suspend to RAM rather than hibernate so I don't need a swap partition. I think the main benefit will come with running virtual machine(s). I've not found any disadvantages as yet & it's a simple tweak.

It will be interesting for SSD users also.

Re: Zram: A good idea?

@tradetaxfree: I found out why it wants to uninstall important things: I do not have zram on my kernel tongue

Well, that's one mystery solved!

Leave the gun. Take the cannoli.

Re: Zram: A good idea?

The deb you tried wanted to install upstart (canonical's init system which replaces legacy sysvinit on Ubuntu)

I looked at installing upstart but it seems systemd is superior to both sysvinit & upstart - I have got systemd working on Wheezy here

If you wanted to try ZRAM just install a Liquorix kernel.

Last edited by tradetaxfree (2011-10-04 15:27:20)

Re: Zram: A good idea?

If you want to use Zram with systemd

http://mystilleef.blogspot.com/2011/10/ … edora.html

Get Dropbox and an extra 250 mb http://db.tt/wAizqw0

Re: Zram: A good idea?

I'm the author of that script on WebUpd8 smile I wrote it for Upstart but somebody ported (an older version of) it to SysVinit, you can use that instead.
Also, systemd is not superior to upstart neither in boot speed (see http://www.phoronix.com/scan.php?page=a … amp;num=1) nor in architecture (see http://netsplit.com/2010/05/27/dependen … -launchd/)