Linux – Can’t allocate memory, although there’s free memory

centoslinuxmemory

I have a web server that is behaving strangely lately. To keep things brief, look at the following:

[root@xxxxx test]# ls -lah
-bash: fork: Cannot allocate memory
[root@xxxxx test]# free -m
             total       used       free     shared    buffers     cached
Mem:          1285        899        386          0          0          0
-/+ buffers/cache:        899        386
Swap:            0          0          0

Now, why would this happen? Any other information I should provide to get help?

Best Answer

You're on a Virtuozzo or OpenVZ PVS (Pseudo-Virtual Server), I see, which makes the concept of "memory" a fairly specious one, at best. Your provider has limited the amount of "overcommitted" memory you can use, which you've bumped up against. That "total memory" number you see in free, by the way, has no relation to reality in a VZ PVS -- the provider can configure VZ to show whatever number they want in there, regardless of what resources have actually been allocated to you.

You need to lodge this support request with your provider, as they're the only ones who can help you (we can't see what the configuration for your PVS is, let alone change it), and if you don't get the support you need from them, I'd highly recommend switching to a provider that can give you (a) a proper VPS that actually has the memory available that it says it does (ie. NOT a VZ-based PVS), and (b) proper support for what you've paid for.