SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-10-02 23:10:52

mahatman2
#! Die Hard
From: Chattanooga TN
Registered: 2009-09-13
Posts: 550

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.


Punch all your friends.

Offline

Be excellent to each other!

#2 2011-10-02 23:50:39

el_koraco
#!/loony/bun
From: inside Ed
Registered: 2011-07-25
Posts: 4,749

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)

Offline

#3 2011-10-03 04:18:18

mahatman2
#! Die Hard
From: Chattanooga TN
Registered: 2009-09-13
Posts: 550

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)


Punch all your friends.

Offline

#4 2011-10-04 03:37:36

tradetaxfree
#! CrunchBanger
Registered: 2011-03-05
Posts: 123

Re: Zram: A good idea?

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

**(revised 200612 to allow a Factor % to be set on line 23 or in /etc/default/zram)**
**(revised 120712 to work with any 3.0+ kernel - see notes in script for building a kernel with zram support if it is missing from your kernel **

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
    last_cpu=$((num_cpus - 1))
    
    #default Factor % = 90 change this value here or create /etc/default/zram
    FACTOR=90
    #& put the above single line in /etc/default/zram with the value you want
    [ -f /etc/default/zram ] && source /etc/default/zram || true
    factor=$FACTOR # percentage

    # get the amount of memory in the machine
    memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
    mem_by_cpu=$(($memtotal/$num_cpus*$factor/100*1024))

    # load dependency modules
    # kernels 3.4 onwards
    if ! modprobe zram num_devices=$num_cpus; then
      # kernels 3.1 - 3.3
      modprobe zram zram_num_devices=$num_cpus        
    else
      echo -e "Your Kernel needs to be compiled with ZRAM support:" \
      "\n\nDevice Drivers --> Staging Drivers --> Compressed RAM block device support (M)" \
      "\nDevice Drivers --> Staging Drivers --> Dynamic compression of swap pages and clean pagecache pages (*)" \
      "\n\nThe Liquorix Kernel (http://liquorix.net) has ZRAM support built in."
      exit 1
    fi
    echo "zram devices probed successfully"
    
    # initialize the devices
    for i in $(seq 0 $last_cpu); do
    echo $mem_by_cpu > /sys/block/zram$i/disksize
    # Creating swap filesystems
    mkswap /dev/zram$i
    # Switch the swaps on
    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
    last_cpu=$((num_cpus - 1))

    # Switching off swap
    for i in $(seq 0 $last_cpu); 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

The latest version of the script will now always be on DropBox here

Last edited by tradetaxfree (2012-08-09 13:58:48)

Offline

#5 2011-10-04 12:00:53

GuruX
#! Die Hard
Registered: 2009-01-18
Posts: 527

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.

Offline

#6 2011-10-04 12:53:56

tradetaxfree
#! CrunchBanger
Registered: 2011-03-05
Posts: 123

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.

Offline

#7 2011-10-04 13:01:32

mahatman2
#! Die Hard
From: Chattanooga TN
Registered: 2009-09-13
Posts: 550

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!


Punch all your friends.

Offline

#8 2011-10-04 13:18:49

tradetaxfree
#! CrunchBanger
Registered: 2011-03-05
Posts: 123

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)

Offline

#9 2011-10-06 14:30:12

jeffreyC
#! Die Hard
Registered: 2010-09-02
Posts: 535

Re: Zram: A good idea?

If you want to use Zram with systemd

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


There's a reason you separate military and the police. One fights the enemies of the state, the other serves and protects the people. When the military becomes both, then the enemies of the state tend to become the people.

Offline

#10 2012-05-10 19:22:34

