← Back to context

Comment by akdev1l

21 hours ago

Linux can be configured to disable memory overcommit

sysctl -w vm.overcommit_memory=2 sysctl -w vm.overcommit_ratio=50

It is probably a bad idea to do that though as it will limit the amount of virtual address space an application can use

Note that the fork()/execve() semantics of Linux pretty much depend on memory overcommit. You may get weird OOM crashes when there is seemingly no memory pressure, if you turn overcommit off.

In the short time between fork() and execve(), the new process duplicates the entire virtual memory of the old one. None of this is physically allocated due to copy-on-write, but still all counts as virtual memory.

  • Has anybody tried a compromise? Like, the program forks and overcommit is ignored for it for a 1 second grace period? I know it would be more complicated than that, but something along those general lines.