<div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">hi all,</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">Thank you so much for the follow-up about the patch that I mentioned about the metaspace last week(<a href="http://mail.openjdk.java.net/pipermail/hotspot-gc-dev/2018-September/023329.html" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196);">A Bug Of Metaspace After Full GC</a>).However,I still have the other suggestion about the metaspace. Please allow me to describe it briefly.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">Still in the Full GC scenario, we will print the size of the metaspace in the GC log. Suppose we set -XX:MetaspaceSize=100M -XX:MaxMetaspaceSize=100M, which means a metaspace full GC should be triggered once the metaspace usage reaches to 100M, but actually we find the problem from the gc log and only 70899KB is used in the metaspace.<span class="Apple-converted-space"> </span></p><div style="-webkit-print-color-adjust: exact; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;"><pre style="-webkit-print-color-adjust: exact; margin-top: 15px; margin-bottom: 15px; background-color: rgb(248, 248, 248); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 19px; overflow: auto; padding: 6px 10px; border-radius: 3px;"><code class="language-none" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; white-space: pre; border: none; background-color: transparent; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-position: initial initial; background-repeat: initial initial;">[Full GC (Metadata GC Threshold) [PSYoungGen: 5092K->0K(132096K)] [ParOldGen: 85822K->60451K(181760K)] 90914K->60451K(313856K), [Metaspace: 70899K->70899K(1136640K)], 0.1482072 secs] [Times: user=0.52 sys=0.00, real=0.15 secs]</code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">First let’s take a look at the code that prints this line of gc log which really depends on the size used by metaspace.</p><div style="-webkit-print-color-adjust: exact; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;"><pre style="-webkit-print-color-adjust: exact; margin-top: 15px; margin-bottom: 15px; background-color: rgb(248, 248, 248); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 19px; overflow: auto; padding: 6px 10px; border-radius: 3px;"><code class="language-none" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; white-space: pre; border: none; background-color: transparent; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-position: initial initial; background-repeat: initial initial;">void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) {
gclog_or_tty->print(", [Metaspace:");
if (PrintGCDetails && Verbose) {
gclog_or_tty->print(" " SIZE_FORMAT
"->" SIZE_FORMAT
"(" SIZE_FORMAT ")",
prev_metadata_used,
used_bytes(),
reserved_bytes());
} else {
gclog_or_tty->print(" " SIZE_FORMAT "K"
"->" SIZE_FORMAT "K"
"(" SIZE_FORMAT "K)",
prev_metadata_used/K,
used_bytes()/K,
reserved_bytes()/K);
}
gclog_or_tty->print("]");
}</code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">However, the basis for triggering metaspace Full GC is not based on the real usage of metaspace, but the memory size of metaspace committed.</p><div style="-webkit-print-color-adjust: exact; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;"><pre style="-webkit-print-color-adjust: exact; margin-top: 15px; margin-bottom: 15px; background-color: rgb(248, 248, 248); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 19px; overflow: auto; padding: 6px 10px; border-radius: 3px;"><code class="language-none" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; white-space: pre; border: none; background-color: transparent; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-position: initial initial; background-repeat: initial initial;">size_t MetaspaceGC::allowed_expansion() {
size_t committed_bytes = MetaspaceAux::committed_bytes();
size_t capacity_until_gc = capacity_until_GC();
assert(capacity_until_gc >= committed_bytes,
err_msg("capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
capacity_until_gc, committed_bytes));
size_t left_until_max = MaxMetaspaceSize - committed_bytes;
size_t left_until_GC = capacity_until_gc - committed_bytes;
size_t left_to_commit = MIN2(left_until_GC, left_until_max);
return left_to_commit / BytesPerWord;
}</code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">Obviously, if we create a lot of classloaders, each of them will correspond to a metaspace data structure. The usage of our metaspace refers to the real in Metanchunk. The size of the memory is allocated, but Metanchunk is not all used up. This problem is simplified. Just like the fragmentation of the CMS GC, we have a certain gap between the memory committed and the memory used, and trigger the metaspace Full GC is based on the size of the committed, so the user feels like the metaspace doesn’t reach our threshold triggers the Full GC, which seems doubtful.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">Therefore, I would like to make a small suggestion that for the scenario of Full GC, the committed memory size instead of the used memory size will be printed more directly when we print the GC log of metaspace, which will make the user to see it more clearly and turn out that the threshold of metaspace has already reached the trigger of Full GC.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">The modified log is more conspicuous and indeed triggered when reaching 100M, but it will bring another drawback that we don‘t know how much metaspace really have been used.</p><div style="-webkit-print-color-adjust: exact; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;"><pre style="-webkit-print-color-adjust: exact; margin-top: 15px; margin-bottom: 15px; background-color: rgb(248, 248, 248); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 19px; overflow: auto; padding: 6px 10px; border-radius: 3px;"><code class="language-none" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; white-space: pre; border: none; background-color: transparent; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-position: initial initial; background-repeat: initial initial;">[Full GC (Metadata GC Threshold) [PSYoungGen: 5092K->0K(132096K)] [ParOldGen: 81395K->60429K(181248K)] 86488K->60429K(313344K), [Metaspace: 102400K->70599K(1136640K)], 0.1330421 secs] [Times: user=0.46 sys=0.00, real=0.13 secs]</code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">This issue will have some impact on various GC strategies.</p><p style="-webkit-print-color-adjust: exact; margin-top: 15px; margin-right: 0px; margin-left: 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto; margin-bottom: 0px !important;">What do you think about this? I am looking forward to your reply.</p><p style="-webkit-print-color-adjust: exact; margin-top: 15px; margin-right: 0px; margin-left: 0px; caret-color: rgb(0, 0, 0); font-family: Helvetica, arial, sans-serif; text-size-adjust: auto; margin-bottom: 0px !important;"><br></p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; text-size-adjust: auto;">Thanks,</p><p style="-webkit-print-color-adjust: exact; margin-top: 15px; margin-right: 0px; margin-left: 0px; font-family: Helvetica, arial, sans-serif; text-size-adjust: auto; margin-bottom: 0px !important;">nijiaben</p></div><div><includetail><!--<![endif]--></includetail></div>