android OOM_adj 的设置流程

流程如下:

setOomAdj

--> framework/base/core/jni/android_util_Process.cpp
android_os_Process_setOomAdj
{
sprintf(text, "/proc/%d/oom_adj", pid);
int fd = open(text, O_WRONLY);
sprintf(text, "%d", adj);
write(fd, text, strlen(text));
}
-->kernel/fs/proc/base.c
    INF("oom_score", S_IRUGO, proc_oom_score),
    REG("oom_adj",   S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
    REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
-->kernel/fs/proc/base.c
static const struct file_operations proc_oom_adjust_operations = {
    .read        = oom_adjust_read,
    .write        = oom_adjust_write,
    .llseek        = generic_file_llseek,
};
--> kernel/fs/proc/base.c
copy_from_user(buffer, buf, count)
err = kstrtoint(strstrip(buffer), 0, &oom_adjust);
task->signal->oom_adj = oom_adjust; //warn,oom_adj is deprecated

task->signal->oom_score_adj = (oom_adjust * OOM_SCORE_ADJ_MAX) -OOM_DISABLE;


说明:

Ams调用setOomAdj设置某进程的adj值,

通过jni接口写到oom_adj文件里,

这个文件是在base.c里注册的文件,里面有个oom_adjust_write方法

该方法将这个值赋给task->signal->oom_score_adj



你可能感兴趣的:(linux)