When a Garbage Collection event runs, it spends a predominant amount of its time in the Java application layer. It also spends a certain portion of its time in the Operating System/Kernel layer.
Amount of time Garbage Collector spends in the Java application layer is reported as ‘User’ time in the GCeasy report. Here are the reasons for the ‘User’ time:
a. Garbage collector has to mark all the objects & identify the ones with active references.
b. It has to evict unreferenced objects in the memory.
Amount of time Garbage Collector spends in the Operating system/kernel layer is reported as ‘Sys’ time in the GCeasy report. Here are the reasons for the ‘Sys’ time:
a. When there is demand for the memory, the application will ask for additional memory from the Operating System. To allocate that memory to JVM, it will take some time. Once memory pressure goes away, JVM will give back the memory to the operating system. This deallocation will also take time.
b. JVM sometimes may request large pages (like in the magnitude of 2mb size/page). If the operating system cannot find contiguous free space to allocate 2mb pages, then it will stop all the processes that are running and start moving around the data to find contiguous free space. This will take time.
c. JVM creates and writes statistics about safepoints and garbage collection events in the /tmp/hsperfdata_(username) file. This file gets updated when GC events run. Occasionally linux kernel threads block the GC threads from updating this file when there is heavy disk I/O. Thus very heavy disk I/O activity can increase ‘sys’ time.
d. Due to lack of memory, Operating system might swap your application in & out of memory. This swapping time will be reported as ‘sys’ time.
e. Sometimes there could be certain problems in the Operating system (such as System faults, misaligned memory references, floating point exceptions) – then in such circumstances Garbage collectors will have to spend more time on the OS/Kernel layer.
CPU time is the total amount of time an application spends in garbage collection. It’s basically the sum of ‘User’ time and ‘Sys’ time.