Disclaimer: Changing the values listed in this post may and will affect the stability of your device, and can lead into unusable state or data loss. Fiddle with the settings at your own risk.
I have a Sony Xperia 10 III and I’m suffering a lot from different kinds of things, which I assume are caused by the operating system killing processes left and right. I had a hunch that the system is too aggressive on this, so I finally decided to dig deeper.
It turns out there are two actors in play:
- in-kernel oom killer
-
lowmemorykiller (aka.
lkmd
)
Exercising some trial and error, I figured out a command to view/log the lowmemorykiller actions:
dmesg -w | egrep "lowmemorykiller|oom_reaper|^ {19}.*|Out of memory"
I then let the log roll via SSH to the phone, and started switching between (large-ish) Android applications and to browse heavy sites with both Browser and Fennec (Firefox, but from F-Droid). The results contain a surprisingly high amount of kills:
[142202.722417] lowmemorykiller: Killing 'ec_fdroid:tab15' (29069), adj 900,
to free 21kB on behalf of 'kswapd-1:0' (102) because
cache 703724kB is below limit 945120kB for oom_score_adj 529
Free memory is 944692kB above reserved.
Free CMA is 72856kB
Total reserve is 92268kB
Total free pages is 346384kB
Total file cache is 781924kB
Slab Reclaimable is 110948kB
Slab UnReclaimable is 421020kB
Total Slab is 531968kB
GFP mask is 0x0
Kernel Memory Reclaimable is 72732kB
Free Swap 690700kB
queue len is 1 of max 1 reason:0x1 margin:45315
[142202.747413] oom_reaper: reaped process 29069 (ec_fdroid:tab15), now anon-rss:0kB, file-rss:0kB, shmem-rss:24kB
[142215.850115] lowmemorykiller: Killing 'AndroidUI' (28891), adj 900,
to free 37kB on behalf of 'kswapd-1:0' (102) because
cache 681388kB is below limit 945120kB for oom_score_adj 529
Free memory is 879460kB above reserved.
Free CMA is 72856kB
Total reserve is 92268kB
Total free pages is 258908kB
Total file cache is 763884kB
Slab Reclaimable is 110716kB
Slab UnReclaimable is 421788kB
Total Slab is 532504kB
GFP mask is 0x0
Kernel Memory Reclaimable is 94960kB
Free Swap 690716kB
queue len is 1 of max 1 reason:0x1 margin:23446
[142215.871661] oom_reaper: reaped process 28891 (AndroidUI), now anon-rss:0kB, file-rss:0kB, shmem-rss:816kB
[142224.781626] lowmemorykiller: Killing 'nec_fdroid:tab0' (29462), adj 905,
to free 90272kB on behalf of 'kswapd-1:0' (102) because
cache 674628kB is below limit 945120kB for oom_score_adj 529
Free memory is 916792kB above reserved.
Free CMA is 72876kB
Total reserve is 92268kB
Total free pages is 305676kB
Total file cache is 757644kB
Slab Reclaimable is 109128kB
Slab UnReclaimable is 422376kB
Total Slab is 531504kB
GFP mask is 0x6000c0
Kernel Memory Reclaimable is 85544kB
Free Swap 690716kB
queue len is 1 of max 1 reason:0x2 margin:35133
[142224.794389] oom_reaper: reaped process 29462 (nec_fdroid:tab0), now anon-rss:0kB, file-rss:0kB, shmem-rss:24kB
[142241.906141] lowmemorykiller: Killing 'ssioncontroller' (29519), adj 905,
to free 73984kB on behalf of 'kswapd-1:0' (102) because
cache 656088kB is below limit 945120kB for oom_score_adj 529
Free memory is 858552kB above reserved.
Free CMA is 72892kB
Total reserve is 92268kB
Total free pages is 277104kB
Total file cache is 739136kB
Slab Reclaimable is 108956kB
Slab UnReclaimable is 422016kB
Total Slab is 530972kB
GFP mask is 0x6000c0
Kernel Memory Reclaimable is 55388kB
Free Swap 690716kB
queue len is 1 of max 1 reason:0x2 margin:28112
[142241.927463] oom_reaper: reaped process 29519 (ssioncontroller), now anon-rss:0kB, file-rss:0kB, shmem-rss:84kB
[142241.969612] lowmemorykiller: Killing 'AndroidUI' (29389), adj 900,
to free 39kB on behalf of 'kswapd-1:0' (102) because
cache 642744kB is below limit 945120kB for oom_score_adj 529
Free memory is 857128kB above reserved.
Free CMA is 72892kB
Total reserve is 92268kB
Total free pages is 284908kB
Total file cache is 725792kB
Slab Reclaimable is 108972kB
Slab UnReclaimable is 422016kB
Total Slab is 530988kB
GFP mask is 0x0
Kernel Memory Reclaimable is 46664kB
Free Swap 690716kB
queue len is 1 of max 1 reason:0x1 margin:29937
[142241.991278] oom_reaper: reaped process 29389 (AndroidUI), now anon-rss:0kB, file-rss:0kB, shmem-rss:776kB
[142248.117695] lowmemorykiller: Killing 'ec_fdroid:tab23' (29796), adj 905,
to free 22kB on behalf of 'kswapd-1:0' (102) because
cache 631292kB is below limit 945120kB for oom_score_adj 529
Free memory is 765464kB above reserved.
Free CMA is 72900kB
Total reserve is 92268kB
Total free pages is 192084kB
Total file cache is 714296kB
Slab Reclaimable is 108444kB
Slab UnReclaimable is 422068kB
Total Slab is 530512kB
GFP mask is 0x0
Kernel Memory Reclaimable is 47832kB
Free Swap 690716kB
queue len is 1 of max 1 reason:0x1 margin:6729
[142248.122556] lowmemorykiller: Killing 'AndroidUI' (29728), adj 900,
to free 40kB on behalf of 'kswapd-1:0' (102) because
cache 629924kB is below limit 945120kB for oom_score_adj 529
Free memory is 768516kB above reserved.
Free CMA is 72900kB
Total reserve is 92268kB
Total free pages is 195552kB
Total file cache is 712928kB
Slab Reclaimable is 108444kB
Slab UnReclaimable is 422068kB
Total Slab is 530512kB
GFP mask is 0x0
Kernel Memory Reclaimable is 46912kB
Free Swap 690716kB
queue len is 1 of max 1 reason:0x1 margin:7722
[142248.129693] oom_reaper: reaped process 29796 (ec_fdroid:tab23), now anon-rss:0kB, file-rss:0kB, shmem-rss:24kB
[142248.139424] lowmemorykiller: Killing 'com.Slack' (28697), adj 199,
to free 162964kB on behalf of 'HwBinder:3801_1' (3969) because
cache 623316kB is below limit 852960kB for oom_score_adj 147
Free memory is 796204kB above reserved.
Free CMA is 72900kB
Total reserve is 92268kB
Total free pages is 229828kB
Total file cache is 706092kB
Slab Reclaimable is 108216kB
Slab UnReclaimable is 422068kB
Total Slab is 530284kB
GFP mask is 0x6280c2
Kernel Memory Reclaimable is 41084kB
Free Swap 690460kB
queue len is 1 of max 1 reason:0x2 margin:16165
[142248.169577] oom_reaper: reaped process 29728 (AndroidUI), now anon-rss:0kB, file-rss:160kB, shmem-rss:820kB
[142248.220399] oom_reaper: reaped process 28697 (com.Slack), now anon-rss:0kB, file-rss:152kB, shmem-rss:3416kB
[142261.194268] lowmemorykiller: Killing 'a.fennec_fdroid' (30025), adj 900,
to free 25kB on behalf of 'kswapd-1:0' (102) because
cache 604272kB is below limit 945120kB for oom_score_adj 529
Free memory is 830024kB above reserved.
Free CMA is 72920kB
Total reserve is 92268kB
Total free pages is 286460kB
Total file cache is 684272kB
Slab Reclaimable is 107744kB
Slab UnReclaimable is 421896kB
Total Slab is 529640kB
GFP mask is 0x0
Kernel Memory Reclaimable is 21108kB
Free Swap 687140kB
queue len is 1 of max 1 reason:0x1 margin:30444
[142261.207562] oom_reaper: reaped process 30025 (a.fennec_fdroid), now anon-rss:0kB, file-rss:92kB, shmem-rss:116kB
[142262.683725] lowmemorykiller: Killing 'a.fennec_fdroid' (30200), adj 900,
to free 29kB on behalf of 'kswapd-1:0' (102) because
cache 653772kB is below limit 945120kB for oom_score_adj 529
Free memory is 738416kB above reserved.
Free CMA is 72924kB
Total reserve is 92268kB
Total free pages is 198104kB
Total file cache is 742164kB
Slab Reclaimable is 108088kB
Slab UnReclaimable is 421764kB
Total Slab is 529852kB
GFP mask is 0x0
Kernel Memory Reclaimable is 18620kB
Free Swap 686884kB
queue len is 1 of max 1 reason:0x1 margin:8228
[142262.701606] oom_reaper: reaped process 30200 (a.fennec_fdroid), now anon-rss:0kB, file-rss:0kB, shmem-rss:144kB
[142267.151109] lowmemorykiller: Killing 'AndroidUI' (30292), adj 900,
to free 32kB on behalf of 'kswapd-1:0' (102) because
cache 646052kB is below limit 945120kB for oom_score_adj 529
Free memory is 756040kB above reserved.
Free CMA is 72924kB
Total reserve is 92268kB
Total free pages is 164940kB
Total file cache is 735304kB
Slab Reclaimable is 108592kB
Slab UnReclaimable is 422432kB
Total Slab is 531024kB
GFP mask is 0x0
Kernel Memory Reclaimable is 69920kB
Free Swap 686372kB
queue len is 1 of max 1 reason:0x1 margin:-63
[142267.182397] oom_reaper: reaped process 30292 (AndroidUI), now anon-rss:0kB, file-rss:96kB, shmem-rss:480kB
[142270.285857] lowmemorykiller: Killing 'sailfish-qml' (29192), adj 103,
to free 201916kB on behalf of 'allocator-servi' (3333) because
cache 640788kB is below limit 760800kB for oom_score_adj 58
Free memory is 724820kB above reserved.
Free CMA is 72924kB
Total reserve is 92268kB
Total free pages is 186332kB
Total file cache is 729688kB
Slab Reclaimable is 108844kB
Slab UnReclaimable is 421884kB
Total Slab is 530728kB
GFP mask is 0x6280c2
Kernel Memory Reclaimable is 17308kB
Free Swap 686372kB
queue len is 1 of max 1 reason:0x2 margin:5285
[142270.330164] oom_reaper: reaped process 29192 (sailfish-qml), now anon-rss:0kB, file-rss:10016kB, shmem-rss:48kB
Then again, the amount of kills is expected to be non-zero, because mpris-proxy
often needs a restart, Email vanishes right when I’m using it, the whole Android support is killed and automatically restarts etc. Just switching between Browser, WhatsApp and Slack is enouch to trigger a steady stream of kills.
Further notifications at this point:
- The kernel oom killer didn’t take action
-
lowmemorykiller
is trigger-happy -
logmemorykiller
can be configured - There seems to be (huge) differences between Android and AOSP-based operating systems (more RAM = more snipes?) (I lost the source in the swamp, sorry)
Here are my minfree
values on my Xperia 10 III:
$ cat /sys/module/lowmemorykiller/parameters/minfree
167160,190200,213240,236280,356490 # n:o pages
$ getconf PAGESIZE
4096 # page size in bytes
Which correspond to roughly 650MB, 740MB, 830MB, 920MB and 1390MB. Those are the limits of free RAM (or usable, I’m not sure really) under which lmkd
starts killing processes in different categories. Combining this with swappiness of
$ cat /proc/sys/vm/swappiness
25
means that the system is likely to start sniping processes before swapping has a change to step in. I think. I have no memory management experience, but the swappiness sounds too low and the memory limits too strict. So, I’m going to adjust those values, and report back how it goes.