Java 8 reserves 1G for Metaspace just after it starts. It means that minimum metaspace size is 1G. But I set up MetaspaceSize to 300m and MaxMetaspaceSize to 400m. Why Java reserves more then I allow?
Java 8在启动后为Metaspace预留1G。这意味着最小元空间大小为1G。但我将MetaspaceSize设置为300米,MaxMetaspaceSize设置为400米。为什么Java保留了我允许的更多?
Java Version
Java版本
$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
VM Flags
VM标志
$ jcmd 21689 VM.flags
21689:
-XX:CICompilerCount=3 -XX:ConcGCThreads=1 -XX:G1HeapRegionSize=1048576 -XX:InitialHeapSize=62914560 -XX:+ManagementServer -XX:MarkStackSize=4194304 -XX:MaxHeapSize=1006632960 -XX:MaxMetaspaceSize=399998976 -XX:MaxNewSize=603979776 -XX:MetaspaceSize=299999232 -XX:MinHeapDeltaBytes=1048576 -XX:NativeMemoryTracking=summary -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC
NMT
NMT
[jetty9-proxy@bm01 bin]$ jcmd 21689 VM.native_memory
21689:
Native Memory Tracking:
Total: reserved=2769543KB, committed=1311159KB
- Class (reserved=1221904KB, committed=197904KB)
(classes #36543)
(malloc=3344KB #44041)
(mmap: reserved=1218560KB, committed=194560KB)
And just after start it was
就在开始之后
Total: reserved=2402748KB, committed=150796KB
- Class (reserved=1056956KB, committed=7868KB)
(classes #1300)
(malloc=188KB #564)
(mmap: reserved=1056768KB, committed=7680KB)
2 个解决方案
#1
23
The reason why Java reserves 1G for Classes hides in the way how it manages compressed class pointers.
Java为类保留1G的原因在于它如何管理压缩类指针。
The long answer: read this doc https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/considerations.html
答案很长:阅读本文档https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/considerations.html
The short answer: setup the correct size in 'CompressedClassSpaceSize' property -XX:CompressedClassSpaceSize=300m
简短的回答:在'CompressedClassSpaceSize'属性中设置正确的大小-XX:CompressedClassSpaceSize = 300m
#2
4
Class (reserved=1221904KB
类(保留= 1221904KB
this isn't memory that's being used, just virtual address space
这不是正在使用的内存,只是虚拟地址空间
committed=197904KB
致力于= 197904KB
That's 197MB, not 1GB
这是197MB,而不是1GB
Therefore you're not showing that java actually consumes 1GB of memory for class data, only that it reserves 1GB worth of address space.
因此,您没有表明java实际上为类数据消耗了1GB的内存,只是它保留了1GB的地址空间。
#1
23
The reason why Java reserves 1G for Classes hides in the way how it manages compressed class pointers.
Java为类保留1G的原因在于它如何管理压缩类指针。
The long answer: read this doc https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/considerations.html
答案很长:阅读本文档https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/considerations.html
The short answer: setup the correct size in 'CompressedClassSpaceSize' property -XX:CompressedClassSpaceSize=300m
简短的回答:在'CompressedClassSpaceSize'属性中设置正确的大小-XX:CompressedClassSpaceSize = 300m
#2
4
Class (reserved=1221904KB
类(保留= 1221904KB
this isn't memory that's being used, just virtual address space
这不是正在使用的内存,只是虚拟地址空间
committed=197904KB
致力于= 197904KB
That's 197MB, not 1GB
这是197MB,而不是1GB
Therefore you're not showing that java actually consumes 1GB of memory for class data, only that it reserves 1GB worth of address space.
因此,您没有表明java实际上为类数据消耗了1GB的内存,只是它保留了1GB的地址空间。