Improve Your Librem 5's Performance (with this one weird trick)

Raspberry Pi is really not comparable. The µSD on Raspi has to do all the work that the eMMC does on the L5, including everything that goes in and out of RAM.

As the OP explains and IrvineWade concurs (I believe), rapid swapping in and out of RAM will still use the zRAM on the L5. He [EDIT: “he” referring only to the OP and definitely not including IrvineWade] presents the case for supplementing the zRAM with a larger but slower swap space. He and I just propose different ways of doing this, and I have given reasons why some users might be better served by a swap partition on the µSD.

Personally, I am a very light user of the L5 and doubt that my swap partition will make any noticeable difference to its operation. However, it does no harm, and µSD storage is cheap.

The other big difference is that the one µSD on Raspi is the only persistent storage, holding the OS as well as all your media. If it wears out, you no longer have a computer. If the µSD on the L5 stops working, all you lose is the 3000 videos of your dog catching a frisby, plus the swap space that your device never used to have in the first place. There is even a question whether deterioration of the swap partition would cause any loss at all of the media in the FAT partition.

If the swap partition doesn’t seem to be working any longer after a year or two, another swap partition can be carved out of the FAT and the /etc/fstab pointed to the new UUID instead. Alternatively, you might buy a new µSD once in a while.

3 Likes

I thought that the Micro-SD in the L5 only works with a transfer-rate of approx 20MB/sec ?

2 Likes

That’s what makes it slower than zRAM, as OP and I have said.

2 Likes

Hmmmmh, it would it make VERY slow if my information is correct. Swap-Out for 256MB RAM will last 15 seconds?
Has anybody tested this configuration with swap on a micro SD and can report his experiences and impressions?

1 Like

But perform periodic backups, of course, or clone it.

BTW, Raspberry Pi OS makes it super easy to clone your installation using its built-in SD Card Copier and a µSD card reader/writer.

2 Likes

Hey, sorry for the misunderstanding. As others have mentioned, the “clickbait” language was absolutely meant as a joke.

6 Likes

How’s your experience swapping to SD card so far? Personally I would be very concerned about the relative speed and reliability comparing SD with onboard MMC.

I think the SD card reader on the Librem 5 is actually connected via USB, which could impact both speed and reliability pretty significantly.

2 Likes

This is something I had previously done on my L5 to assist in performance (and overheating) as well as stability issues (especially when running WayDroid in conjunction with local apps). Tweaks and optimizations such as these would (IMO) be helpful to incorporate into the default build configuration for the L5.

For reference, this public L5 OS-issues repository:

This is where general OS issues will be tracked for the Librem 5 project. It is a catch-all for issues that do not have a place in specific application/project repositories or Apps_issues.

The community is certainly welcome to post feature requests and bug reports there.

In the meantime, I have created an issue to account for this topic. You are all welcome to expand upon the conversation in this ticket, work with the Purism development team to publish a MR, etc:

3 Likes

My experience is not a useful test, because I am a very light user of L5 and seldom have anything in swap. I’ll try to take note of whether there is any reduction in overheating since setting up the swap partition. (JCS suggests that a swap space might reduce overheating, a problem that I have had in browsing certain websites.)

[EDIT] In your first post, you suggested (correctly, I believe) that some readers should not be using dd and other powerful commands on their L5. Some replies were from users who did not feel they had any spare room for a swap space in their eMMC. My aim was to find an alternative for those two groups of users. You might be right that this alternative is not a particularly practical one.

1 Like

I haven’t exactly experienced that.

I have two Pi devices that are on 24x7, and have been for some years, one of them almost a decade. (Actually the newer one now runs off eMMC - but I did that in an unsuccessful attempt to get better performance, not because of any issues of reliability - and it ran off µSD card for a few years before that.)

I have not experienced any outright card failure. I have experienced file system corruption after power failure - and then have to restore from backup.

That by itself would make me wary of putting anything important on SD card. So I guess I am agreeing with the spirit of your post, if not the detail.

No, Irvine Wade does not occur.

