Tuning the oom killer / low memory killer

How does one persistently configure these settings properly on SFOS?

/etc/sysctl? /etc/udev/rules.d? systemd oneshot unit? Something else?

2 Likes

I can tell you of an incorrect way, that I used.
nano /vendor/etc/init/init.lena.rc and changed the settings to Sony defaults listed above, you can input anything.
I am sure it is risky and a mistake here could make your phone unbootable, but it works.

3 Likes

Just a follow-up to say that I have only seen positive results from the changes I made (as mentioned earlier in the thread).

1 Like

How can I adjust the values for the XA2?
There are no values to adjust in init.nile.rc.

  GNU nano 2.8.5                                           Datei: init.nile.rc                                                       

# Copyright 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

on post-fs
    rm /persist/bluetooth/.bt_nv.bin
    rmdir /persist/bluetooth

on boot
    # WLAN MAC
    chown wifi wifi /sys/module/wlan/parameters/fwpath
    chown wifi wifi /sys/kernel/boot_wlan/boot_wlan

    # update foreground cpuset now that processors are up
    write /dev/cpuset/foreground/cpus 0-7
    write /dev/cpuset/foreground/boost/cpus 0-7
    write /dev/cpuset/background/cpus 0
    write /dev/cpuset/system-background/cpus 0-1

    # Set the default IRQ affinity to the primary cluster. When a
    # CPU is isolated/hotplugged, the IRQ affinity is adjusted
    # to one of the CPU from the default IRQ affinity mask.
    write /proc/irq/default_smp_affinity f

Original values are:

[root@XperiaXA2 init]# cat /sys/module/lowmemorykiller/parameters/minfree
1536,2048,4096,16384

Can you also do a PR for the XA2?

The values in the XA2 series phones are already minimal, there’s no benefit taking them any lower than that.

4 Likes

On the contrary, I didn’t see very positive impact by changing to Sony’s default values with 10 II. Weird freezes with apps and OS crashing etc. Switched back and I see the reason for 6x.

4 Likes

Good to know, interesting!

Just a quick update!

I have been using the minfree values of 65536,73728,90112,131072,196608 and so far I have been very happy with these! While I may not get the maximum amount of opened applications at the same, I think 12 is plenty good! I’ve also had zero OOM kills since.

I stand my opinion that the X10III ships with too conservative memory limits and they can be safely lowered to some extent without risking OOM at application startup, and providing a much better user experience.

Edit: I simply haven’t had more than 12 apps opened at the same time.

2 Likes

Didsomeone find something that helped with the 10II ? I tried half of jollas defaults and got weird crashes

1 Like

I tested the halving briefly, and had similar results, unfortunately.

It looks like the limits are quite well tuned for X10II. If that is indeed the case, I see no reason to double the values for X10III only because it has double the RAM.

We are slowly narrowing the acceptable window here, which is good :slight_smile:

5 Likes

It’s been two weeks since I’ve been using halved values on the 10 III, without any problems and with not a single occurrence of closing any app due to OOM, with the single exception of the web browser, which happened once. So I’m more than satisfied.

2 Likes

My experience showed better results when halving the freemem values on my X10II. With the default settings, the Android App Support system gets killed most of the time after I watch a video in Fennec (Androids Firefox Browser), as soon as I stop using my device. Next time I turn on my screen, all Android apps are greyed out and opening one of them starts the Android App support first.
Since I started adjusting the freemem values, this rarely happened.
As I’m only using a few apps on my phone, this may not be the average user use case.

2 Likes

joining the boat here :slight_smile: just tweaked minfree on my 10 II with 58580,70100,81620,93140,128245, I have 4 Android apps open + stock browser + Fernschreiber, and the system is still smooth, and no crash so far :crossed_fingers:

7 Likes

I have posted a bug report for them to consider lowering those values

3 Likes

So I just changed my default values after I really got sick with apps closing down randomly. Following @cartron’s tweak I changed from

[root@Xperia10II-DualSIM defaultuser]# cat /sys/modul
e/lowmemorykiller/parameters/minfree
117160,140200,163240,186280,256490

to

[defaultuser@Xperia10II-DualSIM ~]$ cat /sys/mod
ule/lowmemorykiller/parameters/minfree
58580,70100,81620,93140,128245

I will report back in the next couple of days whether I experience an improvement or not.

What I learned so far:

  • I have to set the limits after every reboot
  • Fennec can be killed like before
5 Likes

I have also modified the config on my 10 II.

Here is my experience:

  • Apps no longer close on their own.
  • Got 3 cashs in 2 days (0 in the last 6 months)

I am back to the default configuration.

2 Likes

I was hit by random OOM kills, too that made using the device (10 Mark 2) nearly impossible.
There where a few things I recognized:

  • SailfishOS browser pinch-to-zoom eats memory, e.g. open some github project source code file and zoom in. Now scroll a little bit inside that zoomed file and bang there you go (LMKD is killing a bunch of running applications in a blink)

  • I had a memory leak caused by faulty / broken Sailfish MTA that consumed a lot of memory but alas it’s a system process so other running non-system applications got killed first

My solution to the latter issue was to re-create my mail account which resolved the MTA system process memory leak that caused LMKD to hunt down my other non-system applications.

Now that’s what I call “interesting”… How did you figure it out that it was the MTA process that had the memory leak? Asking for a friend :wink:

1 Like

To be honest I had a bad feeling when syncing my mailbox (IMAP4) suddenly took very long and ended eventually with sync failures. After that I recognized that running multiple applications (Android: ntfy.sh, Schildichat; SFOS: Mail (backround), browser, Quickdit, forum viewer, Podqast) where killed overnight.

I didn’t dig any deeper nor analysed logs (which would be more objective). However after I fixed my broken mail account no overnight or common use crashes of running the same set of applications occured to me (knocking on wood).

What I wanted to say is that system processes are allowed higher memory demand before they are terminated so in the end faulty system processes can trigger the LMKD killing of unprivileged processes and you wonder why the heck are my applications crashing all the time.

I updated to 4.4.0.72 and my changes to the /vendor/etc files was reverted. Just realized when I got pulseaudio killed today (or yesterday).

1 Like