0

JVM uses G1 GC, Old Gen heap is increasing continuously, I have left my application for 5 days and below is the heap usage -

jstat -gcutil   1
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT    CGC    CGCT     GCT   
  0.00 100.00  43.27  72.98  96.98  89.46   7870   42.034     0    0.000     6    0.033   42.066
    JVM version is 11.0.14.1+1
    using thread-local object allocation.
    Garbage-First (G1) GC with 8 thread(s)
    
    Heap Configuration:
       MinHeapFreeRatio         = 40
       MaxHeapFreeRatio         = 70
       MaxHeapSize              = 1342177280 (1280.0MB)
       NewSize                  = 1363144 (1.2999954223632812MB)
       MaxNewSize               = 805306368 (768.0MB)
       OldSize                  = 5452592 (5.1999969482421875MB)
       NewRatio                 = 2
       SurvivorRatio            = 8
       MetaspaceSize            = 21807104 (20.796875MB)
       CompressedClassSpaceSize = 1073741824 (1024.0MB)
       MaxMetaspaceSize         = 17592186044415 MB
       G1HeapRegionSize         = 1048576 (1.0MB)
    
    Heap Usage:
    G1 Heap:
       regions  = 1280
       capacity = 1342177280 (1280.0MB)
       used     = 469777800 (448.01502227783203MB)
       free     = 872399480 (831.984977722168MB)
       35.00117361545563% used
    G1 Young Generation:
    Eden Space:
       regions  = 106
       capacity = 842006528 (803.0MB)
       used     = 111149056 (106.0MB)
       free     = 730857472 (697.0MB)
       13.20049813200498% used
    Survivor Space:
       regions  = 4
       capacity = 4194304 (4.0MB)
       used     = 4194304 (4.0MB)
       free     = 0 (0.0MB)
       100.0% used
    G1 Old Generation:
       regions  = 340
       capacity = 495976448 (473.0MB)
       used     = 354434440 (338.01502227783203MB)
       free     = 141542008 (134.98497772216797MB)
       71.46194974161354% used

On manually trigger of Full GC, the Old Gen heap is getting cleared. I tried below command to trigger Full GC ->

jmap -clstats 1

JVM version is 11.0.14.1+1

using thread-local object allocation.
Garbage-First (G1) GC with 8 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 1342177280 (1280.0MB)
   NewSize                  = 1363144 (1.2999954223632812MB)
   MaxNewSize               = 805306368 (768.0MB)
   OldSize                  = 5452592 (5.1999969482421875MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 1048576 (1.0MB)

Heap Usage:
G1 Heap:
   regions  = 1280
   capacity = 1342177280 (1280.0MB)
   used     = 304937040 (290.8106231689453MB)
   free     = 1037240240 (989.1893768310547MB)
   22.719579935073853% used
G1 Young Generation:
Eden Space:
   regions  = 218
   capacity = 846200832 (807.0MB)
   used     = 228589568 (218.0MB)
   free     = 617611264 (589.0MB)
   27.01363073110285% used
Survivor Space:
   regions  = 0
   capacity = 0 (0.0MB)
   used     = 0 (0.0MB)
   free     = 0 (0.0MB)
   0.0% used
G1 Old Generation:
   regions  = 78
   capacity = 495976448 (473.0MB)
   used     = 76347472 (72.81062316894531MB)
   free     = 419628976 (400.1893768310547MB)
   15.393366420495838% used

Each time when I trigger the Full GC the memory gets cleared, and only 15% heap I can see in usage. So it seems that there is no memory leak. I have also took heap dumps and analyzed them at various points. I have not found any big objects.

Please help me how to proceed from here, is there any GC fine tuning required ? Currently we are using only below params for GC -

-Xms1280M -Xmx1280M -XX:+UseG1GC

Thanks

Akash
  • 33
  • 1
  • 4
  • Have you get any OOM errors ? As long as you don't get one and there is no memory leaks, you should be OK. – usuario Mar 22 '22 at 06:25
  • 1
    You told the JVM that it can use up to 1280MB, you even told it to immediately allocate that amount on startup and now you’re complaining because it uses 448MB? – Holger Mar 22 '22 at 08:11
  • @usuario no till now we have not got any OOM errors, we had 4 pods running for 5 days continuouly. – Akash Mar 22 '22 at 13:14
  • @Holger The thing I am complaining about is the old Gen heap size is increasing steadily, and it is 80% used now. – Akash Mar 22 '22 at 13:16
  • 2
    The 1280MB are permanently reserved to the JVM and can’t be used for anything else. So for the system (or other processes) it is entirely irrelevant, how much of it has been reported as “used” or “free”. Even less relevant is the reported occupancy of a single region. There’s 35% of the total heap considered in use, so there’s still 65% definitely free. So why should the GC waste CPU cycles to identify another 12% free heap, when there’s still 65% free? – Holger Mar 22 '22 at 14:36
  • @Akash I think the problem is that you don't quite understand how the GC works. It is **reactive**. As @Holger says, you gave it a certain amount of heap, there is still space left, why do anything? When the old gen reaches a certain size then it will clean the old gen. I would change the `-Xms`to something lower and let the gc figure out how to lay out the heap. – Erik Mar 24 '22 at 15:42
  • Thanks @Erik. I tried, it is triggering concurrent GC and clearing old gen after it reaches a certain size. – Akash Mar 25 '22 at 22:20
  • If your app works for a 5 days and JVM sees that objects gets old enough, then they are promoted to old generation (it doesn't need to be 5 days it can be event 5 min). That's how it works and it's "normal". You should learn of G1 life cycle. What actualy is problem? That you see somenthing and you think that this is wrong/bad? Don't tune if you have no memory issues. Do not "search by force problems - you'll spend unneccesary time. If after two, three full gc's you'll see that there are less and less objects that are cleaned then you can search for a reason. – Powiadam Cię Apr 07 '22 at 10:52
  • In short, it will clear up the old gen when it feels it is required and not before. If you start running out of memory then you need to investigate this. And if you want your gc to occur earlier then reduce the amount of memory you desire.. – Richard Apr 11 '23 at 09:01

0 Answers0