I won’t be rushing to put any real swap for the Librem 5 on either eMMC (very much opposed) or µSD card (wary, and it’s sloooooowwwww). However the point of actually owning your hardware is that you are free to do with it what you want.

All I have on the µSD card at the moment is the metaphorical “3000 videos of my dog catching a frisbee” so it wouldn’t be a drama if the card died. That’s all just synched from the server. So if the card fails, I could just buy a new card, resynch it, recreate swap, and off I go.

However I would be a little concerned if there were undetected media failure - since that will corrupt memory and thereby corrupt other things. On the other hand, detected but uncorrected media failure could result in a hang.

You get that much? :wink:

This whole topic is only useful if your real memory usage is getting up towards the amount of RAM installed (3GB on the standard Librem 5).

It is.


Random alternative suggestion … use a USB flash drive as (secondary) swap.

My thinking is that a docked scenario is the more likely scenario when my RAM usage will be high … and in a docked scenario I can throw a flash drive onto the dock. (In that case though, that swap should not be enabled by default, only when present and entering docked mode - and it would make it trickier to exit docked mode).

Maybe.

2 Likes

My apologies for this. When you wrote, “I believe that was addressed in the OP,” I took your “that” to mean the question of excessive wear on the eMMC. Apparently I misunderstood your sentence. Sorry again.

[EDIT: Corrected a quotation: “believe” instead of “thought”]

1 Like

No drama. I just meant that the OP is aware of the potential for excessive wear and that he has expressed his opinion on it in the first post.

2 Likes

Hey and welcome!

Did someone try writeback with zram yet? I didn’t get around to it and I didn’t have any need so far…

1 Like

Hello. I must have done something wrong in trying to install this because my fstab file soes not have any “/swap” files.

Here is what my /etc/fstab file shows:

proc /proc proc defaults 0 0
UUID=442eff79-a91c-42ef-b49b-c991832c0419 / ext4 errors=remount-ro 0 1
UUID=55b6447c-bfc3-42b0-99b8-10b5cf65b47c /boot ext2 errors=remount-ro 0 2

I installed something but I am not sure what. Any help would be most appreciated. Thank you!

2 Likes

If it helps, I had created a helper script to turn a rootfs swapfile on and off:

A couple deviations from the guidance in this thread:

  • I use fallocate rather than dd to allocate disk space for the swapfile to save time, as the data will be quickly overwritten, anyway.
  • I use the nofail flag in /etc/fstab to allow booting in case the swapfile is moved/deleted for any reason.
8 Likes

Did you create a root shell and then run all the commands in that shell (and then type exit)?

What will not work is to prefix each command with sudo - in particular the command that updates
/etc/fstab will not work. This is a well-known Linux annoyance.

The correct hackaround if you want to prefix each command with sudo is, for that one command in the sequence of commands, to replace this command

echo '/swapfile none swap sw 0 0' >>/etc/fstab

with this command

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

3 Likes

I can’t thank you enough . I m using waydroid and swap was always 99 percent. I was getting desperate . Now it’s max 40 percent.

A probably silly question . Does this cause any battery drain or increased CPU usage ?

@alexmarkley

1 Like

Not sure, but it does expend eMMC resources:

1 Like

Yes i have read the op post , just wondering why this happens. I mean there is already a swap file , we are just increasing the size of the swap file

2 Likes

PureOS’s default behavior is to use only zram for swap. This simply takes uncompressed pages out of RAM and compresses them… into RAM. This is not sufficient on the Librem 5 because the total amount of RAM is too small for non-trivial use cases, and the process of storing compressed pages in RAM uses up RAM.

So my reasoning was, adding a “real” swap file will reduce some of the pressure on the RAM more than what zram can accomplish alone.

As for battery drain, you should notice less battery drain with a swap file. The reason for this is because, if the system is under a lot of memory pressure, it will waste a lot of time compressing pages (into zram) that it pulled out of zram moments ago, and then turning around and immediately doing the reverse.

This state (pushing pages into and out of swap constantly) is a well known issue. It’s called thrashing, and it’s a sure fire way to kill your battery (if it doesn’t crash your phone outright): Thrashing (computer science) - Wikipedia

4 Likes