It may be possible to create a systemd .swap unit file which successfully activates a swap file on /home after that has been mounted.
BUT it would have to be very carefully written, so it does not prevent the built-in swap target from coming up. High risk of the system not booting if done wrong.
It would also have to be written i a way it doesn’t cause problems on shutdown (because it may either prevent /home from being unmounted on shutdown OR a part of swap becomes unavailable suddenly which is equivalent to yanking a DIMM module while the system is running. Not good.)
TL;DR: if you want to fuck up your phone in addition to boiling the ocean, use AI instead of a brain.
For the Xperia 10 II, the benefit is real. Initially, the 10 II would experience oom errors whenever more than two apps were used simultaneously. With zRAM, I can now run many apps smoothly and without OOM.
I don’t loose anytime !
maybe try it simple, not sure when the targets are reached (some systemctl command should show this), but e.g. graphical.target could be very late in boot process, so maybe use this as target to activate the swapfile without need of changing fstab (just swapon)
I wouldn’t even know where to start with something like this. In any case, it’s always possible to create a ½ GB swapfile on / — it’s still better than nothing — or use a 1 GB swapfile on / and simply delete it before performing a SailfishOS update.
This whole ZRAM project was originally meant for the 10 III (the phone I use), because I realized that the Android HAL handled the module very poorly. Then it occurred to me that a swapfile would help (and it does), so I created it and shared the procedure. But my technical knowledge and my experience with SFOS end there.
I don’t feel like going any further: it would mean moving blindly, trying to guess the solution, and risking causing damage.
Thanks to everyone who supported and helped me.
P.s.: I’m happy to help everyone have the oom issue with his smartphone.
OK, so with no guarantees of correctness or ridiculousness, this seems to work and indeed does not cause issues with reboot (tested exactly once, on Jolla C2, SFOS 5.0.0.73):
=====
File MUST be named home-swap-swap0.swap and should be placed in /etc/systemd/system. If you change the location of the swap file, you have to change the name of the unit file following the systemd documentation.
I wanted to compliment you on the .swap unit you shared.
I’m still learning how to use systemd in a more advanced way, and I wouldn’t have been able to write a file like that myself — at least not for now!
I was actually starting to think about an autostart script that would enable a manually created swapfile at every SailfishOS boot, but I’m not sure something like that would even be possible.
Thank you so much for your contribution — this might be the definitive solution for anyone using a very old phone with limited space on / and need SWAP.
Just for clarity: your script enables the swapfile at /home/swap/swap0, but it doesn’t create it. So it needs to be created manually in that location using these commands:
devel-su
mkdir -p /home/swap
chmod 0700 /home/swap
fallocate -l 1024M /home/swap/swap0
chmod 0600 /home/swap/swap0
mkswap -L home-swap0 /home/swap/swap0
and then your script enables it at every boot, right?
And naturally we must starting service and enable it, right?
#before swap file
[defaultuser@Fairphone4 /etc/systemd/system> free -m
total used free shared buff/cache available
Mem: 5503 2378 149 347 2976 3466
Swap: 3072 467 2605
# after sytemctl start
[defaultuser@Fairphone4 /etc/systemd/system> free -m
total used free shared buff/cache available
Mem: 5503 2373 155 347 2976 3471
Swap: 3584 467 3117
[defaultuser@Fairphone4 /etc/systemd/system> swapon
NAME TYPE SIZE USED PRIO
/dev/zram0 partition 3G 466,9M 32758
/home/defaultuser/.swap file 512M 0B -2
not sure if it works after reboot (and enable of course) or fails because home is encrypted (I wouldnt recommend to use a swapfile on a phone or only if really necessary)
Thanks, I applied your script and everything seems to be working fine, even after a reboot.
A small niggle re @nephros swap solution: convention demands that manually added units are to be added in /etc/systemd, not /usr/lib/systemd. This doesn’t affect functionality at all though. If this was an installable package, /usr/lib/systemd would be the correct location.
if you check manpage, there is a description where you should put your stuff , e.g. man systemd.unit:
Table 1. Load path when running in system mode (--system).
+-------------------------------+-------------------------------------------+
| Path | Description |
+-------------------------------+-------------------------------------------+
...
+-------------------------------+-------------------------------------------+
| /etc/systemd/system | System units created by the administrator |
+-------------------------------+-------------------------------------------+
| /run/systemd/system | Runtime units |
+-------------------------------+-------------------------------------------+
...
+-------------------------------+-------------------------------------------+
| /usr/local/lib/systemd/system | System units installed by the |
| | administrator |
+-------------------------------+-------------------------------------------+
| /usr/lib/systemd/system | System units installed by the |
| | distribution package manager |
+-------------------------------+-------------------------------------------+
...
as general info, if you create a new systemd file, use systemctl edit --force --full then it’s placed in the correct location (use with --user for user files in ~/.local/share/systemd)