How to know region size used of G1 garbage collector?
Asked Answered
G

5

17

I'm currently looking into G1 GC in latest Java 8 version.

I have issues with "Humongous Allocation" so I wanna know how big my region size is.

How can I find out how big the region size is set?

How can I calculate the region size myself?

Thanks

Gothar answered 17/10, 2017 at 9:15 Comment(0)
S
31

G1 region-size in Java-8 is based on startingHeapSize/2048 and rounded DOWN to the first power of 2 between 1MB and 32MB; region sizes <1MB or >32MB are not supported.

you can also set the region-size via -XX:G1HeapRegionSize=n (note, the value has the same power-of-2/range restrictions).

so actually the JVM seems biased towards a region count between 2048 and 4095 (assuming a heap between 2GB and 128GB).

in general these are the region-sizes per heap-size range:

 <4GB -  1MB
 <8GB -  2MB
<16GB -  4MB
<32GB -  8MB
<64GB - 16MB
64GB+ - 32MB

note, MB is actually MiB and GB is actually GiB

Skittish answered 19/1, 2018 at 18:3 Comment(1)
try use jmap -heap pidScatter
P
4

Regarding "How can I find out how big the region size is set?", instead of calculating you can launch java with -Xlog:gc* flag (Java 9 or later), which should print in the very beginning:

[0.003s][info][gc,heap] Heap region size: 1M
[0.004s][info][gc     ] Using G1
[0.004s][info][gc,heap,coops] Heap address: 0x00000000fc000000, size: 64 MB, Compressed Oops mode: 32-bit
Paulettapaulette answered 4/7, 2020 at 17:47 Comment(0)
K
3

The region size is calculated by the JVM during startup based on the size of the heap. Heap's default value is 1/4th of your physical memory or 1GB (whichever is smaller). Refer this.

The region sizes can vary from 1 MB to 32 MB depending on the heap size. The goal is to have no more than 2048 regions.

You can override the size by specifying -XX:G1HeapRegionSize=XX in the startup script.

Keiko answered 17/10, 2017 at 9:30 Comment(1)
Xms, minimum heap: "The goal is to have around 2048 regions based on the minimum Java heap size." But if not defined, nothing mentioned in the documentation above :(Anthocyanin
M
3

to see the region size, use jinfo -flags your_pid

Non-default VM flags: -XX:G1HeapRegionSize=1048576 -XX:InitialHeapSize=1054867456 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=5368709120 -XX:MaxNewSize=3221225472 -XX:MinHeapDeltaBytes=1048576 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC 
Millisent answered 30/9, 2020 at 7:26 Comment(0)
S
0
  1. jps find java program pid
  2. jmap -heap pid
  3. G1HeapRegionSize is the region size jvm calculated

eg:

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

Heap Configuration:
   MinHeapFreeRatio         = 30
   MaxHeapFreeRatio         = 50
   .............................
   MaxHeapSize              = 12884901888 (12288.0MB)
   G1HeapRegionSize         = 4194304 (4.0MB)

Heap Usage:
G1 Heap:
   regions  = 3072
   capacity = 12884901888 (12288.0MB)
   used     = 4050405416 (3862.7676162719727MB)
   free     = 8834496472 (8425.232383728027MB)
   31.435283335546654% used
Scatter answered 13/1, 2023 at 7:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.