[HowTo] [Xperia X] [2.1.4] Enable swap to prevent App killing

asked 2018-03-02 11:40:09 +0300

ghling gravatar image

updated 2018-03-02 11:40:51 +0300

We have discussed this in the 2.1.4 thread over at TMO, but I want to gather all steps here in a central thread. With the EA of 2.1.4, it seems SFOS on the Xperia X is very aggressive in killing Apps when there is few free memory left. This can happen as soon as there are a few Apps running.

One possible and easy to implement solution is by adding swap memory. This is additional memory that the device can use to "outsource" physical memory when its full. The easiest solution is to use zram, a technique that provides swap by compressing the content of the physical memory and storing it inside the memory again (kind of like a .zip archive). This way, we don't have to allocate any physical space on the file system (already low) or sdcard (low IO speed & card weardown).

So, let's get going. I used a SSH connection to my phone (-> Developer tools) and the privileged root user (-> devel-su). As always, keep in mind that you are doing all on your own risk.

First, create the script that creates, prepares and mounts the swap. I placed it in /root/mkswap, but you can use any other path if you like. Just remember the exact path since we need it later for the systemd service.


zramctl -s 1G /dev/zram0
mkswap /dev/zram0
swapon /dev/zram0

Set the permissions:

chmod 755 /root/mkswap

Next, we have to create a systemd service to execute the script during startup, otherwise the swap would be gone after a reboot. Create the file /etc/systemd/system/zram-swap.service. You can also use another service name if you like. If you placed your script in another path, adjust the ExecStart entry accordingly.


Description=Create and Enable zram swap



Now, test the service file:

systemctl start zram-swap.service

If all went well, you'll see that there is now swap space available from /dev/zram0 when entering swapon -s:

[root@Sailfish nemo]# swapon -s
Filename                Type        Size    Used    Priority
/dev/zram0                              partition   1048572 0   -1

After successful testing, all that's left to do is enabling the service so it gets started on boot:

systemctl enable zram-swap.service

From my personal experience, SFOS should now kill Apps much less often, even though the swap space is rarely used on my device. It seems that Android Apps are killed more likely than native SFOS Apps.

Please feel free to contribute to this HowTo or point out improvements, especially my systemd skills are very basic.

edit retag flag offensive close delete



I use this method long time, so far so good no more app killing

TMavica ( 2018-03-02 12:17:11 +0300 )edit

Thanks a lot, but the right solution would be to tweak the low memory killer not to kill apps that early.

As far as I read in [release notes] 2.1.4 / Lapuanjoki low memory killer was enabled there. So I wonder if Jolla configured it in a way to take the 3 GB RAM of the Xperia X into account? With this great amount of memory available compared to the 2 GB of Jolla C or the 1 GB of Jolla 1 I don't see any reason for apps to get killed before the whole physical memory is exhausted especially when only a few are open.

This is a bug in my opinion what should be properly fixed adjusting the low memory killer.

Also Jolla could enable zram by default for the Xperia X as done for the Jolla 1 and Jolla C.

https://together.jolla.com/question/179223/release-notes-214-lapuanjoki/ HW adaptation . Xperia: low memory killer enabled.

mick3 ( 2018-03-02 12:51:43 +0300 )edit

Hopefully, once Sony's upstream kernel 4.4 will be integrated, we'll be able to also leverage "Zswap" in addition to Zram.

  • From the outside : Zswap has more or less the same usefullness as Zram, except that it can kick less often used page out to an actual physical swap partition on the SDcard. (Zram can only use RAM)
  • Under the hood, Zram is implemented as a compressed block device on which you put a swap partition, Zswap is implemented as compression pre-filter on the normal swap stack's front end.
  • But mostly, the main difference is that Zswap was only added to kernel 3.11, so it is not available on the older kernel 3.10.84 that's still being used by Sailfish X.
DrYak ( 2018-03-02 13:05:26 +0300 )edit

I don't think Zram or swap are necessery! More apps are working perfektly on JollaC with less RAM. It is definitly a bug in 2.1.4 for SailfishX

SaimenSays ( 2018-03-02 15:21:36 +0300 )edit

That's definitely not the case, it was also there in previous versions, so the swap or any codes /settings that can help prevent this app killing is more than welcome!

aQUICK1 ( 2018-03-02 17:58:13 +0300 )edit