Raspberry Pi Performance: Add ZRAM and these Kernel Parameters

Originally published at: Raspberry Pi Performance: Add ZRAM and these Kernel Parameters

Previously, I published a Pinebook Pro review article on this blog. Similar to the Pinebook Pro, the Raspberry Pi and, more recently, the Raspberry Pi 4 are also ARM-based. With good results, I’ve applied some of the optimizations mentioned in that previous article to the Raspberry Pi 4. I wanted to share these tweaks and…


I have added this to Pi 3 and Pi 4 devices and this just makes the user experience more snappy. It helps when you are doing desktop browsing and also helps when you are running services such as Plex for media serving.


1 Like

Welcome to the community forums and thanks for taking the time to confirm results with your setups.

Ubuntu 22.04 is supposed to have zswap correctly enabled but it is missing the configuration to enable the kernel modules specifically for (. I sent in the bug report 2 months ago and there is a work around!

Into Bash/Fish/ZSH:

$ sudo -i
$ echo zstd >> /etc/initramfs-tools/modules
$ echo z3fold >> /etc/initramfs-tools/modules
$ update-initramfs -u

Then reboot, and you should now have the real-time zstd compression algorithm and the z3fold pool for zswap as well. ZSwap could be benificial for the Pi due to the speed overheads of the MicroSD card and so compression of data on the card could theoretically mean data can be loaded “faster” in which I’m referring to the fact that data can be read from the MicroSD and decompressed.

The bug I submitted is at Bug #1977764 “kernel modules “zstd” and “z3fold” missing.” : Bugs : ubuntu-settings package : Ubuntu

1 Like

Kudos. Thanks for adding this! I’m also soon to upgrade to 22.04 LTS.

Thank you for that great article!

I’ve first used the version included in the zram-tools package from the repository (I normally prefer software managed by package managers), but that one will only work if you don’t use any other zram devices that are started before the zramswap, because it uses hardcore zram0.

After switching to the github version it works well together with other zram usages.

My use-case how I ran into that problem is log2ram with enabled compression = zram disks (which I want to use to prevent wearing out my sd card too fast)

Wonderful! I applied this on an Orange Pi Zero running Armbian 23.02.2 Jammy it would freeze and lag despite having 150% set for zram with the distro. I was getting ready to buy something with more memory. Added the Kernel Paramaters and zwap enablement commands from @NothingConspicous in the post below and things look a lot better. So far everything is snappy and has not frozen since. Memory and Zswap usage have also gone down considerably.

1 Like

Nice to know the commands have helped :smiley: ! Newer versions of the Ubuntu Kernel should now be fixed thanks to the ubuntu team.

It was submitted as bug 1977764 and the fix has seemingly not been sent to Jammy (Aka Ubuntu Server and LTS 22.04.) Kinetic Kudu 22.10 has this patch however. So there was progress and has been patched for the most part. To think it has nearly been a year…

Spoke too soon, my Orange Pi Zero is frozen right now. Can still ping it but cannot connect to my service or ssh to the console.

HI @UncleBabyBilly

Welcome :handshake: I have not tried this on The Pi Zero, interesting. Glad you were able to get things going by adding @NothingConspicous line. Feel free to past your working config for anyone else reading this. The update is very much welcomed.

Ahh, I should have read forum thread. Keep us posted.

I’m trying to run a small python app in WebUI with a Orange Pi Zero, 256MB model, already raised my zram to 1GB to no avail. It still freezes and I can no longer SSH. Any variation to the parameters I can try?

 free -h
               total        used        free      shared  buff/cache   available
Mem:           238Mi       190Mi        10Mi       0.0Ki        37Mi        39Mi
Swap:          1.0Gi        72Mi       999Mi

sudo cat /proc/swaps

Filename                                Type            Size            Used            Priority
/dev/zram0                              partition       1097764         12800           5
1 Like

Freezes as in you have to reboot? Or freeze as in becomes very slow?

If you have to reboot, then also check your power supply. I’ve had many times where my board would lock up using a specific power supply and the issue solved by just switching to another.

They are very sensitive.

Freezes as it becomes very slow, nothing loads can’t even SSH into the os. Eventually it comes back performing normally I imagine cause the process forces an out of memory event. I occasionally can get the output of the oom and it’s definitely the app. I can still ping the device but can’t ssh or load the web ui. I believe ultimately I need something with more memory but was hoping to run this for a while.

For background I am using a python based app called ezbeq. I cannot post links but it’s easy to find. It runs a web interface. Nothing else is running on the Orange Pi Zero.

1 Like

Yes everything I read before this sentence says just that. Its just not enough for what you need.

At the same time is amazing to have challenges like this and get around them. Keep us posted.

It’s a little early to tell but I may have stumbled onto something and my memory usage is returning to the baseline after the webui is closed and I’ve been running solid for a few hours. Instead of starting the service with sudo service ezbeq start as the guide prescribes. Used sudo systemctl start ezbeq.service . Apparently there is a difference to these two commands in how much kernel access is granted. But my knowledge of this is very limited. Only time will tell if this was it.

Another issue that can cause a freeze is inadequate cooling, try to monitor the temperature, does it exceed 80-90 ish? I also have this problem on a Pi 3 B+ as well due to cooling.

1 Like

It’s under 60c. I have it near my home theater and theres a fan blowing on it. Right now 48c. It’s been stable since starting services as systemctl. Looks like it needed more access to the kernel. No crashes, slowdowns or out of memory errors since I’ve started it that way.

1 Like