Low memory, apps crashing - change zram settings or add swapfile? [4.x]

Angelfish + Qt Runner does the job, no Android needed.

Performance was really bad when I tried it 2 weeks ago. And I was wondering at that point, isn’t the sfos browser open source? Cause if it is, I can’t understand why people would port basically anything to SFOs instead of working on the stock browser.
Unless I didn’t understand something of course.

Yes, thats right. Angelfish is slow. But stability is better than SF Browser, will say, it never crashes.

Also I prefer the SF-B. because it’s a Firefox derivate while Angelfish is a Chrom(ium) derivate, and for my flavour SFB/FF has much better UI.

I strongly assume, the browser crashes are someway related with power saving settings and sending the CPU or some other parts of the phone to sleep and wake them up later.

I observed that the browser never crashes if DeadBeef Silica is running in the background playing music while surfing and keeps CPU awake preventing power save and sleep mode. In this case also Browser UI interactions (taps, clicks) are noticeable faster with no delays.

On the other hand, if Browser runs alone, UI interactions are generally lazy, e.g. try to write something on a dialog:
If keyboard opens, you touch a letter key too short: ignored;
touch middle time: optical feedback on keyboart comes but letter is not written in the text;
touch long enough: optical feedback on keyboard comes and letter is inserted into text field.

@lkraav Thanks for the lipstick hint. I agree generally. There are times when the Browser crashes are insufferable and also everything is slow on the phone for unknown reasons. Other times UI is fast as it should be and Browser works quite good.
So maybe not the Browser itself is the faulty but some lipstick bug.

The ‘insufferable’ situations often can be solved by leaving the phone in peace for half an hour, after this it works again. Lipstick running into a mess?

Next time this happens I’ll do no other tricks but immediately reset UI with SF utilities, and report here.

…to be continued…

1 Like

Same here.

My latest “overall UX” discovery is that a complete “Lipstick + apps” restart, when it crashes on its own, or you trigger it via Settings > Utilities, does wonders for restoring cold boot-like smoothness, without a restart.

Feeling like if I set up a systemd timer unit to trigger this nightly, I might have a solid daily driver in X10II again.

I’ve been talking about memory leaks in this thread before, and this reinforces my belief that probably many of these complicated base components (GPU driver, Lipstick, Alien Dalvik, Browser) are simply leaking resources over the session and degrade in performance.

1 Like

this does not work for me even doing this before:

In fact, the result is the following:

[root@sfos ~]# zramctl -s $((2*1024*1024*1024)) /dev/zram0 
zramctl: /dev/zram0: failed to reset: Device or resource busy
[root@sfos ~]# echo 1 > /proc/sys/vm/drop_caches; swapoff -av; free
swapoff /dev/zram0
              total        used        free      shared  buff/cache   available
Mem:        3643472     1100024     2353380       12844      190068     2485908
Swap:       1048572      289588      758984

In particular this is the error:

[root@sfos ~]# echo 1 > /proc/sys/vm/drop_caches; swapoff /dev/block/zram0
swapoff: /dev/block/zram0: swapoff failed: Interrupted system call

and checking with dmesg -Hw there is constant flux of these messages:

[  +0.000071] Freezing of tasks aborted after 0.030 seconds
[  +0.000083] OOM killer enabled.
[  +0.000002] Restarting tasks ... done.
[  +0.015447] PM: PM: suspend exit 2023-06-29 09:30:30.916913689 UTC
[  +0.000004] PM: suspend exit
[  +0.004559] binder: 2749:2749 transaction failed 29189/-22, size 32-0 line 3096
[  +0.045540] ## mmc1: mmc_gpio_set_uim2_en: gpio=101 value=1
[  +0.070757] PM: PM: suspend entry 2023-06-29 09:30:31.037763337 UTC
[  +0.000016] PM: suspend entry (deep)
[  +0.000009] PM: Syncing filesystems ... done.
[  +0.008866] Freezing user space processes ... 
[  +0.035409] PM: Wakeup pending, aborting suspend

UPDATE #1

I think that, it was this line to create the problem:

echo 1 > /proc/sys/vm/drop_caches

which starts a drop that will keep longer than supposed to be and interfere with swapoff command which probably does not need it because it should have its own internal specific calls about cache dropping.

