Track virtual memory with native memory tracking (NMT) #8630
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This is currently a draft because I think #8462 should be integrated first.
Related Issue: #8629
This pull request adds virtual memory tracking to NMT. Previously, NMT only tracked mallocs and was missing information about virtual memory.
The main component of this PR is the
VirtualMemoryTracker
class which is based onvirtualMemoryTracker.cpp
in Hotspot. Since commits and uncommits may partially (or not at all) overlap with existing committed regions, it is necessary to keep an internal model of virtual memory in use.NativeMemoryTracking
delegates virtual memory tracking duties toVirtualMemoryTracker
which maintains this internal model. This is the same as howmemTracker.hpp
delegates tovirtualMemoryTracker.cpp
in Hotspot.NativeMemoryTracking
remains the the main interface to record and retrieve tracking data, whileVirtualMemoryTracker
and associated classes are only used by NMT internally.Tracking virtual memory usage before the image heap is mapped requires special handling. We can't use the
NativeMemoryTracking
image singleton yet so we must instead use unmanaged memory and stack memory to temporarily record virtual memory usage. Once the image heap is mapped, the temporary records can be properly committed to tracking.NmtPreImageHeapData
is used to enqueue records of pre-image-heap reserves/commits.More details:
PosixVirtualMemoryProvider
has been instrumented. Later on,WindowsVirtualMemoryProvider
can probably be instrumented too.memTracker.hpp
uses the same approach to protect virtual memory accounting.