谁能解释OOM杀手中的oom_badness()分数?

问题描述 投票:0回答:1
/*
 * 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个回答
0
投票

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

/**
 * 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()时(例如out_of_memory()by the page allocator),它将对所有任务进行迭代以确定它们的“不良”,并且最高价值的任务被强行杀死(实际的调用链为by the page fault handlerselect_bad_process()select_bad_process())。

任务的“坏处”取决于多个因素:

  • 其虚拟内存中有多少页。
  • 它拥有多少个SWAP条目。
  • 进程使用多少内存(总字节数/页面大小)。
  • 如果是oom_evaluate_task(),因为它负责OOM,它将获得最高分。
  • 如果是初始化进程或内核线程,则将其忽略。

[在较早的内核版本中,oom_evaluate_task()函数曾经更加复杂,例如考虑了不同的缩放因子和oom_badness(),但对其进行了更新以使其“尽可能简单且可预测”。

© www.soinside.com 2019 - 2024. All rights reserved.