0

I am running centos 6.4 with 2.6.32-358.6.2.el6.x86_64 which is actually running as a xen vm with

ram 2 GB

On this i have set

cat /proc/sys/vm/overcommit_memory  
2

But when i try to start my java application its showing

java.io.IOException: Cannot run program "/bin/bash": java.io.IOException: error=12, Cannot allocate memory
Caused by: java.io.IOException: java.io.IOException: error=12, Cannot allocate memory

But actually this machine has 1.5 gb free memory.

when i set

echo 0 > /proc/sys/vm/overcommit_memory

Everything is working fine,

i thought over committing memory allow me to use more virtual ram(swap+real ram),but why its failing even with more free real ram.

Kevin Parker
  • 757
  • 1
  • 13
  • 29
  • It sounds like you already have a perfectly fine solution: Disable overcommit and make Linux behave like Unix. As a side benefit this spares you from [the OOM killer](http://serverfault.com/questions/141988/avoid-linux-out-of-memory-application-teardown). – voretaq7 Jun 04 '13 at 15:14
  • i dont need over commit,but this error forced me to check over commit and it was already enabled.so i am looking for the reason for this behaviour. – Kevin Parker Jun 04 '13 at 15:20
  • If you don't allow overcommit and e.g. a big Java process needs to `fork()` it will need twice the memory even if the memory is never actually used thanks to COW (Copy on Write). To workaround the problem you either set `overcommit_ratio` to higher to 100 (in which case you're in reality allowing limited overcommitting) or increase swap space a lot. The "correct" value for `overcommit_ratio` will depend on your workload and there're no "safe" value higher than 100. – Mikko Rantalainen Jan 08 '18 at 16:37
  • See also: `grep Committed_AS /proc/meminfo` which should give you some idea how much the system has already granted memory allocations. That may be a lot more than RAM+swap if you allow overcommit. I'm currently running Committed_AS around 30 GB and the system has 16 GB of RAM and 8 GB swap on SSD. – Mikko Rantalainen Jan 08 '18 at 16:39

1 Answers1

2

From this guide:

2 — The kernel fails requests for memory that add up to all of swap plus the percent of physical RAM specified in /proc/sys/vm/overcommit_ratio. This setting is best for those who desire less risk of memory overcommitment.

If you have less than 2 GB of swap, then the kernel will deny the request if overcommit_ratio is set too low. Having it set to "1" allows overcommitting and is good for performance.

Nathan C
  • 14,901
  • 4
  • 42
  • 62
  • can u please elaborate,my commit_ratio is 80% and swap is 512 – Kevin Parker Jun 04 '13 at 15:27
  • 1
    In that scenerio if 1638+512 MB of RAM was requested, it would be just denied. The notes state that it's not recommended to use "2" as your option if you have less swap than RAM. – Nathan C Jun 04 '13 at 15:29
  • And in my experience Java will gobble up any RAM it can unless specified with -Xms (I think that's the switch), which results in those overcommit errors. – Nathan C Jun 04 '13 at 15:31