Why and how to extend ZRAM on L5. A revolution for Librem 5 stability!

We REALLY have to extend the zram to get more RAM!!! A REVOLUTION I WAS WAITING FOR THE LIBREM 5!
After many tests, i could open:

  • 25 apps, opened quickly one after the other, including:
    • Heavy apps: Firefox, VPN, Waydroid, Freetube and whatch a video,
    • System resources
    • Dino
    • Terminal
    • and others
    • can do what i want
    • wifi on, charging the phone
      About 2 hours of continous testing
      CPU: 90-100% during a lot of time, and back to 40-50% afterwards
      Total MEMORY usage: 7-8 GB !!!
      GPU at 48°C, stable.

The limit seems to be above 8 GB of total used memory + heavy CPU task. I opened ALL my apps (and they all opened a window) and after some minutes, the system lagged strong and got frozen. I could not really get above 9GB of used memory.

With standard usage (Terminal, Settings, Surfshark VPN, Dino, Firefox (editing posts), Secrets, Telegram, Waydroid (still fluid, with Conversation, Telegram), Freetube (watching a video), Maps). It stays fully fluid. Temp is 45°C, Memory at 6-7GB. It is a dream.

==> Little lags sometimes, NO FREEZE, NO CRASH, has always time to close apps if it gets lagging too much,). IT IS A REVOLUTION!

In the past, after opening 4-5 apps (firefox, waydroid, dino, freetube, vpn), I got system crash (frozen screen, and heavy hot phone) after some minutes, making for me waiting for updates or limited usage that would make the phone daily usable for me. With this setting, if it gets lazy, lagging, i always have time to close some apps and continue my work.

Amazing!

Look at the swap: 13.3GB!
What i did is: set zram at 13.3 GB with zram-fraction=4.5 (6 works also) and no limit of max size (see below) just to see what happens.

Here are two ways to do it simply:

  1. Preferred way

Source How to resize ZRAM (compressed swap) managed by systemd/zram-generator | Ctrl blog

  • Copy this script in a file your_script_path
#!/bin/sh
sudo tee /usr/lib/systemd/zram-generator.conf.d/librem5.conf <<EOT 
[zram0]
zram-fraction = 2
max-zram-size = none
EOT
sudo systemctl restart systemd-zram-setup@zram0
  1. Alternative way (you don’t need both!)
  • your_script_path can also contain:
#!/bin/sh
sudo swapoff /dev/zram0
sudo zramctl --reset /dev/zram0
sudo zramctl --find --size 5G
sudo mkswap /dev/zram0
sudo swapon /dev/zram0
sudo systemctl restart systemd-zram-setup@zram0
  1. Finish
  • Run the script
sudo bash your_script_path
  • check
    swapon

NB1:# zram-fraction = 2 (zram0=5-6GB) is enough. More is ok but brings nothing. The cpu is then the limit.
zram-fraction accepts decimal number, and seems unlimited (i tried 6 with no problems)

NB2: If you get trouble after restarting the service, reboot the device and run the script again immediately after login. If you have to much autostarting apps, they can busy the zram, making it not usable by restarting the systemd service, so disable them before reboot.

  1. In order to make this persistent in case a system update overrides the changes made by the script,
    So, to make it persistent, even after system update:
  • create a service “at boot”, with this script (just complete ExecStart):
#!/bin/sh
serviceName=run_at_boot
sudo tee /etc/systemd/system/$serviceName.service > /dev/null <<EOT
[Unit]
Description=run_at_boot
	
[Service]
ExecStart=your_script_path_in_absolute_path

[Install]
WantedBy=multi-user.target
EOT
chmod +x your_script_path_in_absolute_path
sudo systemctl enable $serviceName
sudo systemctl status $serviceName
  • run it
    sudo your_script_path_in_absolute_path

PS: I am also using such a service to autobackup the system at boot on my sdcard and autowakeup from suspend to fetch my xmpp messages.

Enjoy!

It is now in the wiki: Tips & Tricks · Wiki · Librem5 / Librem 5 Community Wiki · GitLab

