brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: vm.overcommit_memory decides whether Linux promises more memory than it has

Linux
~/tips/tip-linux-vm-overcommit-memory

sysctl vm.overcommit_memory

Understand why a program got memory it could not use, and when to change the policy.

Linux usually says yes when a program asks for memory, even when it does not have that much free. The program only gets a problem later, when it actually uses it. One setting controls that policy.

sysctl vm.overcommit_memory

The kernel documentation describes three values. 0, the default, is a heuristic: requests that are obviously too large for RAM plus swap are refused, the rest is allowed. 1 pretends there is always enough memory until it really runs out. 2 never overcommits: the total committed memory may not exceed swap plus a percentage of RAM, set by vm.overcommit_ratio, which defaults to 50.

Some software asks for a specific value. Redis, for example, warns at startup that background saving can fail and recommends 1, because it forks a copy of itself that would look like it needs twice the memory. Set it like any sysctl:

echo 'vm.overcommit_memory = 1' | sudo tee /etc/sysctl.d/90-overcommit.conf

I would only change it when a program asks for it. With 1, a system that really runs out depends fully on the OOM killer, which then picks a process to kill. With 2, programs get clear allocation errors instead, but the default ratio of 50 is low for a box with little swap, and things like browsers or Java can fail to start long before memory looks full. To see how much is committed now, compare Committed_AS with CommitLimit in /proc/meminfo.

Further reading: Documentation for /proc/sys/vm/, Overcommit accounting

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link