Good morning folks! I’m new to the forum here, so I’ll introduce myself briefly below the body of my post. First, let’s dive right in…
One Weird Trick
I got a Librem 5 off eBay a little less than a week ago, and I’ve been experimenting with it specifically for the purpose of using it as a daily driver. Unfortunately, in this process I’ve noticed the system behaving extremely sluggish at times; apps being slow to load, laggy scrolling, and even random app crashes.
Upon investigation, I found this happening:
Yes, the CPU is pegged, but not because of any useful work. It’s pegged because the system is thrashing swapping pages in and out of zram. The memory pressure is way too high, and this is a sign of a system that is about to crash.
How do fix it? Well, I only have two options. Do less on my phone or add a swap file!
Here’s what I did (do not run these commands unless you know what you are doing!):
dd if=/dev/zero bs=1024 count=2097152 of=/swapfile
chown root:root /swapfile
chmod 600 /swapfile
mkswap /swapfile
echo '/swapfile none swap sw 0 0' >>/etc/fstab
Then reboot!
Note: These commands are intended to be run from a root shell. I didn’t prefix anything with sudo because I would really not like for someone to blindly copy/paste and ruin their phone.
Another Note: I’m running the latest stable Byzantium image, with all package updates installed.
Now my /proc/swaps looks like this:
Filename Type Size Used Priority
/swapfile file 2097148 1495000 -2
/dev/zram0 partition 1484796 1443912 100
And voila, my system has been way snappier, even when I have multiple Firefox tabs open, waydroid, and several other apps.
How do I know if I need more swap?
Check your usage app! (Check below for the screenshot. As a new user I’m only allowed one embedded media item per post.)
If your RAM and/or Swap are ever over 80%, you’re approaching the danger zone.
But I already have zram!
That’s just a compressed area in RAM. It doesn’t give you more RAM, it just compresses pages into and out of RAM. It’s fast, and it’s better than nothing, but once the system memory pressure starts getting too high it’s not going to save you.
If I add a swap file, why bother keeping the zram swap?
The swap file is way slower than zram, so it is added to the swap list at a much lower priority. Ideally, the system will move very old / rarely accessed pages to the swap file and make room for much more frequently accessed pages in RAM and zram.
Won’t this burn out my MMC?
Sure, eventually. Here are a few reasons I’m not worried about it:
- I expect mmcblk0 to have implemented wear-leveling inside the hardware. (I didn’t look up the data sheet, so correct me if I’m wrong.) So no individual file can create a high-wear area on the chip.
- As mentioned above, this swapfile is a lower priority than zram, so I’m minimizing the number of writes to the swapfile.
- I’d rather wear out this phone with daily use in an actually usable configuration instead of tossing it in a drawer in disappointment. (With any luck, this phone will burn out around the time Puri.sm starts shipping something with a modern SoC.)
Who are you?
Hi! I’m Alex Markley. As mentioned at the beginning, I’m new here. I have a background in software and I have some professional experience with embedded Linux systems.
I’ve been using Linux for over 20 years now, often as a daily driver either at home or at work or both.
My Librem 5 is my first true mobile Linux device since my Compaq iPaq running Familar Linux (man I loved that thing). I’m really excited by the recent renaissance of activity around Linux Smartphones getting ready for prime time, and I felt it was high time to roll up my sleeves and dive in!