My Thoughts

Notes, code, and reflections from my thoughts

Zram on Raspberry Pi

2026-08-22 7 min read Raspberry Pi Troubleshooting

This is a discussion on ZRAM on the Raspberry Pi. Before I enter into this discussion, I have personally used ZRAM for quite a while. I do not remember when it first came onto my radar. I have a few Raspberry Pi SBC devices.

My earliest one is a Raspberry Pi B, which I purchased in 2012. I ran this with a 4 GB SD card and the Raspberry Pi Raspbian OS. This was a 32-bit Debian OS as the original Raspberry Pi ran on a 32-bit SOC. This unit had a single core processor and no wifi built into the single board computer. I plugged an ethernet network cable between my router and my Raspberry Pi. I still have this unit, but I no longer maintain it as a running system.

Later on, I purchased a Raspberry Pi 3B+. This was a big upgrade with the built-in wifi, and four processing cores.

I purchased a number of Raspberry Pi Zero 2W units. These were fun because I could buy them cheaper than the Raspberry Pi 4 units, even though it was less powerful. I ended up purchasing six of these. This was also during COVID-19 when home shooling and home working computer demand pushed computer prices much higher.

Later, I purchased a Raspberry Pi 5 with 4 GB RAM.

So, somewhere I started using ZRAM along the way, on my earlier units, as limited RAM presented its own challenges.

(As of the publication date of this article, I am running this site on a Raspberry Pi Zero 2W using ZRAM.)

ZRAM is available in the apt repository. I am going to look at what I have installed

username@raspberrypi:~ $ apt list | grep -i zram

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

librust-zram-generator-dev/stable 1.2.1-2 arm64
librust-zram-generator-dev/stable 1.2.1-2 armhf
systemd-zram-generator/stable,now 1.2.1-2 arm64 [installed,automatic]
systemd-zram-generator/stable 1.2.1-2 armhf
zram-tools/stable,stable 0.3.7-1 all

I see that the package systemd-zram-generator (64-bit) is what is running on this system.

So, how did I install this? Well on this system, I installed ZRAM through Pi-Apps to install More RAM. You can use Pi-Apps from the command line without having the GUI installed in Raspberry Pi OS. However before I used Pi-Apps for installing ZRAM, I had created documents for this.

I used to use instructions from Using zram with the Raspberry Pi - Pi My Life Up , I do not know how this compares with the method used in Pi-Apps.

Why am I telling you all of this?

I have a script that I have named as image-backup.sh and it sits in my ~/bin/image-backup.sh folder. This script runs via cron to take a full-image backup of my system. On a 512 MB board, reading through thousands of block files forces the Linux kernel to allocate almost all available physical memory to file system caching (buff/cache).

Under normal circumstances, Linux drops or squeezes these memory caches as programs demand RAM. However, checking systemctl revealed an unexpected dynamic at play:

username@raspberrypi:~ $ systemctl list-timers | grep zram
zram-flush.timer    zram-flush.service
rpi-zram-writeback.timer rpi-zram-writeback.service

When installing ZRAM using automated helpers, background helper timers are often enabled by default. In this case, zram-flush.timer was configured to fire every 3 to 5 minutes to flush dirty compressed pages out of memory and write them back to physical storage (the MicroSD card).

When the backup job triggered heavy disk reads, a vicious loop occurred.

  1. Memory Compression: The backup process filled physical RAM, forcing active background processes into ZRAM swap.
  2. Timer Interruption: The zram-flush.timer fired while the backup was actively reading/writing.
  3. Storage Thrashing: ZRAM attempted to compress pages and flush them down to the SD card at the exact moment the backup script was saturating the storage bus.

This sounds like exactly what I did not need. I have a server which is handling a static-content management system, and a full system backup on a schedule. The full system backup does not need this. The result was that I found a system that became unresponsive to ssh and was no longer serving html.

On low-memory single-board computers, ZRAM works best when it stays strictly in physical memory as a fast, volatile buffer. Writing compressed swap pages to an SD card defeats the purpose of memory compression and destroys flash storage endurance.

Disabling the background flush timer immediately resolved the issue:

sudo systemctl stop zram-flush.timer
sudo systemctl disable zram-flush.timer

Now, the strange part about this is that I do not know if this was a problem before. I have been working with Raspberry Pi computers for well over a decade. Symptoms would include being unable to ssh into my system, a web server that becomes unresponsive, possibly a system that would crash on a major system upgrade to the point that I need to rebuild the entire system.

