JDK-8009561 : NPG: Metaspace fragmentation when retiring a Metachunk
  • Type: Bug
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: hs25
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-03-06
  • Updated: 2013-09-24
  • Resolved: 2013-09-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 Other
8Fixed hs25Fixed
When a Metaspace allocation request cannot be satisfied by the current chunk the chunk is retired and a new chunk is requested. This causes whatever is left in the chunk to be effectively leaked.
It might be a good idea to add the last piece of each chunk to the SpaceManager's block dictionary.
The reason I'm seeing this is that when running the test attached to JDK-8004241 the waste in the class space is 20% when running with MaxMetaspaceSize=256m. We end up with something like:

 Metaspace total 171164K, used 146740K, reserved 178176K
  data space     68764K, used 66765K, reserved 75776K
  class space    102400K, used 79975K, reserved 102400K

while trying to allocate ~40 words in the class space.
noreg-hard: The fix tweaks the limits for when allocations are done from the internal free list as opposed to taking new memory. It would be extremely difficult to write a reliable test to verify this.