Custom ZRAM Optimization (4 GB + Swappiness=20) with example for Xperia 10 III and tested on C2 too— Guide Available

[ENGLISH]
Hi everyone,

I’ve been experimenting with ZRAM optimization on the Sony Xperia 10 III running SailfishOS, and I ended up creating a small workaround that allows you to:

  • increase ZRAM size (in my case, 4 GB)

  • set a custom compression algorithm

  • adjust swap priority

  • enforce a final swappiness value

  • and make everything persistent through a systemd service

I wrote a complete guide on GitHub, including the script and the systemd unit.

The workaround has been tested on SailfishOS 5.0.0.72 in Sony Xperia 10 III, but with a few adjustments (for example: never setting ZRAM larger than the device’s physical RAM), it should be potentially applicable to any SailfishOS device — of course at your own risk.

The goal of this setup is to increase performance and to give users more control over how ZRAM is configured and to override the early-boot settings applied by droid-hal. If you’re curious about how ZRAM, swap priority, and swappiness interact on SailfishOS, the guide may be useful.

Feedback, improvements, and testing on other devices are very welcome.

Thanks!

GUIDE: GitHub - RootGPT-YouTube/ZRAM-4Gb-on-Sony-Xperia-10-III-with-SailfishOS: Ottimizzazione ZRAM su Sailfish OS con script personalizzato e servizio systemd Questa guida mostra come creare uno script per riconfigurare ZRAM (dimensione, algoritmo di compressione, priorità dello swap) e come renderlo automatico tramite un servizio systemd. È stata testata su Sony Xperia 10 III con Sailfish OS e su Jolla C2.

[ITALIANO]
Ciao a tutti,

ho sperimentato un po’ con l’ottimizzazione di ZRAM sul Sony Xperia 10 III con SailfishOS, e alla fine ho realizzato un piccolo workaround che permette di:

  • aumentare la dimensione della ZRAM (nel mio caso, 4 GB)

  • impostare un algoritmo di compressione personalizzato

  • regolare la priorità dello swap

  • forzare un valore finale di swappiness

  • rendere tutto persistente tramite un servizio systemd

Ho scritto una guida completa su GitHub, che include sia lo script sia l’unità systemd.

Il workaround è stato testato su SailfishOS 5.0.0.72 su Sony Xperia 10 III, ma con qualche modifica (ad esempio: non impostare mai una ZRAM più grande della RAM fisica del dispositivo) dovrebbe essere potenzialmente applicabile a qualsiasi dispositivo SailfishOS — naturalmente a proprio rischio e pericolo.

L’obiettivo di questa configurazione è migliorare le prestazioni del dispositivo e dare agli utenti un maggiore controllo su come ZRAM viene configurata, oltre a permettere di sovrascrivere i parametri impostati molto presto nel boot da droid-hal. Se siete curiosi di capire come interagiscono ZRAM, priorità dello swap e swappiness su SailfishOS, la guida potrebbe esservi utile.

Feedback, suggerimenti e test su altri dispositivi sono più che benvenuti.

Grazie!

GUIDA: GitHub - RootGPT-YouTube/ZRAM-4Gb-on-Sony-Xperia-10-III-with-SailfishOS: Ottimizzazione ZRAM su Sailfish OS con script personalizzato e servizio systemd Questa guida mostra come creare uno script per riconfigurare ZRAM (dimensione, algoritmo di compressione, priorità dello swap) e come renderlo automatico tramite un servizio systemd. È stata testata su Sony Xperia 10 III con Sailfish OS e su Jolla C2.

10 Likes

why such low swapiness value?
because some sources tend to go the opposite way if using zram (high swapiness), e.g. https://wiki.archlinux.org/title/Zram

default value on my phone is also very high

[defaultuser@Fairphone4 ~]$ sysctl -a | grep swap
vm.kswapd_threads = 1
vm.swap_ratio = 100
vm.swap_ratio_enable = 0
vm.swappiness = 100

# but not much used