11 Likes

What is zram precisely? Is this a swap partition?

1 Like

Yes. It is like a swap fille or partition. It works like a swap partition. It is installed by default on the L5 but it is only 1.4G. I had several lags, frozen screen, crashes before i did that.

1 Like

Thanks for the tip! I’ve added these instructions to the Librem 5 community wiki: https://source.puri.sm/Librem5/community-wiki/-/wikis/Tips%20&%20Tricks#resize-zram

1 Like

I think ZRAM is part of RAM, while swap is part of storage device.

1 Like

Thanks, that is interesting.

1 Like

You might want to read this thread:

which discusses this. There is a lot of opinion in it, so you need to keep your critical thinking engaged while you form your own opinion. (I don’t endorse or dispute anything written in it.)

3 Likes

Thanks. Don’t forget to read my update to make it persistent after reboot…

2 Likes

You created the swap file in the RAM that is almost two times bigger than the RAM size! It is something really strange… Could you provide the output for free -h command at a maximum load?

1 Like

Yes but it works like a charm! I did not created a swap file, just used the default zram0.

free -h:

                          total       utilisé      libre     partagé tamp/cache   disponible
Mem:                      2,8Gi       2,1Gi        98Mi       208Mi       686Mi       487Mi
Partition d'échange:      4,2Gi       2,7Gi       1,6Gi
1 Like

You created the swap file in the RAM that is almost two times bigger than the RAM size! It is something really strange… Could you provide the output for free -h command at a maximum load?

I don’t think it’s that strange:
I have a Chromebook Tablet with 4GB Ram, and ChromeOS when that still ran it (it’s running postmarketOS now) was set up with 8GB of zram.

@Lionel : Well done! Regarding the config: I wonder if it would not be better to change the config that sets up zram by default to allow for more zram, instead of adding an additional service to change it on every boot. (My Librem 5 is not running PureOS right now, so I can’t look into it.)

3 Likes

Thanks for the detailed and clear update in wiki.

I tried yesterday with 5G of zram, and today with size-fraction = 1.5 RAM and max-size=none, with ram and zram usage at filled by 90%, my librem was still totally stable. I never had this experience before. It is really making it daily usable for me now ! It is day and night difference.

Could everyone report here his experience in order to make later a PR on the purism gitlab, so that new users make a better first UX with L5?

2 Likes

Great news. I was authorized to make a PR to make the change in the default pureos version for the librem 5!

5 Likes

Should be

sudo swapoff /dev/zram0
3 Likes

I tried doing the more permanent solution but it didn’t seem to like something about this setting it up as a service. It actually couldn’t find the service because instead of run_at_boot it was looking for run_at_boot.service.

1 Like

I can confirm that extend ZRAM to 5 GB greatly improves stability, associated with the kernel fix solving my resume from suspend issue, it really does my L5 daily drivable

3 Likes

I ended up just using the zram-generator.conf method, that seems to work, but wondering about the best values to choose.

So the max-zram-size just constrains it to not exceed that amount? If you leave it blank it defaults to 4096? And then the fraction is the fraction of the the max-zram-size?

1 Like

Best values are described in my original post:

zram-fraction = 2
max-zram-size = none

value 2 corresponds to 2*2.8G (Hardware RAM) = 5.6GB available in zram
So 2.8 + 5.6 = 8.4G of total memory.
More is useless after my tests (i tried tilll fraction 6) , because of the cpu limit if too much apps and work is running…
NB: It does not reduce free space on the disk.

PS: PR for the default pureos-librem5 is done, just waiting for merging by the admin’s team.

6 Likes

Instead of editing /usr/lib/systemd/zram-generator.conf.d/librem5.conf, create a new file /etc/systemd/zram-generator.conf.d/librem5.conf. Like with many systemd things, files in /etc are overriding their counterparts in /usr/lib.

5 Likes

How is your solution different from what Kyle Rankin describes here: My First Year of Librem 5 Convergence – Purism ?

3 Likes