Skip to content

Expanding RAM with swapfile

Bùi Minh Đức edited this page Feb 22, 2024 · 13 revisions

Warning

Welcome to the danger zone! Before proceeding, please keep in mind that tempering your phone's system will void your warranty and potentially render it unbootable if done incorrectly. PROCEED WITH CAUTION AND AT YOUR OWN RISK. It's recommended to back up your data first.

KaiOS, being the successor of Firefox OS, relies on the Gecko browser engine to run apps written in light-weight web technologies. It runs very efficiently most of the time, despite having as little as 256MB of memory.

But in rare cases, as with other operating systems, the phone can handle as much before it starts killing system processes to avoid RAM overflow. To overcome this constraint, KaiOS pulls the Linux trick and compresses some of the RAM data into a zRAM image that resides within the RAM itself. Although the compressed zRAM is faster as it directly uses the RAM, it takes up about half of its space, leaving just the other half for active tasks.

Creating a swapfile on your phone's internal storage and direct the system to use that swapfile instead of built-in zRAM will free up that half of your RAM, leaving room for more processes and possibly make the phone faster and more capable—though you might have to trade off a tiny degradation in speed, some storage space and storage chip longevity.

Disabling the Low Memory Killer daemon

Low Memory Killer is the Gonk adaption of an Android daemon that terminates system processes in priority order to prevent overflow if you're low on memory. On KaiOS 2.5 devices such as the 6300 4G, this behaviour is directly managed by a kernel module, whereas on KaiOS 3 ones it is controlled through another daemon named b2gkillerd. While it works well as intended, it can be quite intrusive in some ways, like preventing crucial processes from using Alarm API, or stopping Wi-Fi hotspot from transferring data packets (see Known issues).

This daemon can be controlled with a flag at /sys/module/lowmemorykiller/parameters/enable_lmk