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

Thank you for the great technical article. I love learning new things. I have set this up and will give it a test drive. I may choose to undo this eventually because there isn’t much space on my internal storage to be using up 2 more gigs to swap space. My takeaway may be to keep an eye on memory usage and if it gets too high (over 80%) be sure to close apps I don’t need at this moment.

2 Likes

I opened a bunch of apps. (Usage, Nheko, Geary, Phone, Browser (several tabs open to car manufacturers), Tuba, Chatty, Evolution Calendar, Contacts, Weather, Pure Maps, Terminal, QModMaster, Watch Mate, VLC). Even with all this going on it seems the new swap space isn’t being used. I guess it doesn’t benefit me or am I missing something?

3 Likes

Oh yeah you are correct. As long as the system reports 0 “Used” on /swapfile, it hasn’t needed to swap out to the MMC at all.

It seems like you only have a couple of apps taking up 100+ MB of RAM, so that’s probably why. (In my case, I had Waydroid taking up over 1 GB all by itself.)

I also have several thousand contacts (and a very full calendar) so those apps are both taking up over 100MB of RAM each. And Podcasts, which uses 140MB also.

Side note, @adamd, are we mutual followers on Mastodon? I’m @alex@mbe.tv

3 Likes

Purism “Hire this man”…lol.

6 Likes

Welcome! I hope you enjoy your Librem 5 like many of us do!

If you have any additional tips, I recommend sharing them in the Librem 5 wiki, particularly the Tips & Tricks section. Also, if you have any additional information about swap files, feel free to make edits or corrections to the section about them.

Again, welcome to the forums and I hope to see you around! :smile:

5 Likes

Last night I was using my L5 as I normally do and just for the fun of it I checked memory usage.

I wasn’t doing anything special. I was just catching up on Mastodon reading using Tuba and surfing the web. There were several other open apps but I wasn’t trying to use a lot of ram. Just doing what I do. So it seems this trick does have benefits for my use case.

7 Likes

This trick is a subtle hint that Librem 5 RAM is already too small 2024.

5 Likes

That depends on your use case.

2 Likes

I’d actually push back a tiny bit here. It has more to do with the operating system itself than the hardware.

By default, desktop Linux evicts no running apps from memory. In the case of both iOS and Android, the OS is very aggressive about killing processes to keep memory pressure low. They will issue warnings (iOS docs, Android docs) and then stop or kill processes as necessary.

Desktop Linux (and therefore PureOS) has no such mechanism. The closest built-in functionality would be the OOM-killer, which issues absolutely zero warnings and (in the case of the Librem 5) isn’t going to activate until it’s way too late to keep the system running smoothly.

A lot of this is just for historical reasons, and the historical solution has always been to make sure the machine has a reasonable amount of swap available. So to maintain compatibility with the current standards for Linux apps, Librem 5 really needs swap.

If we ever seriously wanted to eliminate the need for swap, we’d need something like the following:

  • The desktop (Gnome or phosh or some user-space component thereof) would need to keep track of which apps have been interacted with most recently, and which apps are most likely to be interacted with in the near future.
  • It would also need to have a process to keep a close eye on the system’s current memory pressure.
  • As the memory pressure went too high, it would start notifying the oldest apps that they are about to be closed. (I don’t think this API exists today, so it would have to be added.)
  • Apps which receive this signal would need to save their UI state and exit before they get killed.
  • Apps would need to also adopt a practice of restoring their previous UI state upon launch. (To make the user think they were running the whole time.)

At least, that’s how iOS handles this problem. I don’t know about Android, but I expect it’s similar.

You might expect applications to stay running in the background when you navigate away from them. And on desktop Linux, that is definitely the case. But on a mobile system with such limited memory, this would not be possible.

You really only have two options when a user opens an application and navigates away from it:

  • Kill the app and free the memory, making the user sad when they come back. (Unless you are sneaky like iOS.)
  • Let it run and continue taking up memory, eventually running the system out of memory. (Unless you can swap it out as necessary.)

Tradeoffs are everywhere! I don’t know what the right answer is. :smiley:

7 Likes

Well I know the right answer for my security practices: after the intended function has been fulfilled, either manually or automatically terminate the process.

See also:

4 Likes

Easy as this: Power to users. I want to have the memory management in my own hands. I know better what I don’t need. A system may closes 3 apps from 15min ago with total amount of memory: 200mb. I may just kill the app I used 2 minutes ago that takes 500mb.

There is another issue for L5. Start up closed apps take some time. More time as modern Smartphones. So this is a strong reason not to close apps you may want to open again compared to iOS etc.

The real thing that I miss is to easy access background processes. While we can always open usage app to kill those processes, it would be nice to access them directly from Phosh to kill (or reopen) them. But I’m sure it’s coming some day - it’s something devs have also in mind.

5 Likes

If money isn’t particularly a consideration, and there is not enough RAM for your use case, then you can upgrade from a 3GB model to a 4GB model.

2 Likes

And then people make entire websites dedicated to avoiding that behaviour. Both as Android developer and user I hated having my apps randomly killed (more and more aggressively release after release). I don’t miss it.

4 Likes

Does this need a new phone or can the mainboard be replaced?

1 Like

I hear you. I’ve dabbled in app development for iOS and Android and this behavior has definitely driven me crazy.

As a user, it’s not as seamless as Apple would like you to imagine. Even their first-party apps can do a very bad job of restoring the state of the user interface once the app has been killed. And the side effects can be painfully visible.

2 Likes

Official answer would come from Purism but I would think that getting a new phone is by far the easiest, particular as the eMMC drive is soldered on (so you have the hassle of migrating the contents with either approach) and also taking into account downtime if you send the phone in for Purism to replace the mainboard.

2 Likes

Classic clickbaiting. Really distasteful form.

1 Like

I think you may have missed OP’s use of sarcastic humor. :wink:
(Unless you’re trying to be funny, too…?)

3 Likes

Indeed. With the loss of tone in online communications, it could easily be taken the wrong way. I certainly had a negative reaction to the topic, purely based on the title.

My suggestion (without moderator hat on) is that the topic title should have included either a smiley or a “/‍s” sarcasm indicator, with the former being more widely recognised.

2 Likes

Yes. Thank you.

1 Like