【问题标题】:Could anyone explain about oom_badness() score in OOM killer?任何人都可以解释OOM杀手中的oom_badness()得分吗?
【发布时间】:2020-07-12 03:17:21
【问题描述】:
/*
 * 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.
 */

【问题讨论】:

    标签: memory-management linux-kernel out-of-memory


    【解决方案1】:

    我认为the source code 中的 cmets 已经很好地解释了它:

    /**
     * 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.
     */
    

    oom_badness() 函数由out_of_memory() 间接调用,该函数负责处理严重的内存不足状态。当out_of_memory()被调用(例如by the page allocatorby the page fault handler)时,它会遍历所有任务以确定它们的“坏”,并且具有最高值的任务被强行杀死(实际的调用链是select_bad_process()oom_evaluate_task()oom_badness())。

    一项任务的“坏处”取决于多种因素:

    • 它的虚拟内存中有多少页。
    • 它拥有多少个 SWAP 条目。
    • 进程使用了​​多少内存(总字节数/页面大小)。
    • 如果是 already marked to be killed,因为它负责 OOM,它会获得尽可能高的分数。
    • 如果是 init 进程或内核线程,则会被忽略。

    在较旧的内核版本中,oom_badness() 函数过去更加复杂,例如考虑到不同的缩放因子和"bonuses" for privileged processes,但它已被更新以使其“尽可能简单和可预测”。

    【讨论】:

      猜你喜欢
      • 2011-03-31
      • 1970-01-01
      • 2015-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      相关资源
      最近更新 更多