首页 > 解决方案 > Java JVM 元空间分配很多但使用很少

问题描述

知道为什么 meta Sapce 分配了很多但很少使用 vevy 吗?

在此处输入图像描述

标签: javagarbage-collection

解决方案


The size of metaspace is controlled by the JVM according to metaspace usage, and within the constraints of certain tuning parameters that are set via command line options ... or defaults.

  • The -XX:MetaspaceSize option gives the initial size of metaspace. The default is platform specific.

  • The -XX:MaxMetaspaceSize option gives an upper limit for the size. The JVM won't go beyond that limit. The default for this is "unlimited".

  • The -XX:MaxMetaspaceFreeRatio and -XX:MinMetaspaceFreeRatio control the JVM's resizing of metaspace following a GC run. Basically, the JVM tries to keep the free space to used space ratio within the specified range ... by increasing or decreasing the size.

So to answer your question:

Java JVM meta space allocated a lot but used less.

It will be a reflection of either how big the metaspace was to start with (determined by -XX:MetaspaceSize or its default value) and what the actual peak and recent metaspace usage patterns have been.

I haven't seen anything explicit about this, but metaspace resizing probably behaves like normal Java heap resizing. The JVM only reduces the size of the metaspace only after a major garbage collection and does it "cautiously". (If metaspace is reduced too much or too soon, that is liable to trigger a major garbage collection.)

However, there is no need to worry about this. If the metaspace is underused, the unused portions should not (in the long term) tie down physical RAM pages. The OS's virtual memory system should write out the page content to disk (if the pages are dirty) and then reallocate the RAM pages to something else. Normal virtual memory stuff.


推荐阅读