[defaultuser@Fairphone4 ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           5503        2123         616         333        2764        3655
Swap:          3072         323        2749

or better use lower values?

My device has 4GB of RAM but only 1GB of swap. That seems too low.
My sysctl output is also different.

Did you @mive adjust yours?

> sysctl -a|grep swap
vm.swap_ratio = 100
vm.swap_ratio_enable = 0
vm.swappiness = 25

defaultuser@Xperia10II-DualSIM:~
> free -h
              total        used        free      shared  buff/cache   available
Mem:           3.5G        1.9G      459.3M       20.4M        1.1G        1.8G
Swap:       1024.0M      387.4M      636.6M

What do those sysctl values mean anyhow?

1 Like

AI ANSWER:
Here’s the key point: the ideal swappiness value depends heavily on the type of device and on how its memory management works.

On Linux servers, where CPUs are powerful, RAM is abundant, and workloads are predictable, a high swappiness value (60–100) is often ideal. It maximizes throughput and allows the kernel to use swap as a natural extension of memory. Latency is not a critical concern, so higher values work well.

On Linux desktops, the priority is keeping the user interface responsive. For this reason, many users prefer very low values, such as: vm.swappiness = 10

This ensures that swap is used only when truly necessary, avoiding lag caused by compression/decompression or page movement.

SailfishOS devices, which rely on the Android HAL memory layer, behave more like desktops than servers:

  • Android HAL tends to kill background processes rather than swap aggressively

  • even with swappiness=100, swap usage often stays low

  • mobile CPUs pay a higher cost for compression/decompression

  • UI responsiveness is more important than raw throughput

For these reasons, a low swappiness value (10–30) is generally more balanced. In my case, I chose 20, which keeps ZRAM as a safety buffer instead of turning it into the primary memory extension.

In summary:

  • Linux servers → high swappiness (60–100)

  • Linux desktops → low swappiness (10–20)

  • SailfishOS smartphones → low swappiness (10–30)

So yes, high values make sense in some contexts, but on SailfishOS smartphones a conservative value like 20 tends to provide a more stable and responsive experience.

1 Like

Did you just post an AI answer straight off?

1 Like

no this is the device default, so I guess @mal configured it that way

I’m italian, it’s very difficult for me answer clearly in english, so yes, I have used AI for answer, but the concept is that. I have always use low swappiness on my desktop/laptop and high value on my server.

Oh I just noticed you use a Fairphone. It would be interesting to get the differences explained.

Please make your own answers in the future and avoid all the useless fluff. If people were interested in AI answers, they could get them themselves.

I will try it. However the concept of swappiness is simple: low value = priority to read and write on phisycal RAM, high value = priority to compress data in ZRAM.
So, in a device that needs reactivity, low swappiness is preferred.

1 Like

See, it wasn’t so hard. That to-the-point answer is plenty good.

3 Likes

yeah i also dont know much about this only thing I know is that some recommend low other high value (see the arch example)

Maybe I’m just afraid I won’t be able to explain myself clearly. I’ll try to improve my English as well.

5 Likes

It’s not like the AI is clear either - it adds so much useless fluff. But at least you can know what you want to say - it just puts up random plausible/related stuff.

3 Likes

Maybe it would be better if I used AI only to translate my replies! :wink:

5 Likes

some simple test with high swappiness also tends to fill (mostly) ram first? (swappiness=100)

start

              total        used        free      shared  buff/cache   available
Mem:           5503        2109         628         333        2766        3668
Swap:          3072         323        2749

use 4x512 mb

Mem: 5550276K used, 85124K free, 250844K shrd, 242768K buff, 1516084K cached
CPU:  1.0% usr  1.0% sys  0.0% nic 97.8% idle  0.0% io  0.0% irq  0.0% sirq
Load average: 0.03 0.10 0.23 1/1728 56790
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
55534 48720 defaultu S     518m  9.4   5  0.0 use_mem 512 keep
55583 48999 defaultu S     518m  9.4   5  0.0 use_mem 512 keep
55588 48934 defaultu S     518m  9.4   5  0.0 use_mem 512 keep
55593 48678 defaultu S     518m  9.4   4  0.0 use_mem 512 keep

[defaultuser@Fairphone4 ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           5503        3542          80         245        1882        1733
Swap:          3072         507        2565

2x512, 2x1024

59006 48678 defaultu S    1034m 18.7   2  0.0 use_mem 1024 keep
58847 48934 defaultu S    1034m 18.7   0  0.0 use_mem 1024 keep
59174 48999 defaultu S     518m  9.4   0  0.0 use_mem 512 keep
59320 48720 defaultu S     518m  9.4   2  0.0 use_mem 512 keep

[defaultuser@Fairphone4 ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           5503        4530          29         139         944         790
Swap:          3072         648        2424

My workaround is highly customizable, if you like an high swappiness you can set it. But, in my honest opinion, low swappiness is better if you use a device like NOT a server.

With swappiness=100: when the kernel decides to reclaim memory, it is allowed to swap out pages more aggressively, but the kernel will always try to use RAM first, because RAM is faster than ZRAM and ZRAM is faster than disk swap. So even with swappppiness=100 Linux still fills RAM before swapping. Swappiness affects WHEN swapping happens, not the basic rule that RAM is always used first.

With swappiness=10 the system will use ZRAM ONLY if RAM is full at around 90%.

With high swappiness: ZRAM kicks in as soon as the system feels some memory pressure, and this can increase latency on mobile CPUs because of continuous compression and decompression.

With low swappiness: the system tries to avoid swapping as much as possible and will therefore use ZRAM only when RAM is really under heavy pressure (almost full). This helps maintain better responsiveness because the CPU stays free more often.

I hope I managed to explain myself clearly…

5 Likes

There is one thing that bothers me, what is the reason to increase zram if you are decrasing swappines to not use it? It does not make any logical sense. If you try avoid zram you should increase available RAM.

1 Like

Please do not share curl | bash commands here.
Some newbie might take you up on it and actually do that on their phone.

During our discussion here it became clear that you yourself are aware that you aren’t 100% sure about how exactly each of these settings affects each different phone.

Also, through your username you basically admit to using AI and that makes me doubly uncomfortable.

1 Like

Increasing ZRAM provides more fast virtual memory and helps avoid OOM (Out Of Memory situations, where the kernel would otherwise need to kill various processes). Lowering swappiness does not disable ZRAM, it simply prevents the kernel from swapping too early. This way, real RAM is used to its fullest, and ZRAM kicks in only when it’s genuinely needed.

It’s a balance between performance and stability, not a contradiction.

I’ve spent a lot of time experimenting with ZRAM configurations on Linux to find the best setup. In the end, for a responsive system, I’ve always preferred ZRAM equal to RAM (or slightly less) combined with low swappiness.

I’m not forcing anyone to use my configuration choices — the script is open and easily adjustable to personal needs. For example, someone using their smartphone as a server (a friend of mine does this) might actually benefit from a higher swappiness value.

4 Likes