Memory management 有人能解释一下《oom杀手》中的oom_badness()分数吗?
我认为中的评论已经很好地解释了这一点:Memory management 有人能解释一下《oom杀手》中的oom_badness()分数吗?,memory-management,linux-kernel,out-of-memory,Memory Management,Linux Kernel,Out Of Memory,我认为中的评论已经很好地解释了这一点: /* * If any of p's children has a different mm and is eligible for kill, * the one with the highest oom_badness() score is sacrificed for its * parent. This attempts to lose the minimal amount of work done while * still freei
/*
* If any of p's children has a different mm and is eligible for kill,
* the one with the highest oom_badness() score is sacrificed for its
* parent. This attempts to lose the minimal amount of work done while
* still freeing memory.
*/
oom_badness函数由间接调用,该函数负责处理严重的内存不足状态。例如,当调用out of_memory(内存不足)时,它会迭代所有任务以确定它们的坏处,并且具有最高值的任务会被强制终止,而实际的调用链是→ → 糟糕
任务的好坏取决于多个因素:
它的虚拟内存中有多少页。
它拥有多少交换条目。
使用总字节/页面大小,进程的内存是多少。
如果是因为它负责OOM,它会得到可能的最高分数。
如果是init进程或内核线程,则忽略它。
在较旧的内核版本中,oom_badness函数过去更为复杂,例如考虑到不同的缩放因子和参数,但它经过了更新,使其尽可能简单和可预测
/**
* oom_badness - heuristic function to determine which candidate task to kill
* @p: task struct of which task we should calculate
* @totalpages: total present RAM allowed for page allocation
*
* The heuristic for determining which task to kill is made to be as simple and
* predictable as possible. The goal is to return the highest value for the
* task consuming the most memory to avoid subsequent oom failures.
*/