I'm doing some OpenCV development on a Raspberry Pi 3, and I have found some information about using ZRAM on the Pi to try and boost its processing effectiveness. I know this isn't actually adding more RAM (since you can't just add more RAM without a physical addition), and it's more of a compression/swap file scheme.

This post has the best explanation I have seen so far, and explains that ZRAM is useful in some cases but not in others.

For my particular case, I am trying to run live OpenCV (Python) on a Raspberry Pi 3 B+ on a USB camera input. Would using ZRAM be helpful in my case? I would think an operation like this would be very CPU heavy, so it might be helpful.

  • @jsotola - I have done some, and yes I have googled it - I was trying to install OpenCV on my Pi, and have been reading conflicting things about whether or not swap space is helpful. Some say to increase the swap space in order to allow the installation, and others say that increasing swap space just slows things down. That's when I heard about ZRAM, and started researching it. Most of what I have found just says how to use it, but I don't fully understand what exactly it is doing. Is it just more swap space? Someone else said using ZRAM was overclocking, but I didn't think that was the case. Mar 21 '19 at 16:25
  • I did just find this post though: raspberrypi.stackexchange.com/questions/8053/… This seems to answer some of my questions. I may tailor my question to be more specific for my uses. Mar 21 '19 at 16:26
  • upvote (you did research and the question appears to be useful)
    – jsotola
    Mar 21 '19 at 18:05
  • don't forget that ZRAM has nothing to do with RPi specifically .... it is a linux kernel module ....... ZRAM appears to simply be a ramdisk filesystem that is compressed ...... it is entirely in memory, so it reduces available memory for running apps ..... it is like a zip file, so more data can be stored in the available space ...... the resulting filesystem can be used for storing files same as a regular disk or it can be used as swap space ...... any stored files will disappear at reboot, at reset or at powerfail
    – jsotola
    Mar 21 '19 at 18:13

You should gain no additional performance, but you may lose.

Since your application is a live machine vision app, you should be limited on the physical RAM of the Raspberry Pi and get the most out of the CPU, otherwise, you will face quite a performance impact.

In your case swap should ideally be just a place to store inactive processes, thus there is no need speeding them up with ZRAM. ZRAM can be helpful if you need to create a ramdisk so that you can read/write fast data from/to it, but I don't think that your application has such a dependency.

  • 1
    Even then it's use case is very specific since open files are cached in memory anyway if there is available space so the bottlneck happens at first read or if caches are purged to reclaim memory. Whatever access performance benefit can be had by simply explicitly loading your application data into memory when program starts, the compression does conserve space vs vanilla ramdisk
    – crasic
    Mar 22 '19 at 2:22
  • So ZRAM would be helpful if I was running multiple processes, instead of just the one OpenCV app? Mar 25 '19 at 0:45
  • No. Swap is useful in that case, because it may move inactive app data to the disk.
    – GramThanos
    Mar 25 '19 at 1:16
  • Could you possibly give a concrete example of when ZRAM might be helpful? I'm not sure I quite understand. Mar 26 '19 at 15:51
  • 1
    ZRAM can be used as swap or as ramdisk. As ramdisk: lets say you have more ram than you need, you can mount /tmp on ZRAM so that read and write on /tmp is fast (you will have some CPU load due to the compressing and decompressing). As swap: in plain words, it converts ram to compressed swap on the ram, it may be able to fit for example 500MB data to 400MB ram space at the cost of speed and CPU load, slower than normal ram, faster than disk swap.
    – GramThanos
    Mar 26 '19 at 17:35

Zram likes spare ticks as the compression even though light creates load. If ram is a problem and its forcing disk based swap then yes zram could help as your swap is mem based rather than flash based.

If you are just maxing out on cpu load then zram could actually just add a little more load. Don't use zram-config-0.5 as its an awefull implementation try https://github.com/StuartIanNaylor/zram-config

  • You forgot to mention your affiliation with that Github project (though it's obvious). I also find troubling that you berate someone else's implementation in favor of yours, while providing zero information as to why yours is better. Mar 26 '19 at 11:59
  • I don't quite understand what you mean by "Zram likes spare ticks as the compression even though light creates load". Could you elaborate? Mar 26 '19 at 15:49
  • LZO / LZ4 are extremely fast and low load compression algs, when you have av load you barely notice zram in operation. When you have intense load any extra cpu load just adds to the process queue. If you are maxed out on load then zram can be a negative, spare ticks which yeah is bad slang by me and its great as the minimal load increase will not be noticed. Mar 27 '19 at 5:07
  • @Dmitry Grigoryev your comment is as puzzling as yes its absolutely obvious to my affiliation. Check the bug reports on ubuntu with zram-config and the questions that they failed to answer. Zram-config is an extremely bad implementation that is even incorrect in name as all it does is some bad illogical swaps. Mar 27 '19 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.