`
baiguomeng
  • 浏览: 998379 次
文章分类
社区版块
存档分类
最新评论

OOM Killer

 
阅读更多

OOM Killer


The functions, code excerpts and comments discussed below here are from mm/oom_kill.c unless otherwise noted.

It is the job of the linux 'oom killer' to sacrifice one or more processes in order to free up memory for the system when all else fails. It will also kill any process sharing the same mm_struct as the selected process, for obvious reasons. Any particular process leader may be immunized against the oom killer if the value of its /proc/<pid>/oomadj is set to the constant OOM_DISABLE (currently defined as -17).

The function which does the actual scoring of a process in the effort to find the best candidate for elimination is called badness(), which results from the following call chain:


_alloc_pages -> out_of_memory() -> select_bad_process() -> badness()

The comments to badness() pretty well speak for themselves:

badness() works by accumulating 'points' for each process it examines and returning them to select_bad_process(). The process with the highest number of points, loses and is ultimately eliminated, unless it is already in the midst of freeing up memory on its own.

The scoring of a process starts with the size of its resident memory:

The independent memory size of any child (except a kernel thread) is added to the score:

'Niced' processes have their scores increased, and long running processes have their scores decreased:


Processes with CAP_SYS_ADMIN and CAP_SYS_RAWIO, respectively, each have their scores reduced:


Finally the accumulated score is bitshifted by the user-settable value of /proc/<pid>/oomadj:


So the ideal candidate for liquidation is a recently started, non privileged process which together with its children uses lots of memory, has been nice'd, and does no raw I/O. Something like a nohup'd parallel kernel build (which is not a bad choice since all results are saved to disk and very little work is lost when a 'make' is terminated).


分享到:
评论

相关推荐

    有关OOM KILLER的一些理解

    OOM Killer,全称为Out of Memory Killer,是Linux内核中的一种机制,用于处理系统内存不足的情况。当系统内存耗尽时,为了避免整个系统的崩溃,OOM Killer会选择并终止一些进程来释放内存,从而确保系统的稳定运行...

    Linux系统的OOM Killer处理机制.docx

    Linux系统中的OOM Killer机制,即“Out of Memory Killer”,是内核中用于处理内存不足状况的一种紧急措施。本文将深入探讨Linux系统的OOM Killer处理机制,分析其触发条件、工作原理以及如何优化配置以保障系统稳定...

    MySQL OOM 系统二 OOM Killer

    在Linux系统中,当内存资源紧张,即将耗尽时,为避免系统崩溃,Linux内核引入了一种称为OOM (Out Of Memory) Killer的机制。OOM Killer会选择性地杀死某些进程以回收内存。这一机制主要针对系统可用内存(包括Swap...

    heart_oom_protect:Erlang库可保护心脏免受Linux内核的OOM Killer的杀害

    当Linux系统面临内存不足的压力时,内核会启动一个称为“Out-of-Memory (OOM) Killer”的机制来防止系统崩溃。然而,OOM Killer可能会选择终止重要的进程,包括Erlang应用程序。针对这种情况,有一个名为“heart_oom...

    lab8_oom实验说明1

    《理解Linux OOM Killer机制:从lab8_oom实验入手》 Linux操作系统的OOM (Out-Of-Memory) Killer是一个重要的内存管理机制,用于处理系统内存不足的情况。当系统资源极度紧张,无法分配新的内存时,OOM Killer会...

    oom.rar_legacy

    标题“oom.rar_legacy”暗示了我们正在探讨与操作系统内存管理中的“Out of Memory”(OOM) killer相关的遗留问题。在Linux系统中,当系统内存不足时,OOM killer会被触发,它会选择并终止某些进程以回收内存,从而...

    安卓内存OOM分析

    如果一个应用持续占用大量内存,系统为了保护整体稳定性和用户体验,可能会触发OOM Killer,选择性地杀死一些内存占用高的进程。 **内存泄露分析:** 内存泄露是导致OOM的常见原因之一。当一个对象不再使用但仍然被...

    Android 内核分析报告4

    2. **触发时机:** OOMKiller通常在尝试分配内存失败时触发,位于`mm/page_alloc.c`中的`__alloc_pages_may_oom`函数会调用`oom_kill.c`中的`out_of_memory`函数来选择并终止一个进程。而LMK则是在内存紧张时主动...

    Android LMK机制简介

    虽然Linux的oom killer能够应对大多数低内存情况,但在Android这种高度定制化的环境中,oom killer存在一些明显的局限性: - **响应速度慢**:oom killer通常在内存极度紧张时才会被触发,此时可能已经对用户体验...

    【性能】OOM原理解析:LowMemoryKiller原理

    1 概述 Android的设计理念之一,便是应用程序退出,但进程还会继续存在系统以便...Android基于Linux的系统,其实Linux有类似的内存管理策略——OOM killer,全称(Out Of Memory Killer), OOM的策略更多的是用于分配内存

    MySQL Slave 触发 oom-killer解决方法

    Mar 9 11:29:16 xxxxxx kernel: mysqld invoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0, oom_score_adj=0 Mar 9 11:29:16 xxxxxx kernel: mysqld cpuset=/ mems_allowed=0 Mar 9 11:29:16 x

    Linux中使用cgroups控制内存.docx

    可以通过 cat memory.oom_control 来查看当前设置以及目前是否触发了 oom,echo 1 memory.oom_control 就可以禁用 oom killer。 usage_in_bytes、max_usage_in_bytes、failcnt 则分别对应当前使用量,最高使用量和...

    安卓kernel 内存回收机制

    3. OOM(Out Of Memory)管理:当系统内存耗尽,无法通过回收内存来满足进程的内存请求时,就会触发OOM Killer。OOM Killer会根据进程的重要性(比如进程的UID、运行时间、内存占用情况等)选择并杀死某个进程以释放...

    嵌入式开发经验:Android系统的内存管理研究

    Linux内存管理的基础概念包括反向映射机制、页面回收机制和OOM Killer(内存溢出杀手)。反向映射机制通过物理页面建立链表,链接到相关的虚拟内存区域,这样可以快速定位和管理页面。这种机制在Linux 2.6中得到了...

    Understanding The Linux Virtual Memory Manager.rar

    oom killer在系统面临内存耗尽时,会选择杀死一些低优先级的进程,以保障关键服务的正常运行。 总的来说,理解Linux虚拟内存管理对于系统管理员、内核开发者和性能优化工程师至关重要。通过深入学习这一主题,我们...

    linux内存操作.rar

    8. **oom killer**:当系统出现严重的内存不足时,内核会启动OOM Killer,选择某些进程进行杀死,以释放内存供更重要的进程使用。 9. **内存泄漏检测**:Linux系统中可以使用 Valgrind 等工具进行内存泄漏检测,...

    藏经阁-私有云迁移问题解决方法.pdf

    * 进程运行一段时间会挂掉,查看系统日志发现是被 OOM Killer 给结束掉了。 解决方案: * 对于 redirect 指令问题,可以通过修改 Tomcat 的模板,在 server.xml 中增加配置来解决。 * 对于中文乱码问题,可以通过...

Global site tag (gtag.js) - Google Analytics