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

Jolla already ships a 1G zram configuration out of the box, so they are very aware of our RAM limitations.

AFAICT the primary strategy has really boiled down to

Today’s daily driver experience has been really good so far

  • I have 13 apps open, incl. Browser
  • Lighthouse shows 1G memory free, while 1G/7G swap is used
  • phone is still super responsive to every move I make in all apps

Swap stats probably signal “overkill”, but let’s see how this play out after a few days of heavy workweek. Stay tuned for updates.

4 Likes

Yep, I just posted about swapon -p -3 at Low memory, apps crashing - change zram settings or add swapfile? [4.x] - #52 by lkraav

3 Likes

@lkraav were you able to somehow implement your settings so this would be a default, or loaded later (during boot) system configuration at startup?

I need to manually execute few commands from terminal each time I reboot. I already asked this question few times, but nobody seems to know how to help

zram expansion is easy to persist, exactly as described in this thread.

For added swapfile on /home, I just run swapon manually, with help of Terminal history, as I aim to not reboot often.

I increased zram swap size as described in this thread. Now my 10ii does not kill applications any more.
Also fingerprint reader appears to run longer but that might be just wishful thinking.

Today’s daily driver experience has been really good so far
I have 13 apps open, incl. Browser
Lighthouse shows 1G memory free, while 1G/7G swap is used
phone is still super responsive to every move I make in all apps

After 3 weeks of daily driving additional swap on X10II, my conclusion: it is hopeless.

UX is great at first, maybe 1 day, then massively degrades as more and more key components start getting into superslow /home/swapfile. zram, even boosted, gets exhausted quickly.

Browser, as implemented, is just way too heavy of an app for 4G or less RAM. It is possible to daily drive most other apps pretty smoothly, but with every hyperlink open a massive elephant destroys the porcelain shop.

I like @jojo taking initiative with some Browser memory profiling work [SFOS Browser] Solving the browser memory issue - #41 by jojo but I think upgrading to 6G or preferrably min. 8G RAM device is the only real solution.

Isn’t that a bit much?
I mean other OS’s that supposedly are not as lightweight as sfos can run up to date full fledged browsers with a couple of GBs of ram. And they run blazing fast with no issues at all.
From what I understand is that the browser needs a lot of work and not that 6GB is not enough for a great browsing experience.

1 Like

Certainly, but I predict hardware to solve this problem significantly faster than Jolla will be able to noticeably optimize Gecko. Would love to be proven wrong. Based on the overall SFOS progress velocity, not holding my breath.

I can tell you from my 10III that 6G of ram is still not enough, but I don’t have a II to tell you the actual difference.
Based on that I believe that even with 8, that is overkill in my opinion, the experience won’t be that much different.
It is sad to open any android browser (and dealing with the whole choppy android app experience) to be able to browse without any random closes.

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:

5 Likes