Manjaro desktop performance improvement on Pinebook Pro and Raspberry Pi 4

Hello,

I could get drastic desktop performance improvements on both Pinebook Pro and Raspberry Pi 4 by performing some little tuning, that Manjaro ARM might consider using as defaults ?

Both devices have 4 GB RAM, a bit less being actually available to Linux. That’s not much by nowadays standards.

The default values make an extremely high usage on RAM-compressed swap, which is detrimental to RAM actually available to software, and slow down things to a crawl by constantly swapping/compressing much to much in RAM.

So this can be improved with :

  • Reduce defaut vm.swappiness of “60” to something like 25
    This can be achieved by creating an /etc/sysctl.d/99-swappiness.conf containing the line :
    vm.swappiness = 25

  • Reduce size of zswap-arm in-RAM compressed swap. It defaults to 150% of RAM size, reducing it to something like 75% seems more reasonable and will ensure more RAM is kept for running programs. 50% might even be better. This should typically be done in the zswap-arm package, otherwise it can be locally done the following way :
    – Create a /etc/systemd/scripts directory and copy /usr/lib/systemd/scripts/zswap-arm-ctrl into it
    – Edit /etc/systemd/scripts/zswap-arm-ctl and change the value of ZRAM_SIZE_PERCENT to 75, or whatever fits better for you.
    – Copy /usr/lib/systemd/system/zswap-arm.service into /etc/systemd/system
    – edit /etc/systemd/system/zswap-arm.service so it calls the script from /etc/systemd/scripts instead of /usr/lib/systemd/scripts
    – You’re done for this part

  • Create a swap partition (better than a swap file, even though it could be) on the machine’s eMMC or SD card.
    – This swap file’s purpose is to manage possible overflow from zram swap, but we don’t want to use it as much as possible both for performance considerations and flash memory wear.
    – So we list this swap partition in /etc/fstab with the « pri=-1 » option, so it won’t be used unless the zram swap fills up (this one has a priority of 100).
    – In this setup, the on-disk swap partition, getting only overflow from ZRAM, wil seldom be used, and if it is, only end up containing swap data wich may never be actually needed again by the system, thus saving RAM without impacting performance or wearing the flash storage.
    – I used a 2 GB swap partition on the Raspberry Pi, and a 6 GB swap partition on the Pinebook Pro, in the hope that hibernation to disk migh someday be possible…

Once all this is done, just reboot.

Then check that everything is as expected using the commands :

  • sysctl vm.swappiness
  • free
  • swapon -s
  • zramctl

You should enjoy much better system overall response, and you can use the command above after some use of the system, to check how much RAM is used, how much swap and of which kind.

Hope this helps :grin:

Here on a quite heavily loaded Pinebook Pro with KDE, Thunderbird open, Vivaldi brower open with more than a dozen tabs, signal-desktop, Dophin open plus some other stuff, I get :

root in /
❯ free -m
total utilisé libre partagé tamp/cache disponible
Mem: 3860 2022 16 1184 1821 614
Partition d’échange: 15149 1635 13513

root in / as :mage:
❯ swapon -s
Nom fichier Type Taille Utilisé Priorité
/dev/dm-3 partition 4175868 0 -2
/dev/zram0 partition 2964520 1675776 100

root in / as :mage:
❯ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo-rle 2,8G 1,6G 499M 520,6M 6 [SWAP]

I even consider reducing swappiness and zram swap still a bit more.

2 Likes

After some more tests, it works even bettter with vm.swappiness reduced down to “5” and ZRAM_SIZE_PERCENT=50 in the same places discussed above.

With that I get much less swapping (but still some useful swapping) and smaller disk cache in RAM, with more RAM directly available to actual software, which helps much with system desktop responsiveness.

And nothing goes to the on-disk swap which is there “just in case of overflow”.

Looks all good, so I believe I will stick with these settings.

As far as I know, zram will only use RAM that is not used by applications.

Yes, but as far I as understand, if there actually is available RAM, but vm.swappiness is set rather high (to its default of 60) the kernel will soon choose to swap, and even if this swap is to RAM, it involves the overhead of the kernel swap mechanism, plus compression/decompression that are quite costly on small ARM CPUs.
So you end up with a lot of RAM unnecessarily attributed to disk cache - not so useful for desktop usage - a lot of RAM-compressed swap usage, very little RAM actually used in its genuine form to applications, and a lot of swap/compression/decompression CPU overhead.

Limiting the size of the ZRAM to half of the RAM guarantees it will never exceed a certain ratio of it (even if some can be made free), and giving vm.swappiness a much lower value will reduce the agressivity of the kernel in sending to swap RAM regions that actually don’t need to, which much improves system responsiveness when shifting from one application to another, toggling between virtual desktops, brower tabs, and the like.

By my own personal impression, the overall desktop responsiveness is greatly improved.

By my own tests, with the original settings, in desktop usage after a couple hours on a 4 GB RAM system, I had more than 2 GB in “compressed swap” (compressed to about 500-600 MB), about 2 GB of disk cache that looks really overkill for a desktop, and only the little rest as “true application RAM”.

With my settings, after a couple of hours, I get about 800-900 MB of disk cache, looks more than enough on a desktop, about 800 MB in compressed swap (actually using about 250 MB of real RAM), and the rest for true application RAM, which mutliplies by 4 to 6 the amount of RAM “used as normal application RAM” on my system…