Search code examples
javagarbage-collectionjvmg1gc

Sudden increase in G1 old generation committed memory and decrease in Eden size


For some reason, G1 is deciding to increase the committed old generation memory (although the used memory does not increase) and decrease the Eden generation committed memory (consequently the usable space). It seems to be causing a spike in GC's young generation runs and making the application unresponsive for some time.

We also can see a spike in CPU usage and the total committed virtual memory in the machine (which gets bigger than the total physical memory). It is also possible to see a spike in disk usage and swapout/swapin.

My questions are:

  1. Is it likely that the G1 decision to decrease the Eden size and drastically increasing the old generation committed memory causing all those spikes?
  2. Why is it doing that?
  3. How to prevent it from doing that?

JVM version: Ubuntu, OpenJDK Runtime Environment, 11.0.11+9-Ubuntu-0ubuntu2.20.04

enter image description here enter image description here enter image description here enter image description here

EDIT: Seems that what is causing the memory spike is a sudden increase in the off-heap JVM direct buffer memory pool. The image below shows the values of 4 metrics: os_committed_virtual_memory (blue), node_memory_SwapFree_bytes (red), jvm_buffer_pool_used_direct (green) and jvm_buffer_pool_used_mapped (yellow). The values are in GB.

I'm still trying to find what is using this direct buffer memory and why it has such an effect on the heap memory.

enter image description here


Solution

  • The issue was caused by a memory leak related to direct memory usage. An output stream was not being closed after being used.