We have moved to a new Sailfish OS Forum. Please start new discussions there.

Revision history [back]

click to hide/show revision 1
initial version

posted 2018-03-02 11:40:09 +0200

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

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.

/root/mkswap:

#!/bin/bash
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.

/etc/systemd/system/zram-swap.service:

[Unit]
Description=Create and Enable zram swap
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/root/mkswap

[Install]
WantedBy=local-fs.target

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.

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

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.

/root/mkswap:

#!/bin/bash
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.

/etc/systemd/system/zram-swap.service:

[Unit]
Description=Create and Enable zram swap
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/root/mkswap

[Install]
WantedBy=local-fs.target

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.