我有一个Netty进程,它使用具有4个线程的并行GC运行8 GB的堆。我正在尝试分析堆,并观察到jmap
中显示的所有容量的总和甚至不接近8 GB,Old Gen仅1.5 GB,Young Gen 750 MB。
下面是 jmap -heap 7595
的输出Attaching to process ID 7595, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.131-b11
using thread-local object allocation.
Parallel GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 30
MaxHeapFreeRatio = 70
MaxHeapSize = 8589934592 (8192.0MB)
NewSize = 88080384 (84.0MB)
MaxNewSize = 2863136768 (2730.5MB)
OldSize = 176160768 (168.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 763363328 (728.0MB)
used = 418551600 (399.1619110107422MB)
free = 344811728 (328.8380889892578MB)
54.8299328311459% used
From Space:
capacity = 1048576 (1.0MB)
used = 458752 (0.4375MB)
free = 589824 (0.5625MB)
43.75% used
To Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
PS Old Generation
capacity = 1530396672 (1459.5MB)
used = 1196099760 (1140.6896209716797MB)
free = 334296912 (318.8103790283203MB)
78.15619191309898% used
27146 interned Strings occupying 3164408 bytes.
[年轻一代(728)+老一代(1459)= 2187 MB] << 8GB
答案 0 :(得分:1)
默认情况下,JVM在启动后不会分配最大堆,而是在JVM需要时分配并扩展较小的初始堆。您可以使用-Xms
标志,例如将初始堆大小强制为8GB。 docs中的-Xms8g
:
-Xmssize
设置堆的初始大小(以字节为单位)。此值必须是1024的倍数且大于1 MB。字母k或K表示千字节,m或M表示兆字节,g或G表示千兆字节。