By default Linux has a somewhat brain-damaged concept of memory management: it lets you allocate more memory than your system has, then randomly shoots a process in the head when it gets in trouble. (The actual semantics of what gets killed are more complex than that – Google “Linux OOM Killer” for lots of details and arguments about whether it’s a good or bad thing).
To restore some semblance of sanity to your memory management:
- Disable the OOM Killer (Put
vm.oom-kill = 0in /etc/sysctl.conf)
- Disable memory overcommit (Put
vm.overcommit_memory = 2in /etc/sysctl.conf)
Note that this is a trinary value: 0 = “estimate if we have enough RAM”, 1 = “Always say yes”, 2 = “say no if we don’t have the memory”)
These settings will make Linux behave in the traditional way (if a process requests more memory than is available malloc() will fail and the process requesting the memory is expected to cope with that failure).
Reboot your machine to make it reload
/etc/sysctl.conf, or use the
proc file system to enable right away, without reboot:
echo 2 > /proc/sys/vm/overcommit_memory