UPDATE #2

Anyway chianging the size of the swap size at running system time does not seem a immediate procedure (not so much, at least). In fact, this functions fails in this aim even when succeed for each command:

zram_set_size() {
	declare -i mb=${1:-1024}
	swapusage() { free -m | grep -i swap | tr -s ' ' | sed "s,0 0 0,off,"; }
	swapusage; swapoff -v /dev/zram0; swapusage
	echo
	echo "The zram size at boot is set in $(ls -1 /vendor/etc/fstab.pdx20?):"
	sed -i "s|\(^/dev/block/zram0.*size\)=[0-9]*,max|\\1="$((mb*1024*1024))",max|" \ 
           /vendor/etc/fstab.pdx20?
	grep zram /vendor/etc/fstab.pdx20? | tr -s ' '
	echo
	swapusage; swapon -v /dev/zram0; swapusage
}

What device are you using?
Did you try reboot and do swapoff after fresh system restart?
To be honest I’ve never faced problems with swapoff command.
Maybe you can also try disabling all swap spaces?:

swapoff -a

SFOS 4.5.0.19 on Xperia 10 mark 2

After a reboot, it is the same: neither swapoff -a nor swapoff /dev/zram0 work.

Possilby in the new version they put some processes that cannot killed by OOM and therefore swap cannot be releasead? I do not think that this is the problem because there was enought plain RAM to move that processes. However, if the flag about being ignored by OOM can easily prevents that OOM can move them in plain RAM. I never had to do with zRAM swap before.

Changing the size of zRAM in /vendor/etc/fstab.x* and reboot the smartphone achieve the goal but I wish avoid to reboot the system. After all, this is Linux not Windows! :blush:

EDIT - This post have been changed thanks to @Blumenkraft reply.

This Patch Manager patch will help you in resizing the zRAM swap while the system is running:

after the PM2 patch application execute the script with

  • devel-su /bin/bash zram_swap_resize.sh 1536

The default value is 1024, other reasonable values are 512 or 1536.

All the information have been delivered into the PM2 patch description.


UPDATE

In my personal case which includes the use of Android Support, the statistics collected by System Monitor indicates that 1GB of zRAM swap is large value because its use rarely will go over 60% of its full capacity probably the best valiue for my use style is 768MB or even 512MB with a 5% of swapiness insted of 25% (default).

With all respect, it is really not good practice to suggest anyone to run any script without thorough introduction. Essentially it is just a really, REALLY bad idea security wise to let people think it is ok to just “try it out”, if you catch my drift. Even if your intentions are good, i have to point this out.

3 Likes

I see your point expecially because the script is on a shared link Google drive.

Therefore, I am going to paste here the full code of the script:

#/bin/bash
#
# (C) 2023, Roberto A. Foglietta <roberto.foglietta@gmail.com>
#           Released under MIT license for SailFish OS 4.5.19
#
#################################################################

if [ "$(whoami)" != "root" ]; then
    echo "This script should be executed by root"
    echo "Please, insert the password or CTRL-C"
    devel-su /bin/bash $0 $1
    exit $?
fi

pwsvenagain=0
pwsvstate=enabled
power_saving_state() {
    pwsvstate=$(mcetool | sed -ne "s,^Power saving mode: *\([endisabl]*\) .*,\\1,p")
    echo "Power saving mode: $pwsvstate" 
}

power_saving_toggle() {
    if [ "$1" = "disabled" ]; then
        echo "Enabling power state..."
        mcetool --set-power-saving-mode=enabled
        power_saving_state
    elif [ "$1" = "enabled" ]; then
        echo "Disabling power state..."
        mcetool --set-power-saving-mode=disabled
        power_saving_state
    else
        echo "USAGE: power_saving_toggle enable|disable"
        return 1
    fi
    return 0
}

mtavail=no
mcetool_check() {
    if ! which mcetool >/dev/null; then
        echo -e "\nThis script wishes to have mce-tools installed"
        echo    "because swapoff will fail with power saving enabled."
        echo    "You can disable power saving manually or you can"
        echo    "accept to reboot the device to complete the resize"
        echo    "or you can install with pkcon install -y mce-tools"
        echo -e "\nPress ENTER to continue or CTRL-C to abort."
        read
     fi
     mtavail=yes
}

