2

I want to use the latest G1 garbage collector however I am running into a situation where I hit memory allocation errors when using it. I believe this is because it is releasing memory back to the OS, and the OS is then not allowing the JVM to have it back when it requested since this does not happen with the CMS collector. The particular server I am running on has been functioning fine with the CMS collector (besides some less than ideal GC pauses), as soon as I move it to G1 it hits these allocation errors after about 6 hours of running and the JVM exists.

It is not clear if it is possible to prevent this from happening with the G1 collector but I was hoping someone in the community would have an answer.

Thanks!

Casey Jordan
  • 1,204
  • 1
  • 20
  • 39
  • 2
    The `-Xms` option sets the initial heap allocated for the JVM. I would think this might prevent the allocated heap from being released back to the OS. – Steve Kuo Sep 06 '16 at 17:19
  • Have you actually determined that "the OS is then not allowing the JVM to have it back"? Or is it just an inference from observing no failures with CMS? – the8472 Sep 06 '16 at 18:21
  • I don't have as strong of evidence as I would like that the OS is not allowing the JVM to have the memory back, but it seems to be the case since I know one of the major features of G1 is that it will release memory back to the OS. I figure the best way to determine if this is the root cause it to disable it and test again. – Casey Jordan Sep 07 '16 at 19:03
  • G1 on JDK7 is not production ready. On JDK8 it could be failing for any number of reasons, but it would definitely let you know if it requested memory of the OS and the OS said -ENOMEM. Would need detailed logs around the failure time to offer targeted advice. – Jonah Benton Sep 08 '16 at 01:54

1 Answers1

1

-XX:MaxHeapFreeRatio=100 should prevent it from downsizing the heap.

That said, it would be point at a deeper problem if this actually fixed the jvm crashes. Either there is enough memory on the machine to all allocation requests from applications or there isn't. If you let the JVM stay greedy then something else would have to suffer.

the8472
  • 40,999
  • 5
  • 70
  • 122