Where have I noticed this before? On my lower end Raspberry Pi computers, especially on my Raspberry Pi Zero 2W systems.

My Raspberry Pi 5 computer is running 24/7 and I have had very little trouble with it.

In Conclusion

I am making a case to support what I have surmised as the problem and the fix. However, I cannot assume that this is all good and true. I am throwing this out there as a potential issue with Raspberry Pi systems running ZRAM.

Post Conclusion

I went back to my Pi-Apps on my Raspberry Pi 5 system by loading it over ssh into my development laptop. I saw that there were updates and I saw that More RAM was one of them. I ran the updates. Then I looked at my system again.

username@raspberrypi5:~ $ zramctl
NAME       ALGORITHM DISKSIZE   DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd         15.8G 258.8M 43.3K  608K         /zram
/dev/zram4 zstd            4G    16K   59B   48K         [SWAP]
/dev/zram3 zstd            4G    16K   59B   48K         [SWAP]
/dev/zram2 zstd            4G    16K   59B   48K         [SWAP]
/dev/zram1 zstd            4G    16K   59B   48K         [SWAP]

Ok, I cannot remember if this is what I am looking for. Let me check something else.

username@raspberrypi5:~ $ systemctl list-timers | grep zram
Sun 2026-08-23 01:10:01 ADT 3min 26s Sun 2026-08-23 01:05:01 ADT 1min 33s ago zram-flush.timer             zram-flush.service
Sun 2026-08-23 16:06:55 ADT      15h Sat 2026-08-22 16:06:55 ADT       8h ago rpi-zram-writeback.timer     rpi-zram-writeback.service

Oh no! zram-flush.timer is back like a bad dog!

This tells me that the zram-flush.timer is installed by Pi-Apps, which is why I do not recognize it. Let’s stop this puppy.

username@raspberrypi5:~ $ sudo systemctl stop zram-flush.timer
username@raspberrypi5:~ $ sudo systemctl disable zram-flush.timer

Good! That worked! Now I know that updating Pi-Apps is going to send this back into play. How to stop this in the future?

username@raspberrypi5:~ $ sudo systemctl mask zram-flush.timer
Failed to mask unit: File '/etc/systemd/system/zram-flush.timer' already exists

Ok, now I know that Pi-Apps has hooked this up like a bad computer virus. Let me try this:

username@raspberrypi5:~ $ sudo systemctl stop zram-flush.timer
username@raspberrypi5:~ $ sudo rm /etc/systemd/system/zram-flush.timer
username@raspberrypi5:~ $ sudo systemctl daemon-reload
username@raspberrypi5:~ $ sudo systemctl mask zram-flush.timer
Unit zram-flush.timer does not exist, proceeding anyway.
Created symlink '/etc/systemd/system/zram-flush.timer' -> '/dev/null'.

That looks like I might have nailed it.

I hope you have enjoyed following me on a extended troubleshooting to find a root cause of my system problems. I can see now that this zram-flush.timer is probably a new iteration and not something I have worked with before. I do not have any peer review on this so far, and I have no disrespect for where this may have come from. But rather than writing a boring Just Do This article, I wanted to explore this issue in a more meaningful way.

Thank you for reading my article.

And I Thought It Was Over

I look back at my Raspberry Pi Zero 2W server. I run this command ONE LAST TIME.

username@raspberrypi:~ $ systemctl list-timers | grep zram
Sun 2026-08-23 16:19:54 ADT      14h Sat 2026-08-22 16:19:54 ADT       9h ago rpi-zram-writeback.timer     rpi-zram-writeback.service

My heart races and panic sets in. What is this now? I did a look up and I came to these conclusions:

zram-flush-timer (Third-Party Rogue)

  • Origin: Pi-Apps More RAM script
  • Frequency: Fires every three to five minutes
  • Behaviour: Forces memory to flush storage causing issues on active Raspberry Pi Zero 2W server
  • Fix: Kill it

rpi-zram-writeback.timer (The Official Raspberry Pi OS Service)

  • Origin: Official Raspberry Pi OS package ( rpi-swap, systemd-zram-generator) Raspberry Pi Forums
  • Frequency: Once every 24 hours
  • Behaviour: Hybrid memory approach
  • Fix: Leave it alone.