pgy*_*esh 3 linux kernel memory virtual-memory
这是我当前的设置:
vm.overcommit_ratio = 50 (default)
vm.overcommit_memory = 2
Run Code Online (Sandbox Code Playgroud)
和当前内存使用情况:
[localhost~]$ free -g
total used free shared buffers cached
Mem: 47 46 0 0 0 45
-/+ buffers/cache: 1 45
Swap: 47 0 47
Run Code Online (Sandbox Code Playgroud)
根据文档我的理解是:
vm.overcommit_memory = 2不允许过度使用内存超过 RAM 的 50% (as vm.overcommit_ratio is 50),但我仍然可以看到当前内存使用量为 47 GB 中的 46 GB。
我是不是误会了什么?
实际上,设置 vm.overcommit_memory=2 确实允许过量使用。如果将 overcommit_ratio 设置为(例如)200,则可以将内存提交到 swap +(RAM * 200/100) 的范围。
内核文档稍有误导性,暗示“2”表示不要过度提交 - 它意味着提交到此限制,在 overcommit_ratio (这是一个用词不当,因为它实际上是一个百分比)大于 100 的情况下,确实允许过度投入。
vm.overcommit_memory 更准确地描述为设置过度使用的限制,默认情况下不允许任何过度使用。
您可以看到提交限制:
$free -m | awk '$1 ~/[Mm]em/ {print $2}' ; sysctl -a 2>/dev/null | grep vm.over ; grep -i commitlimit /proc/meminfo
vm.overcommit_kbytes = 0
vm.overcommit_memory = 2
vm.overcommit_ratio = 800
CommitLimit: 23449596 kB
Run Code Online (Sandbox Code Playgroud)