First not all devices have the same OOM configuration. Post boot maybe some scripts may change the default Android settings.
Therefore you need to check some things to make sure what you are doing.
Android 2.x had OOM but different config. This is for Android 4.x Please correct me if I am wrong
First get your OOM ADJ levels right:
dumpsys activity oom
OOM ADJ levels 10,11,12,13,14 are also cached/hidden apps. Levels with "-" ADJ will never be killed.
So be sure to configure the OOM ADJ file correctly:
echo "0,1,2,4,9,15" > /sys/module/lowmemorykiller/parameters/adj
echo "6144,8192,10240,12288,14336,16384" > /sys/module/lowmemorykiller/parameters/minfree
0 FOREGROUND_APP 24MB
1 VISIBLE_APP 32MB
2 PERCEPTIBLE_APP 40MB
4 BACKUP_APP 48MB
9 HIDDEN_APP_MIN 56MB
15 HIDDEN_APP_MAX 64MB
All other levels take the value of the above defined level. So ADJ level 6 gets the MB value of ADJ 9.
(note: There can only be 6 OOM ADJ levels in the adj file?)
The ADJ file can contain OOM SCORE instead of the written OOM ADJ values: writing 0,1,2,4,9,15 will read 0,58,117,235,529,1000
OOM_SCORES go up with the OOM_ADJ level. So apps in the foreground (ADJ 0) will have OOM_SCORE like 50,
apps with ADJ 15 will have OOM_SCORE up to 1000.
Lets check when the launcher will be killed.
With dumpsys activity oom
Proc #23: adj=fore /FA trm= 0 742:com.anddoes.launcher/u0a130 (top-activity)
oom: max=15 hidden=10 curRaw=0 setRaw=0 cur=0 set=0
keeping=true hidden=false empty=false hasAboveClient=false
PID of launcher is 742
with OOM_ADJ of 0 (not home adj but 0 since it is foreground app at this moment).
Now see what the real OOM SCORE value is with cat /proc/742/oom_score
That gives a value of 69.
(or use ps -o
It is foreground app now with score 69. So if allocatable mem < 24MB it might get killed.
When launcher is not the foreground app we see: ps 742 -o
USER PID PPID VSIZE RSS OOM_ADJ OOM_SCORE WCHAN PC NAME
u0_a130 742 151 413800 60108 6 422 ffffffff 4020da70 S com.anddoes.launcher
Now lancher has HOME_APP adj of 6 with an OOM_SCORE of 422. So if allocatable mem < 56MB it is a candidate to get killed.
Note: OOM_ADJ 6 is not listed in adj config file. But ADJ 9 is. So ADJ 6 will take its level from 9 which is 56MB.
What process is killed first?
For every process (with a specific OOM_ADJ level) the OOM_SCORE is calculated/adjusted. Processes with higher OOM_SCORE will be killed sooner when allocatable (not free) RAM drop below given level.
Check all processes with ps -o
and watch the OOM_SORE column.
Note: if you configure OOM options to minimal you can experience high cpu usage due to kswapd0 deadlock on no swap file device