Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track virtual memory with native memory tracking (NMT) #8630

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

roberttoyonaga
Copy link
Collaborator

@roberttoyonaga roberttoyonaga commented Mar 22, 2024

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 on virtualMemoryTracker.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 to VirtualMemoryTracker which maintains this internal model. This is the same as how memTracker.hpp delegates to virtualMemoryTracker.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:

  • For now, only PosixVirtualMemoryProvider has been instrumented. Later on, WindowsVirtualMemoryProvider can probably be instrumented too.
  • All virtual memory accounting operations are protected by a spinlock. I don't think this should have an impact on performance since changes in virtual memory usage should be infrequent. memTracker.hpp uses the same approach to protect virtual memory accounting.
  • Virtual memory peak tracking is also added.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Mar 22, 2024
@roberttoyonaga roberttoyonaga marked this pull request as draft March 22, 2024 15:53
@roberttoyonaga roberttoyonaga force-pushed the nmt-vmem branch 2 times, most recently from 44c2748 to c3bedd6 Compare March 22, 2024 17:18
@roberttoyonaga roberttoyonaga force-pushed the nmt-vmem branch 4 times, most recently from 2d80457 to 896c258 Compare April 5, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant