Tuning the oom killer / low memory killer

@Maus, I can assure you; after I modified the values, my X10III feels like it actually has 6GB of RAM! If my phone felt like a beast before (even when compared with Xperia 10 II), now it’s a monster!

@hackman238 That is both very neat and unfortunately hacky at the same time…! It’s great that the oom_score_adj can be easily set per-process, but it really shouldn’t have to be done via a shell script. I tried to search for a bit, but I didn’t find any obvious way to set a desired value at startup.

However; I found this question which reveals that a process can write value to /proc/self/oom_score_adj, so that is something that the binary can do by itself, which is nice! Another option is to have a dedicated adjust daemon with a list of processes and adjustments, I guess.

Anyway, after a few hours of testing, with a stable phone still, here are the current values – I simply halved each number and doubled the swappiness.

$ cat /sys/module/lowmemorykiller/parameters/minfree
83580,95100,106620,118140,178245
$ cat /proc/sys/vm/swappiness
50

Note: These are from Xperia 10 III with 6GB of RAM! The propotion of the numbers relative to the physical memory are as follows:

Old: 10.6% 12.1% 13.6% 15.0% 22.7%
New:  5.3%  6.0%  6.8%  7.5% 11.3%

Old: 653.0MiB 743.0MiB 833.0MiB 923.0MiB 1392.5MiB
New: 326.5MiB 372.5MiB 416.5MiB 461.5MiB  696.3MiB

(I think the values could be a lot lower still, the tinkering continues…)

And the current memory usage:

$ cat /proc/meminfo 
MemTotal:        5640112 kB
MemFree:          510008 kB
MemAvailable:    1085776 kB
Buffers:           64880 kB
Cached:           602544 kB
SwapCached:        14832 kB
Active:          1435476 kB
Inactive:        1527836 kB
Active(anon):    1153812 kB
Inactive(anon):  1227808 kB
Active(file):     281664 kB
Inactive(file):   300028 kB
Unevictable:       13148 kB
Mlocked:           13148 kB
SwapTotal:       1048572 kB
SwapFree:         730044 kB
[...]
$ zswapctl
NAME       ALGORITHM DISKSIZE   DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lz4             1G 307,8M 77,5M 81,8M       8 [SWAP]

I’m simply blown away. The swap is chilling there with third of the capacity used!

I’m currently running Browser, WhatsApp, Slack, Hydrogen, Whisperfish, “Firefox”, HERE WeGo, Deezer, Gallery and Email, all at once, and none of them gets killed when I rapidly switch between them (I’ve been doing this for a few minutes now, going strong)! The fingerprint sensor still works as it should, and so does my Bluetooth headphones’ media controls (aka. mpris-proxy hasn’t been killed either)!

I still have ~179MB free RAM and ~1100MB available (used by cache, free-able anytime) RAM, this is nothing short of a breakthrough! And there are zero processes killed since I made the change above.

For comparison, here’re the numbers from Jolla Phone:

$ cat /sys/module/lowmemorykiller/parameters/minfree 
4096,6144,8192,12288,20000
$ zramctl 
NAME       ALGORITHM DISKSIZE  DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram1              52,6M  5,5M  1,9M  2,9M         [SWAP]
/dev/zram0              52,6M  5,4M  1,9M  2,9M         [SWAP]

 2.0%  3.0%  4.0%  5.9%  9.7%
16MiB 24MiB 32MiB 48MiB 78.1MiB

So my adjusted (halved) values above are still higher in relative terms to the total RAM size, which indicates to me that the default values in Xperia 10 III actually are stupendously large.

6 Likes