此内容没有您所选择的语言版本。

2.8. Swapping and Out of Memory Tips


Memory Swapping

Swapping pages out to disk can introduce latency in any environment. To ensure low latency, the best strategy is to have enough memory in your systems so that swapping is not necessary. Always size the physical RAM as appropriate for your application and system. Use vmstat to monitor memory usage and watch the si (swap in) and so (swap out) fields. It is optimal that they remain zero as much as possible.

Procedure 2.8. Out of Memory (OOM)

Out of Memory (OOM) refers to a computing state where all available memory, including swap space, has been allocated. Normally this will cause the system to panic and stop functioning as expected. There is a switch that controls OOM behavior in /proc/sys/vm/panic_on_oom. When set to 1 the kernel will panic on OOM. The default setting is 0 which instructs the kernel to call a function named oom_killer on an OOM. Usually, oom_killer can kill rogue processes and the system will survive.
  1. The easiest way to change this is to echo the new value to /proc/sys/vm/panic_on_oom.
    ~]# cat /proc/sys/vm/panic_on_oom
    0
    
    ~]# echo 1 > /proc/sys/vm/panic_on_oom
    
    ~]# cat /proc/sys/vm/panic_on_oom
    1
    

    Note

    It is recommended that you make the $RT; kernel panic on OOM. When the system has encountered an OOM state, it is no longer deterministic.
  2. It is also possible to prioritize which processes get killed by adjusting the oom_killer score. In /proc/PID/ there are two files named oom_adj and oom_score. Valid scores for oom_adj are in the range -16 to +15. This value is used to calculate the 'badness' of the process using an algorithm that also takes into account how long the process has been running, among other factors. To see the current oom_killer score, view the oom_score for the process. oom_killer will kill processes with the highest scores first.
    This example adjusts the oom_score of a process with a PID of 12465 to make it less likely that oom_killer will kill it.
    ~]# cat /proc/12465/oom_score
    79872
    
    ~]# echo -5 > /proc/12465/oom_adj
    
    ~]# cat /proc/12465/oom_score
    78
    
  3. There is also a special value of -17, which disables oom_killer for that process. In the example below, oom_score returns a value of O, indicating that this process would not be killed.
    ~]# cat /proc/12465/oom_score
    78
    
    ~]# echo -17 > /proc/12465/oom_adj
    
    ~]# cat /proc/12465/oom_score
    0
    
Related Manual Pages

For more information, or for further reading, the following man pages are related to the information given in this section.

  • swapon(2)
  • swapon(8)
  • vmstat(8)
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部