gpt4 book ai didi

linux - Linux 中的 vm.overcommit_ratio 是什么?

转载 作者:行者123 更新时间:2023-12-05 07:44:51 28 4
gpt4 key购买 nike

这是我当前的设置:

vm.overcommit_ratio = 50 (default)
vm.overcommit_memory = 2

和当前内存使用情况:

[localhost~]$ free -g
total used free shared buffers cached
Mem: 47 46 0 0 0 45
-/+ buffers/cache: 1 45
Swap: 47 0 47

根据 documentation我的理解是:

vm.overcommit_memory = 2 不允许过量使用内存超过 50% 的 RAM (因为 vm.overcommit_ratio 是 50) 但我仍然可以看到当前的内存使用情况是 47 GB 中的 46 GB。

我是不是误会了什么?

最佳答案

我相信 vm.overcommit_memory 的默认值是 0 而不是 2。overcommit_ratio 是否只与模式 2 相关?我想是的,但我不完全确定。

来自 https://www.kernel.org/doc/Documentation/vm/overcommit-accounting

0 - Heuristic overcommit handling. Obvious overcommits of addressspace are refused. Used for a typical system. It ensures a seriouslywild allocation fails while allowing overcommit to reduce swapusage. root is allowed to allocate slightly more memory in thismode. This is the default.

1 - Always overcommit. Appropriate for some scientific applications.Classic example is code using sparse arrays and just relying on thevirtual memory consisting almost entirely of zero pages.

2 - Don't overcommit. The total address space commit for the systemis not permitted to exceed swap + a configurable amount (default is50%) of physical RAM. Depending on the amount you use, in mostsituations this means a process will not be killed while accessingpages but will receive errors on memory allocation as appropriate.

而不是 free -g 我假设四舍五入为零,你可能想使用 free -m 或只是 free 是更精确。

这可能也很有趣:

cat/proc/meminfo|grep 提交

关于linux - Linux 中的 vm.overcommit_ratio 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42527334/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com