这部分主要是记录下调查lmkd过程中想到的几个疑问,如果读者有其他的问题也可留言,我会根据自己的理解做出相应的分享。
AMS会将查杀的进程adj和对应的内存水位写入/dev/socket/lmkd,最终在lmkd的处理函数中设置的属性sys.lmk.minfree_levels可以看到相关水位。在Runtime,AMS会根据进程状态来调整相应adj的值,并更新到lmkd;
lmkd使用proc结构体来管理进程,并通过size为PIDHASH_SZ的hash表和长度为ADJTOSLOT_COUNT的procadjslot_list来维护所有proc;
android_master/system/memory/lmkd/lmkd.cpp
struct adjslot_list {
struct adjslot_list *next;
struct adjslot_list *prev;
};
struct proc {
struct adjslot_list asl;
int pid;
int pidfd;
uid_t uid;
int oomadj;
pid_t reg_pid; /* PID of the process that registered this record */
struct proc *pidhash_next;
};
#define ADJTOSLOT(adj) ((adj) + -OOM_SCORE_ADJ_MIN)
#define ADJTOSLOT_COUNT (ADJTOSLOT(OOM_SCORE_ADJ_M