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

Linux kernel-vm memory related parameters

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

View method:

1. Sysctl-a

2 、 cat / proc/sys/vm/overcommit_memory

1. Overcommit_memory

Introduction in kernel source code:

This value contains a flag that enables memory overcommitment.

When this flag is 0, the kernel attempts to estimate (estimated) the amount

Of free memory left when userspace requests more memory.

When this flag is 1, the kernel pretends there is always enough

Memory until it actually runs out.

When this flag is 2, the kernel uses a "never overcommit"

Policy that attempts to prevent any overcommit of memory.

This feature can be very useful because there are a lot of

Programs that malloc () huge amounts of memory "just-in-case"

And don't use much of it.

The default value is 0.

The file specifies the kernel policy for memory allocation, which can be 0, 1, 2.

0: (default) means 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 the error is returned to the application process. 0 is the heuristic overcommitting handle, which minimizes the use of swap. Root can allocate slightly more memory than the average user.

1: indicates that the kernel allows all physical memory to be allocated, regardless of the current memory state, allowing CommitLimit to be exceeded until memory is used up. It is not recommended to set it to 1 on the database server to avoid using swap. 1.

2: indicates that the CommitLimit value cannot be exceeded

II. Vm.overcommit_ratio

The default value is 50 (that is, 50%)

This parameter value will only take effect in the case of vm.overcommit_memory=2.

Execute grep-I commit / proc/meminfo

See the CommitLimit and Committed_As parameters.

CommitLimit is an upper limit for memory allocation, CommitLimit = physical memory * overcommit_ratio (default 50%) + swap size

Committed_As is the amount of memory that has been allocated.

General situation:

Situation ①

Overcomot_memory = 0m.overwritten ratio = 50-> max_num malloc size = 7.137890GB

Situation ②

Overcomot_memory = 2, vm.overcommit_ratio = 50-> max_num malloc size = 3.958923GB

Situation ③

Overcomot_memory = 2, vm.overcommit_ratio = 99-> max_nummalloc size = 6.722099 GB

III. Vm.min_free_kbytes

Cat / proc/sys/vm/min_free_kbytes centos6.4 defaults to 66m

67584

This file represents the minimum amount of free memory (Kbytes) that forces Linux VM to reserve.

When the available memory is lower than this parameter, the system begins to reclaim cache memory to free up memory until the available memory is greater than this value.

Vm.vfs_cache_pressure

This item indicates the kernel's tendency to reclaim memory for directory and inode cache:

The default value of 100 means that the kernel will keep directory and inode cache at a reasonable percentage based on pagecache and swapcache

Lowering this value below 100 will cause the kernel to tend to retain directory and inode cache

Increasing this value by more than 100 will cause the kernel to tend to recycle directory and inode cache.

Vm.dirty_background_ratio defaults to 10

When the number of dirty pages of all global system processes reaches the percentage of the total memory of the system, background write-back processes such as pdflush/flush/kdmflush will be triggered to run.

Set vm.dirty_background_ratio to 5-10 and set vm.dirty_ratio to about twice as much to ensure that dirty data can be continuously flushed to disk, avoiding instant write and serious waiting (similar to innodb_max_dirty_pages_pct in MySQL)

Vm.dirty_ratio defaults to 20

When the number of dirty pages in a single process reaches the percentage of the total memory of the system, background write-back processes such as pdflush/flush/kdmflush will be triggered to run.

Vm.panic_on_oom defaults to 0 and 1 means to disable this feature.

A value equal to 0 means that when memory is exhausted, the kernel triggers OOM~~~~ killer to kill the most memory-consuming process.

When OOM Killer is started, the score / proc//oom_score of each current process is automatically calculated by observing the process. The higher the score, the easier it is to be dropped by kill.

And the score is mainly calculated with reference to / proc//oom_adj. Oom_adj values range from-17 to 15. A value equal to-17:00 means that the process will not be dropped by oom killer kill at any time (applicable to mysql).

/ proc/ / oom_adj, the weight of the pid process killed by oom killer is between [- 17]. The higher the weight, the more likely it is to be selected by oom killer, and-17 means that it is prohibited from being dropped by kill.

/ proc/ / oom_score, the current kill score of the pid process, the higher the score, the more likely it is to be kill. This value is based on the result of the oom_adj operation and is the main reference of oom_killer.

There are 2 configurable options under sysctl:

Vm.panic_on_oom = 0 # whether the kernel directly panic when there is not enough memory

Vm.oom_kill_allocating_task = 1 # oom-killer whether to select the process that is currently requesting memory for kill

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