kadams2929
Posts: 31
Joined: Sat Aug 25, 2012 2:32 am

How to enable zram on Raspbian Wheezy?

Fri Oct 05, 2012 1:50 am

Does anyone have a guide to enable zram on Raspbian Wheezy?

I followed the instructions exactly on this page: http://www.extremeshok.com/blog/tuning/ ... ng-memory/

During the reboot, the Pi returned:

[FAIL] startpar: services returned failure: zram ... failed!

I've attempted to run this with both a 128 split and a 224 split.

Wendo
Posts: 142
Joined: Sun Jun 10, 2012 8:27 pm

Re: How to enable zram on Raspbian Wheezy?

Fri Oct 05, 2012 8:27 am

The easiest way to find out whats going wrong would be to just run the commands one at a time in the start section of the file you create and see which one fails and why

kadams2929
Posts: 31
Joined: Sat Aug 25, 2012 2:32 am

Re: How to enable zram on Raspbian Wheezy?

Fri Oct 05, 2012 1:57 pm

That my friend is excellent advice and I will do just that.

Is anyone else on the Forum implementing zram memory compression on Raspbian Wheezy? Any performance benefits to be gained should be explored.

kadams2929
Posts: 31
Joined: Sat Aug 25, 2012 2:32 am

Re: How to enable zram on Raspbian Wheezy?

Fri Oct 05, 2012 3:43 pm

Another example of zram memory compression: http://forums.debian.net/viewtopic.php?t=77627

Could someone be so kind to try this and post your results/performance? :)

Compressed Memory Swap

1. First log into a root terminal. To check if you have the zram module available and load it run:
modprobe zram

2. Next create the device. In this case 50mb.
echo $((50*1024*1024)) > /sys/block/zram0/disksize

3. Then you have to make the compressed memory device into a swap and mount it as higher priority than other swap devices.
mkswap /dev/zram0
swapon -p 10 /dev/zram0

4. You can check if it works by running:
swapon -s

If it works the output should look like this:
Filename Type Size Used Priority
/dev/sda1 partition 2928636 0 -1
/dev/zram0 partition 51196 23924 10

5. In order to have this persistant upon reboots I just add the commands to /etc/rc.local such as this:
modprobe zram &&
echo $((50*1024*1024)) > /sys/block/zram0/disksize &&
mkswap /dev/zram0 &&
swapon -p 10 /dev/zram0 &&
exit 0

kadams2929
Posts: 31
Joined: Sat Aug 25, 2012 2:32 am

Re: How to enable zram on Raspbian Wheezy?

Sat Oct 06, 2012 3:36 am

Using Steps 1-5 works! Information gets written to the compressed zram swap file before being written to disk. I'm going to do some comparison testing, but up front, I'm inclined to keep the zram swap file.

User avatar
jackokring
Posts: 815
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: How to enable zram on Raspbian Wheezy?

Sun Oct 07, 2012 10:03 pm

A good first disk size to use is about half your memory split. So if your on 128/128 then an initial zram of 64*1024*1024 is fine. If you make it too small you'll not get much benefit of the fast disk simulation, and if you make it too big and use a lot of already compressed files and have many file buffers of these, it will actually slow your pi.

The reason it works is the 64MB disk is compressed to round about 32MB or less on general user programs and data. This has the effect of freeing over 32MB of memory on average. There is the slight time penalty of decompressing some infrequently used parts of programs before use, and compressing the parts on loading. But the extra 32MB is useful for preventing an early swap to SD card.

If you use a 128MB zram disk, then on average 64MB will be extra memory freed, but the problem of difficult to compress data filling your zram disk will cause a larger swap to SD overhead. Someone will provide net productivity benchmarks, but I find the gradual slowing effect, instead of a swap to SD stall to be the best effect. I set 64MB zram, and kept the default CPU/GPU split, and have seen no reason to change yet.
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

richard77
Posts: 12
Joined: Fri Oct 28, 2011 7:35 pm

Re: How to enable zram on Raspbian Wheezy?

Wed Oct 10, 2012 8:00 pm

It is worth to point out that it is NOT possible to set the amount of memory to be used by zram, only the disk size, i.e. the amount of UNcompressed data to store.

As jackokring says, conservative settings have to be used, to avoid stalling in case of low compression ratios.
Also note that strange things can happens at shutdown, if not enough memory can be freed to deactivate swap and zram.

It is possible to used multiple zram devices (actually it is the recommended setup for multicore pcs), so it could theoretically possible to create 2 or 3 devices, with some daemon dynamically (de)activating the 2nd and 3rd according to real compression ratios [I'm not recommending such a kind of setup, I never tried it and I'm doubtful of its real efficiency]

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 14 guests