How does the OOM-Killer select a task to kill?

 

How does the OOM-Killer select a task to kill?

 SOLUTION 已验证 - 已更新 2017年二月28日16:41 - 

English 

环境

  • Red Hat Enterprise Linux ( All version)

问题

  • How does the OOM-Killer select a task to kill?

决议

When a system runs out of memory and OOM-killer is needed to set memory free in order to allow new memory allocations, any process in the system's task list is a candidate to be killed. This does not necessarily mean that the process which has the biggest virtual memory area will be a direct first hit, however it has its chances of being killed as well.

When the routine OOM-killer is called, it iterates over the task list calculating a score, called 'badness', for each process enlisted there. In its context the badness calculator utilizes a fairly simple formula that tries to select the better task to kill in a system following this logic:

  1. try to lose the minimum amount of work done;
  2. permit to recover a large amount of memory;
  3. try to not kill anything innocent of allocating large amount of memory;
  4. try to kill the minimum amount of tasks at a time (one process is always the goal);
  5. try to kill what end-users expect the kernel should kill;

When OOM-killer is calculating a given process badness, the first thing taken into account is the process total virtual memory size (vm), in pages, and this number will serve as the base for all further OOM-killer 'badness' score calculations. While one might think that processes which have big "vms" are prone to be first selected by OOM-killer, the calculations also take into consideration other data to adjust a process score, thus giving to it a chance of not being killed even if it is the biggest memory allocator in the box.

Below, these are other things that will adjust a process 'badness' score:

  • Forked childs: for each child which has its own 'vm', a half of that vm is accounted to a task points score;
  • CPU time: a task gets its score reduced by a factor rendered from the integer part of the square root of its CPU running time. So last longing tasks or tasks runing often are adjusted to score less, even if they are allocating big chunks of memory;
  • Niced processes: a niced process is considered less important, so they get their score doubled;
  • Superuser processes: As they are usually considered more important, they get their score reduced by a factor of 4;
  • External adjustment: System administrator can do external adjustments to this calculations, in order to prevent oom-killer to kill an undesirable process which otherwise would be killed in a memory shortage.

Further information on OOM-Killer:

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值