Android 7.0 LowMemoryKiller 初识

kill 日志中的(adj 900)

848: 11-10 16:21:21.424072 1114 21429 I ActivityManager: Killing 1029:com.google.process.gapps/u0a16 (adj 900): system app is not cached in devices with low memory

低内存阈值

主要这个2个文件,不同配置的手机这2个文件是不一样的哦

/sys/module/lowmemorykiller/parameters/minfree
/sys/module/lowmemorykiller/parameters/adj

C:\Users\fadi.su>adb shell cat /sys/module/lowmemorykiller/parameters/minfree
18432,23040,27648,32256,55296,80640

C:\Users\fadi.su>adb shell cat /sys/module/lowmemorykiller/parameters/adj
0,100,200,300,900,906
OOM_ADJ minfree minfree_MB
0 18432 18432 * 4 KB = 72 MB
100 23040 23040 * 4 KB = 90 MB
200 27648 27648 * 4 KB = 108 MB
300 32256 32256 * 4 KB = 126 MB
900 55296 55296 * 4 KB = 216 MB
906 80640 80640 * 4 KB = 315 MB

我的机器是Android 7.0 我记得以前adj值没这么大的,印象中是0,1,2,7,14,15的样子。

故当系统可用内存小于 minfree值时,kill对应的OOM_ADJ级别进程
故当系统可用内存小于216 MB时,adj优先级为900的会被kill掉

    // This is the process running the current foreground app.  We'd really
    // rather not kill it!
    static final int FOREGROUND_APP_ADJ = 0;

    // This is a process only hosting activities that are visible to the
    // user, so we'd prefer they don't disappear.
    static final int VISIBLE_APP_ADJ = 100;

    // This is a process only hosting components that are perceptible to the
    // user, and we really want to avoid killing them, but they are not
    // immediately visible. An example is background music playback.
    static final int PERCEPTIBLE_APP_ADJ = 200;

    // This is a process currently hosting a backup operation.  Killing it
    // is not entirely fatal but is generally a bad idea.
    static final int BACKUP_APP_ADJ = 300;

    // This is a process only hosting activities that are not visible,
    // so it can be killed without any disruption.
    static final int CACHED_APP_MAX_ADJ = 906;
    static final int CACHED_APP_MIN_ADJ = 900;
OOM_ADJ 常量表示 含义
0 FOREGROUND_APP_ADJ 当前正在使用的前台进程
100 VISIBLE_APP_ADJ 可见进程
200 PERCEPTIBLE_APP_ADJ 可感知进程,比如后台音乐播放
300 BACKUP_APP_ADJ 备份进程
900 CACHED_APP_MAX_ADJ 不可见进程的adj最大值
906 CACHED_APP_MIN_ADJ 不可见进程的adj最小值

结语

大体明白为毛,应用被杀的缘故了。不过具体ADJ的计分规则还没研究。遇到再说

你可能感兴趣的:(安卓系统)