How to prevent GC logs from filling filesystem?

Question:

How to prevent Garbage Collection (GC) logs from filling up filesystem and generating "No space left on device" error?

 

Answer:

GC log size will be directly proportional to the number of GC cycles.  There can be cases where heap is near exhaustion and there are back-to-back GC cycles to try to keep up.  In such situations, the GC log can become quite large.

There are 2 things that can be done to help prevent the GC log from taking up too much disk space:

  1. Firstly, to reduce the amount of GC logging, please remove -XX:PrintGCDetails startup flag if present.  This will still provide sufficient logging to debug GC issues, but significantly reduce the size of the logs.
  2.  Secondly, it is recommend to set a maximum size for the GC log and also a maximum number of log files to keep.  This way one can precisely define the maximize disk space the GC log will occupy (size x #).  For example, setting the maximum size to 100MB with 5 log files (total of 500MB) can be accomplished with the following arguments:
    -Xloggc:/home/java/gc.log -XX:+GCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=100M

The above options work for Java 8.  Newer versions of Java of 11 and newer utilize Unified Logging.  For example,

-Xlog:gc,safepoint:/home/java/gc.log::filecount=5,filesize=100M

Defaults: filecount=5,filesize=20M

Add Comment

Comments

0 comments

Please sign in to leave a comment.

Was this article helpful?
0 out of 0 found this helpful