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

[Xperia X] Lack of swap, apps get killed

Tracked by Jolla (In release)

asked 2017-11-14 16:15:24 +0300

synthent gravatar image

updated 2017-11-14 23:43:36 +0300

On my Xperia X (SFOS I noticed that there is no swap at all. I always thought that no swap at all was a bad idea in general, and now after using the phone for a few weeks I've experienced some cases where apps would be unexpectedly killed, usually just the browser but sometimes some android apps as well, when for example loading a heavy webpage. On JollaC this almost never happened to me, so it's strange that a device with more RAM has this problem.

For example the Peacekeeper browser test (http://peacekeeper.futuremark.com/) always crashes at the fourth testing sequence. (see edit)

To check if the lack of swap was really the culprit, I created a 1GB swap file in my home directory. After enabling the swap I ran the Peacekeeper test and this time it succeeded to finish the whole test. During the test around 450MB of swap was used. Another test with the swap disabled caused browser to be killed again, and once swap was enabled it went straight through, again. So my conclusion is that swap should be enabled for the Xperia X to ensure stability of the system/apps in heavy usage.

IIRC there isnt a swap-partition, the system-partition is too small for swap, and creating a new swap-partition is highly risky. But this can be solved by creating a swap-file in the home-partition which has the most space. 512MB or maybe even smaller (<400mb on JollaC) swap file is probably enough, so its not a huge sacrifice for the stability. Any thoughts?

edit. I had quite a lot of apps (my normal usage) open when I had the browser crash on the fourth sequence. On a fresh boot without other apps the total RAM usage is of course smaller and this test will not be enough to fill the RAM & kill the browser. So the testing method is not the best, but you get the point.

edit retag flag offensive close delete


I'm using Opera as browser and it have been killed couple times. I don't know the reason but I'd like to test this swap-file and see if it helps. Can I use the method described in ArchWiki for creating the swap-file?

kaappikello ( 2017-11-14 22:22:14 +0300 )edit

Yes, you can use those instructions, but I wouldnt touch the /etc/fstab file unless I knew exactly what I was doing. You can experiment with the swap without touching fstab.

synthent ( 2017-11-14 23:25:28 +0300 )edit

How about using zram device instead of storage space? Zram is compressed so it actually saves you more memory than what it uses. As devel-su run:

zramctl -s 524288000 /dev/zram0
mkswap /dev/zram0
swapon /dev/zram0
swapon -s

It allocates 512 MB of swap with compression. Double the amount if you still run out of memory.

Reboot when you want it back to normal. Or one can also first run swapoff /dev/zram0 and then zram -r /dev/zram0, if I remember it correctly.

Manatus ( 2017-11-15 09:55:52 +0300 )edit

I fear there might be also a memory leak in lipstick. However you need very long runtime to achieve that. However I can achieve that big memory usage in lipstick on the tablet everytime which causes crashes of the browser. Restarting lipstick and voila browser does not crash anymore. (I mean crash not OOM Killing)

The SWAP on Sailfish X needs to be turned on. It should be at least 1 GB (using ZRAM with LZ4 compression [which is default] this should be possible without issues)

The Sailfish-Browser btw. crashes also not only because of RAM usage sometimes on the Xperia X. I guess it has to do with the graphics driver still being not fully optimized.

leszek ( 2017-11-15 12:41:56 +0300 )edit

Thanks for the tip about how to setup zram. I will now test it for a while and see if I will run into anything strange.

edit. Swap file seems unnecessary (plus has risks pointed out by Cmdr_Zod) so zram only is probably the best way to have swap enabled.

synthent ( 2017-11-15 18:13:31 +0300 )edit

2 Answers

Sort by » oldest newest most voted

answered 2017-11-16 11:31:52 +0300

Cmdr_Zod gravatar image

updated 2017-11-16 12:34:50 +0300

The problem with the browser getting OOM-Killed on the xperia but not on the Jolla C could be due to 64bit binaries, which needs a bit more memory. But it should not use that much more.

Swap on flash is a bit critical, unlike harddrives, flash has a limited amount of write cycles.Wear leveling helps with this, and I assume the flash memory in mobile devices has improved, but I still would not want to have swap on my cell phones flash memory.

edit flag offensive delete publish link more


Thanks for the tip about the flash wear, it's definitely something you should know when setting up a swap file or partition on flash memory. As far as I know Android doesn't use swap partition or files at all and only relies on zram, maybe because of the risk of wearing out the flash memory on cheaper phones and because phones have so much RAM now.

After testing zram+swapfile for a bit on the Xperia it seems that the swap file gets barely used at all. 512MB of zram didn't get even close to full when I deliberately opened lots of apps and ran heavy stuff on browser and so on. I removed the swap file for now and will try to keep my phone on for a week or two to see if the zram swap ever gets full. After all it could be a memory leak (as pointed out by leszek) or something else, and swap isn't the real fix.

synthent ( 2017-11-16 15:14:22 +0300 )edit

the xperia x might be a 64-bit device, but the sailfish userspace is still 32-bit.

Asseon ( 2017-11-16 23:27:58 +0300 )edit

answered 2017-11-14 23:09:17 +0300

objectifnul gravatar image

updated 2017-11-15 13:32:39 +0300

My Xperia X (SailfishX shows this (SysMon): sysmon

(Not sure this is an evidence of swap actually working though: both curves are a bit too similar).

edit flag offensive delete publish link more



By default there is no swap. Check with swapon -s or free -m

Not sure what SysMon is showing there.

leszek ( 2017-11-15 13:34:30 +0300 )edit

SysMon uses /proc/meminfo for its memory information. You can read it here: https://github.com/custodian/harbour-systemmonitor/blob/master/daemon/datasourcememory.cpp

Maybe it uses the fairly new systemd-swap functionality? I don't know if this would be shown by free??

MrHundert ( 2017-11-15 14:27:49 +0300 )edit

That could be.

leszek ( 2017-11-15 15:37:39 +0300 )edit

I believe SysMon is reading the wrong values. The order of /proc/meminfo data is different than at the source. SysMon thinks that the value of AnonPages is SwapTotal and that the value of Mapped is SwapFree. If you dont have swap enabled and you look into /proc/meminfo you will see that SwapTotal, SwapFree and SwapCached are all zero.

synthent ( 2017-11-15 19:30:53 +0300 )edit
Login/Signup to Answer

Question tools



Asked: 2017-11-14 16:15:24 +0300

Seen: 1,156 times

Last updated: Nov 16 '17