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.
-
- Posts: 31
- Joined: Sat Aug 25, 2012 2:32 am
Re: How to enable zram on Raspbian Wheezy?
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
-
- Posts: 31
- Joined: Sat Aug 25, 2012 2:32 am
Re: How to enable zram on Raspbian Wheezy?
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.
Is anyone else on the Forum implementing zram memory compression on Raspbian Wheezy? Any performance benefits to be gained should be explored.
-
- Posts: 31
- Joined: Sat Aug 25, 2012 2:32 am
Re: How to enable zram on Raspbian Wheezy?
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
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
-
- Posts: 31
- Joined: Sat Aug 25, 2012 2:32 am
Re: How to enable zram on Raspbian Wheezy?
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.
- jackokring
- Posts: 818
- Joined: Tue Jul 31, 2012 8:27 am
- Location: London, UK
Re: How to enable zram on Raspbian Wheezy?
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.
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
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028
Re: How to enable zram on Raspbian Wheezy?
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]
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]