-1

I am recently seeing some weird behaviour with G1GC. I am using java 1.8.0_152 and have set GC algorithm as G1GC with string deduplication. Recently I see that the memory footprint of java process (got from top -c) is 6.8g while the actual heap size (S0U + S1U + EU+ OU) 4 gb. With 260 threads (using default xss 1MB) I see that 2.54gb memory is taken by G1 collector itself which seems quite large.. Am I missing something here..Can someone please help me out here...as to why G1GC itself is taking so much memory..What will happen if I heap increases to 6 gb...Will G1GC try to take more than the existing RAM (8gb) and fail or will it do a full GC (which I believe it should) at that time

My XMX is 7GB

It looks like G1GC internals are taking extra memory. I ran a full GC through jstat and the java process footprint increased by 0.1gb. This makes me think that G1GC internals are taking this memory. Apart from reducing the RAM is there anyway else to ensure that G1GC itnernals don't take too much memory

prashant
  • 1,382
  • 1
  • 13
  • 19
  • 3
    Possible duplicate of [Huge system memory usage of java applications compared to heap usage](https://stackoverflow.com/questions/38223821/huge-system-memory-usage-of-java-applications-compared-to-heap-usage) – the8472 Apr 19 '19 at 16:57
  • Not a duplicate, I am aware that the Grabage Collector needs space to grow...My question here is when this happens and it exceeds the maximum RAM available what happens.. – prashant Apr 19 '19 at 17:13
  • That's not clear from your question. You don't mention what Xmx you have configured and you are mixing OS-observable memory statistics (RSS? VSZ?) with heap-only memory statistics, which does not make much sense as explained by the linked question. – the8472 Apr 19 '19 at 17:18
  • Updated XMX value – prashant Apr 19 '19 at 18:30
  • I'd suggest that you first update to a more recent Java 8 version to rule out issues that have been fixed already, update 152 is pretty old by now. – Mark Rotteveel Apr 20 '19 at 10:10

1 Answers1

1

With -Xmx=7G G1 may take up to 7GB RAM for the java object heap plus additional memory for managing that heap. Additionally the JVM (not G1) may take varying amounts of memory for memory-mapped files, loaded class data, compiled methods, direct byte buffers and other internal data. Additionally any native libraries loaded into the process may also take up memory not tracked by any java-specific mechanisms.

What your operating system does once physical memory is exhausted depends on configuration. It may swap to disk, try to compress memory or kill the process. The JVM may detect some but not all of those conditions before getting killed and throw an OOME instead.

the8472
  • 40,999
  • 5
  • 70
  • 122
  • Will g1gc not do a full GC before JVM takes 8GB ram ?? – prashant Apr 19 '19 at 18:45
  • GCs only run on heap memory pressure. If you're running out of memory due to non-heap allocations then a GC won't help. – the8472 Apr 19 '19 at 20:09
  • There is no non heap allocation through code...yesterday i trigerred a full gc and saw res size increase by .1 gb. Is this because i have given high value for xmx and left only 1gb for the os – prashant Apr 20 '19 at 04:45
  • 1
    Also each Thread has its own stack that might cost you (on 64 bit Linux by default) 1MB native memory each, override with: `-Xss` and/or verify with `-XX:+PrintFlagsFinal` and look for: ThreadStackSize. – JohannesB Feb 11 '21 at 21:40