zram_swap_change() {
    echo "Disabling and resizing the zRAM swap..."
    sleep 0.25; echo 1 > /proc/sys/vm/drop_caches
    if [ "$swapuse" != "off" ]; then
        if ! swapoff -v $blockname; then
            echo -e "\nWARNING: the on-line resize failed, reboot required"
            return 1
        fi
    fi
    swapusage
    zramctl -s $1 $blockname
    mkswap $blockname
    return 0
}

zram_swap_resize() {
    mb=$((${1:-1024} + 0))
    zramsize=$((mb*1024*1024))
    blockname=/dev/block/zram0
    filename=$(ls -1 /vendor/etc/fstab.pdx20?)
    swapusage() { free -m | grep -i swap | tr -s ' ' | sed "s,0 0 0,off,"; }
    swapuse=$(swapusage | awk '{ print $2 }')
    
    printf "Current size of zram0: %s Mb\n" $swapuse
    
    zram_swap_change $zramsize || resized=no
	
    echo -e "\nThe zram size at the next boot is set in $filename by this line"
    sed -i "s|\(^"$blockname".*size\)=[0-9]*,max|\\1="$((mb*1024*1024))",max|" \
        $filename
    grep zram $filename | tr -s ' '

    if [ "$resized" != "no" ]; then
        echo -e "\nEnabling the zRAM swap..."
        swapusage; swapon -v /dev/zram0; swapusage
    fi
    echo
}

mcetool_check
power_saving_state
if [ "$pwsvstate" = "enabled" ]; then
    power_saving_toggle enabled
    pwsvenagain=1
fi
zram_swap_resize $1
if [ "$pwsvenagain" = "1" ]; then
    power_saving_toggle disabled
fi

Probably the best I can do, is coverting it into a Patch Manager patch which create this file into /usr/bin folder in such a way the user can execute it trusting into the community surveillance.

1 Like

If not sure, you can always ask chatGPT :smiley:

4 Likes

I’m wondering that on my spare-Sailfish Device (Sony Xperia X Compact) the swap will never be really used and on my daily Sony XZ2 Compact it makes heavy use of the swap (around 500MB), although it have 1GB more RAM (4GB Total) like the X Compact (3GB Total).

Peek CPU-Performance is better on the XZ2 Compact (Browsing Webpages, starting Apps) but the long-term Battery consumption save and less heat production is better on the X Compact.

1 Like

SWAP OFFLOADING

Since v0.0.8, it has been introduced the offload parameter that enforce - as far as possible - the dump of the zRAM swap in order to free it:

  1. close all your applications
  2. stop the Android Support
  3. call the script with offload

It might fail but usually in less than one minute, it will move all your Android apps sleeping in backgroud to the RAM with the high chance to be terminated by OOM. After this action, your smartphone will performe with native apps like after a reboot.

1 Like

I have installed the patch but the script does not start:
/bin/ash: can’t open ‘/tmp/patchmanager/usr/bi
n/zram_swap_resize.sh’: No such file or direct
ory

Well @shults, you have been robanged.

5 Likes

I am not using the UI anymore because I am refactoring the recovery image. I cannot check and IMHO the Patch Manager is not the right tool for this things (also their authors are not happy about the use I do of that tool, but this is another story).

Before executing a script you have to set the executable bit on it with chmod +x otherwise it does not run. Therefore curl -L to download, then chmod +x and the you can run it.

Looks like work at jolla tablet for sailfish4.5.0.25

Hello everyone.

A week ago I formatted a 128GiB SD card into a swap device and enabled it with my phone’s CLI (swapon). On top of that, I disabled the zRam swap device with swapoff.

The result is excellent — the system is always 100% stable, only slow at times. There is no weird flickering, no crashes and no hang-ups.

I am very confident that my removal of the zRam swap is crucial to stability of the system. In the past, I performed a very similar test, where I simply added the 128GiB swap on SD. That was a failure, because the system was ultimately more unstable than unmodified. I suspect there was a lot of data cycling between the compressed and uncompressed memory regions, causing the instability.

If you want to replicate this, don’t forget that my setup is just a pair of swapon and swapoff commands, which doesn’t survive reboots. On the other hand, I had no need to reboot at all.

1 Like