Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand Linux kernel parameters overcommit_memory and OOM killer

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to understand the Linux kernel parameters overcommit_memory and OOM killer, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

What are Linux Overcommit and OOM?

Overcommit_memory is a kernel strategy for allocating memory. It has three optional values: 0, 1, and 2.

0. Indicates that the kernel will check whether there is enough memory available for the application process; if there is enough memory available, the memory request is allowed; otherwise, the memory request fails

And return the error to the application process.

1. Indicates that the kernel allows all physical memory to be allocated, regardless of the current memory state.

two。 Indicates that the kernel allows more than all physical memory and swap space to be allocated.

Linux replies "yes" to most requests for memory so that it can run more and larger programs. Because memory will not be used immediately after applying for memory.

This technique is called Overcommit.

OOM killer (OOM=out-of-memory) occurs when linux finds that it is out of memory. It will choose to kill some processes.

(a user-mode process, not a kernel thread) to free memory.

For example, if the following error message is found under Linux, OOM killer has occurred in the system.

# dmesg | grep redis | grep "oom-killer"

Redis-server invoked oom-killer: gfp_mask=0x280da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x200da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x200da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x200da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x280da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x200da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x200da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0xd0, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x280da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x280da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0xd0, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x280da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0xd0, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0xd0, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0xd0, order=0, oom_adj=0, oom_score_adj=0

Redis-server invoked oom-killer: gfp_mask=0x280da, order=0, oom_adj=0, oom_score_adj=0

When oom-killer occurs, linux chooses to kill the process, for example:

Out of memory: Kill process 21809 (redis-server) score 951 or sacrifice child

Killed process 21809, UID 0, (redis-server) total-vm:33466920kB, anon-rss:32324096kB, file-rss:100kB

Which process to kill depends on the function of selecting the process. The function of selecting the process is the oom_badness function (in mm/oom_kill.c), which is

The number of points for each process is calculated (0,1000).

The higher the points, the more likely the process is to be killed. The number of points in each process is related to oom_score_adj, and oom_score_adj can be

Setting (- 1000 lowest, 1000 highest).

The key to understanding memory overcommit: commit (or overcommit) is for memory request, memory request is not equal to memory allocation, memory

It is allocated only when it is actually used.

Note:

There are three ways to modify the value of Linux vm.overcommit_memory:

1)。 Log in to Linux as root, edit / etc/sysctl.conf, change vm.overcommit_memory=1, and then sysctl-p to make the configuration file effective

2). Sysctl vm.overcommit_memory=1

3). Echo 1 > / proc/sys/vm/overcommit_memory

After reading the above, have you mastered how to understand the Linux kernel parameters overcommit_memory and OOM killer? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report