RFR: JDK-8292072: NMT: repurpose Tracking overhead counter as global malloc counter

Thomas Stuefe stuefe at openjdk.org
Fri Aug 12 07:27:08 UTC 2022


On Tue, 9 Aug 2022 06:13:13 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> I need a fast counter for global mallocs for [JDK-8291878](https://bugs.openjdk.org/browse/JDK-8291878). NMT does not keep a global counter, just category-specific counters. At the moment, `MallocMemorySummary::total()` iterates all these counters and adds them up, which is quite costly.
> 
> This patch makes `MallocMemorySummary::total()` fast by introducing a global malloc counter. However, we don't add a new counter, we just repurpose the tracking overhead counter. 
> 
> The tracking overhead counter gets updated on every malloc and counts number and size of all malloc headers. But malloc headers have always the same size. This patch uses the former overhead counter to count number and size of all mallocs. So now we have a global malloc counter, at no additional cost, and the overhead gets calculated from the number of total mallocs * constant header size.

Hi Ioi,

> Have you done any testing to confirm that the old and new code reports the same overhead numbers. I see that you've moved the accounting code around so I am not sure if all the accountings are still being done at the exact same places.

I checked, numbers are similar.

> 
> Also, if possible, a new gtest would be useful.

I added a gtest, but it needs quite a large leeway for heuristics to prevent false positives. Since NMT itself does malloc/free and concurrent code can malloc/free, numbers wobble quite a bit between runs. I ended up with a tolerance factor of +-30% - not sure how useful this test is apart from catching obvious errors like overflows.

-------------

PR: https://git.openjdk.org/jdk/pull/9804


More information about the hotspot-runtime-dev mailing list