In a Java 8 heap printout, you may see a line that looks like:
Metaspace used 2425K, capacity 4498K, committed 4864K, reserved 1056768K
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/considerations.html tries to explain the line:
In the line beginning with Metaspace, the used value is the amount of space used for loaded classes. The capacity value is the space available for metadata in currently allocated chunks. The committed value is the amount of space available for chunks. The reserved value is the amount of space reserved (but not necessarily committed) for metadata.
Again, from the above link:
Space is requested from the OS and then divided into chunks. A class loader allocates space for metadata from its chunks (a chunk is bound to a specific class loader).
I want to know what each field means (used, capacity, committed, reserved), but I am struggling to understand the above definitions.
My understanding is that metaspace is carved out of the JVM process's virtual address space. The JVM reserves an initial size on startup based on -XX:MetaspaceSize, which has an undocumented, platform-specific default. I assume that reserved refers to the total size of the metaspace. The space is divided into chunks. I am not sure if each chunk has the same size. Each chunk contains class metadata associated with a single class loader.
Capacity and committed sounds like free space to me (based on the definitions from the link). Since metadata is stored within chunks, then I would assume that used + capacity would equal committed, but it doesn't. Maybe committed means reserved space that is used, but then what would used mean? Used space used by metadata? Then, what other ways are there to use the space?
I hope you see my confusion. I would appreciate clarification on the definitions.
Metaspace contains metadata about the application the JVM is running. It contains class definitions, method definitions, and other information about the program. The more classes you load into your app, the larger metaspace will be.
Simply put, Metaspace is a new memory space – starting from the Java 8 version; it has replaced the older PermGen memory space. The most significant difference is how it handles memory allocation. Specifically, this native memory region grows automatically by default.
They live in a native memory region outside of the Java heap. That region is called Metaspace.
The Java™ virtual machine (JVM) heap size setting directly relates to how many server instances can be started within a dynamic cluster on a specific node. You might need to modify the JVM heap size setting based on your environment configuration. The default value is 256 MB.
Metaspace consists of one or more Virtual Spaces. Virtual Spaces are areas of contiguous address space obtained from the OS. They are allocated on demand. When allocated, Virtual Space reserves memory from the OS, but not yet commits it. Metaspace reserved memory is the total size of all Virtual Spaces.
Allocation unit inside Virtual Space is Metachunk (or simply Chunk). When a new chunk is allocated from a Virtual Space, the corresponding memory is committed. Metaspace committed memory is the total size of all chunks.
Chunks may differ in size. When a ClassLoader gets garbage collected, all Metachunks belonging to it are freed. Free chunks are maintained in the global free list. Metaspace capacity is the total size of all allocated (i.e. not free) chunks.
New chunk allocation
Class metadata is allocated within a chunk. Chunk may not contain data from multiple ClassLoaders, but one ClassLoader may have several chunks. Metaspace used is the total size of all class metadata from all chunks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With