adj文件包含队列包含oomadj队列,当对应的minfree值达到,则进程的oomadj如果大于这个值将被杀掉。
minfree包含对应oom_adj的警戒值。
# Define the memory thresholds at which the above process classes will
# be killed. These numbers are in pages (4k).
setprop ro.FOREGROUND_APP_MEM 1536
setprop ro.VISIBLE_APP_MEM 2048
setprop ro.SECONDARY_SERVER_MEM 4096
setprop ro.BACKUP_APP_MEM 4096
setprop ro.HOME_APP_MEM 4096
setprop ro.HIDDEN_APP_MEM 5120
setprop ro.CONTENT_PROVIDER_MEM 5632
setprop ro.EMPTY_APP_MEM 6144
# Write value must be consistent with the above properties.
# Note that the driver only supports 6 slots, so we have HOME_APP at the
# same memory level as services.
write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15
write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,5120,5632,6144
# Set init its forked children's oom_adj.
write /proc/1/oom_adj -16
实际上在frameworks/base/services/java/com/android/server/am/ActivityManagerService.java中定义了两个更高的优先级。
// This is a process running a core server, such as telephony. Definitely
// don't want to kill it, but doing so is not completely fatal.
static final int CORE_SERVER_ADJ = -12;
// The system process runs at the default adjustment.
static final int SYSTEM_ADJ = -16;
根据以上分析,对于某些小内存设备,我们可以调整对应的门限值,例如:
一般调整后三个值。
echo "1536,2048,4096,15360,17920,20480">/sys/module/lowmemorykiller/parameters/minfree