-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Feature request
Is your feature request related to a problem? Please describe.
Not related to a problem.
Describe the solution you'd like.
Hotspot JFR has native memory tracking (NMT) events. It may be useful to have support for NMT in SubstrateVM.
In Hotspot, NMT hooks into malloc and also the virtual memory management code (where mmap is used). This allows for tracking how much memory each VM component needs for its own operations. Native memory is grouped into categories (ie GC, Metaspace, etc). The JFR NMT events are just a small feature built on top of the already existing NMT infrastructure.
In SubstrateVM, the memory used by the java application and VM itself is not so clearly separated because memory used by the VM can be managed by the GC. So I can think of two approaches:
- Record only off-heap memory. Perhaps adding tracking in places such as
org.graalvm.nativeimage.UnmanagedMemory#malloc- This wouldn't provide a complete picture of how much memory each VM component is actually using. It would at least fill in the gaps left by heap dumps and JFR allocation events.
- Determine a way to distinguish VM-level allocations from application level ones. This would provide a more complete breakdown of what memory is needed for VM internal operations. I think this is probably more complicated to accomplish.
In SubstrateVM there are three areas where the VM itself might contribute to memory usage: the java heap, off-heap, and the image heap.
To implement NMT in Native Image we first need to decide what "native memory" we want to track. Does "native memory" mean all memory used by the VM for its internal operations, or does it simply mean unmanaged memory? In the Hotspost NMT implementation, these are basically the same thing -- memory used by the VM is not managed by the GC.
In Hotspot, there are two NMT modes "summary" and "detailed". The "detailed" mode includes call site information, whereas the "summary" only provides a memory amounts per category. As a first step, I think the goal should be scoped down to only the "summary" mode.
Describe who do you think will benefit the most.
GraalVM users and contributors would benefit. Some use cases would be:
- RSS is higher than expected or exceeds specified heap size. NMT can shed light on memory usage contributing to RSS not visible in heap dumps or JFR allocation events.
- A user or GraalVM developer may want to measure how much each VM component contribues to RSS. For example, is JFR too expensive to use in their native image executables for their use-case?
Express whether you'd like to help contributing this feature
I'd like to help contribute this if it is desired and feasible.