Shnatsel
New Member
Registered: 2012-05-09
Posts: 2

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 … _bp&num=1) nor in architecture (see http://netsplit.com/2010/05/27/dependen … -launchd/)

Offline

#11 2012-06-17 22:04:15

tradetaxfree
#! CrunchBanger
Registered: 2011-03-05
Posts: 123

Re: Zram: A good idea?

I've revised the zram script to work with any 3.0+ kernel.

Last edited by tradetaxfree (2012-07-12 17:20:48)

Offline

#12 2012-06-17 22:35:04

omns
#! wanderer
From: ~/
Registered: 2008-11-25
Posts: 5,131

Re: Zram: A good idea?

Moved to Help & Support smile

Offline

#13 2012-06-18 06:14:35

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: Zram: A good idea?

Yo dawg...

People really put their swap in the RAM to circumvent slow drives, which takes away free RAM which accelerates the need for swap? What exactly did I miss?


I'm so meta, even this acronym

Offline

#14 2012-06-18 10:42:11

tradetaxfree
#! CrunchBanger
Registered: 2011-03-05
Posts: 123

Re: Zram: A good idea?

If you use an SSD zram reduces disk writes therefore extending the life of the drive. Even without an SSD applications which use a lot a RAM load more quickly (virtual machines / Office Application Suites etc..)

zram is built into the 3.0 kernel & is a zero cost tweak.

(I don't actually use swap as I suspend rather than hibernate - with 2GB+ of RAM for me swap was hardly ever used)

Last edited by tradetaxfree (2012-06-18 10:44:48)

Offline

#15 2012-06-18 11:59:09

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: Zram: A good idea?

If I set the swappiness correctly, then the kernel won't swap until it needs to. It would swap earlier, as there is less ram because it is allocated to the zram. I am still not convinced that there is a real scenario for this, that goes beyond a misconfigured swappiness.


I'm so meta, even this acronym

Offline

#16 2012-09-03 22:22:26

nettlebay
New Member
Registered: 2012-09-03
Posts: 1

Re: Zram: A good idea?

:)Hello!
About the Tradetaxfree's script.
I use it without any problem on my Eeebox B-202 with Crunchbang  Waldorf installed. But is it possible to adapt it to ramzswap? Because my wife's Eeepc 700 has not Zram available but only ramzswap ( I prefer not to update the kernel now) .
Thanks in advance.

Offline

#17 2012-09-04 12:04:51

tradetaxfree
#! CrunchBanger
Registered: 2011-03-05
Posts: 123

Re: Zram: A good idea?

ZRAM supercedes ramzswap / compcache.

If "sudo modprobe zram" or the script gives errors - the simple way to get ZRAM working is just add the Liquorix Kernel Sources which have ZRAM support built in & install the Liquorix Kernel via Synaptic or APT.

Offline

#18 2012-09-14 03:52:47

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,855
Website

Re: Zram: A good idea?

Awebb wrote:

People really put their swap in the RAM to circumvent slow drives, which takes away free RAM which accelerates the need for swap? What exactly did I miss?

The swap data gets compressed. You effectively get a bit of extra RAM at the cost of some extra CPU activity. For some people it might be a good tradeoff. I'm just about to try it out as I've only got 500MB.


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#19 2012-09-14 04:21:32

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,855
Website

Re: Zram: A good idea?

To get some benefit with a virtualized machine, should this be done on the host or the guest, or both?

In my case, host has 1GB RAM and guest has been allocated 395 or so. The guest often starts swapping and really slows down, almost freezing sometimes. (apt-xapian-index is a major culprit.)

Last edited by johnraff (2012-09-14 04:24:03)


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#20 2012-09-14 07:43:30

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: Zram: A good idea?

As a side note, guests should not swap at all. They should be allocated enough RAM and the host should do the swapping. If you, for some reason, need swap space for a guest, I would create a seperate disk file on the host and put that in a tmpfs... if you have enough RAM that is.

Once RAM is compressed, it cannot be compressed any further by the same algorithm on the same quality level. Take a 1MB text file and compress it with bzip2 and then compress the archive with bzip2 again. All you will compress on the second run are the archive metadata.

I'd turn swap off for the guests anyway. I'd rather have the host do the swapping and I'd rather allocate too much ram to the guest. This was helpful in a few real life scenarios at least. There is no unique answer to that question. It all depends :-)


I'm so meta, even this acronym

Offline

#21 2012-09-14 12:48:11

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,855
Website

Re: Zram: A good idea?

@awebb thank you for that. It's only the last couple of months that I installed Virtualbox and started playing with virtualization. This machine doesn't really have enough resources to do it properly (1GB, 1GHz) but it's so useful that I want to try and get it sort of working somehow, even if slow. The guest (Waldorf) is only a testbed so it doesn't need to do any real work, but it does need to function. apt-xapian-index has been gobbling up all its memory and bringing the whole machine to a stop while the hard disk thrashes. neutral The same OS in a "real" install works fine.

Re swap on the guest - I just accepted Virtualbox's suggested setting of 384MB of RAM and didn't think about swap. I just assumed that the guest would swap out into its virtual hard disk if it ran out of RAM, but now I can't find any reference to swap for the guest in VB's help, or any settings for it. I guess your advice not to let guests swap is what VB does anyway.

Your point about trying to compress twice of course makes sense. The same reason you can't compress a .jpg file.

So if zram is any help, I guess it's for the host only.


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#22 2012-09-14 13:02:19

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: Zram: A good idea?

If you really want to defeat performance problems, do not use Virtualbox. Either bite the pear and get the free VMWare player or learn how to use qemu. This is, by the way, not motivated by asympathy for Oracle. Virtualbox just sucks, teaches you bad concepts and keps you away from really knowing anything about virtualization.


I'm so meta, even this acronym

Offline

#23 2012-09-14 13:39:15

tradetaxfree
#! CrunchBanger
Registered: 2011-03-05
Posts: 123

Re: Zram: A good idea?

I have also bitten the bullet & learnt KVM & no longer use Virtualbox (KVM is much faster)

In a little while I will also be posting a script that builds a Grsecurity kernel with AppArmor support.

Offline

#24 2012-09-14 15:25:20

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,855
Website

Re: Zram: A good idea?

Hmm OK you guys no more Virtualbox. Aah another hard road lies ahead...


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

Be excellent to each other!

#25 2012-09-14 15:53:01

el_koraco
#!/loony/bun
From: inside Ed
Registered: 2011-07-25
Posts: 4,749

Re: Zram: A good idea?

virt-manager is a graphical utility to handle most of the tasks. I haven't tried it, just browsed the docs, and it doesn't seem too inconvenient, no harder than LVM or NFS.

Last edited by el_koraco (2012-09-14 15:53:13)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo