Why is my VPS running out of memory?
I have a Linux Virtual Private Server with 1GB memory, but I keep getting errors like:
fork failed: Cannot allocate memory
However, I don't think I'm short on memory. If I run free:
root@server44:~# free -m
total used free shared buffers cached
Mem: 1024 133 890 0 0 0
-/+ buffers/cache: 133 890
Swap: 0 0 0
root@server44:~# man swapon
man: fork failed: Cannot allocate memory
I have 890 MB free, but fork is failing. Any idea why? Is the server my server is running on running out of memory? My host is FsckVPS running HyperVM.
What virtualization technology are you using? With OpenVZ/Virtuozo at least, the 'free' command does not show your actual memory available. Often it shows much larger than the amount that is actually allocated to your VPS slice.
In addition, there are several different 'memory' limits that limit different types of memory (in OpenVZ terms they are kmemsize, lockedpages, privvmpages, shmpages, vmguarpages, oomguarpages, etc).
If you are using OpenVZ, check /proc/user_beancounters to see what limit you are hitting, check in the 'failcnt' column.
Could it be that your host has overly oversold the RAM on the host that is running your VM? It could be that you only have 128Mb of "dedicated" RAM and the rest available for burst if no other VM is using it at the time. If you tell us more detail about the environment you are working in (which VM technology, possible which hosting provider and which of their products) we might be able to tell you have to check this.
Overselling RAM resource on a VM host is generally a bad idea in my opinion, but many hosting providers do it if the technology permits.