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

8306841: Generational ZGC: NMT reports Java heap size larger than max heap size #14355

Closed
wants to merge 1 commit into from

Conversation

stefank
Copy link
Member

@stefank stefank commented Jun 7, 2023

ZGC has separated the committing of physical memory from the mapping of the committed memory to virtual memory. It also has asynchronous, lazy unmapping of virtual memory from physical memory. This leads to a situation where multiple virtual memory areas can be mapped to the same physical memory. NMT has a strong assumption that there's a 1-to-1 correspondence between committed memory and its virtual memory areas. Because of this NMT and ZGC is not entirely compatible. ZGC has worked around this by adding NMT hooks where the virtual memory is mapped to the committed memory. This mostly works, but there are situations where we have multiple virtual memory areas mapped to the same physical memory, and that causes the NMT values to be inflated.

I propose that we move the NMT committed memory tracking from the mapping of virtual memory to the actual committing of physical memory.

FWIW, given that NMT and ZGC doesn't agree about how memory is committed, we have to fake the virtual memory addresses reported to NMT. This could probably be noticed if you look for the Java heap addresses in the NMT details output, but I don't see why anyone should be looking for those address for the Java heap in NMT. The interesting number is the amount of committed memory, not the exact addresses, IMHO. This isn't something that we change with this patch, but it can be worth understanding while looking at this Bug and the associated PR.

I've written a small sanity test for the NMT Java Heap values, however it's non-trivial to write a test that efficiently provokes this. I've verified this fix by manually running an over-provisioned SPECjbb2015 run, which results in a lot of splitting of ZGC heap regions, which in turn gives us multiple virtual memory area mapping for the same physical memory.

Side note: the lazy unmapping of virtual memory can cause other problems with too many virtual memory areas. The inflated NMT numbers have been a smoking gun showing us that issue. We are tracking that issue with JDK-8308783.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8306841: Generational ZGC: NMT reports Java heap size larger than max heap size (Bug - "4")

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14355/head:pull/14355
$ git checkout pull/14355

Update a local copy of the PR:
$ git checkout pull/14355
$ git pull https://git.openjdk.org/jdk.git pull/14355/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14355

View PR using the GUI difftool:
$ git pr show -t 14355

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14355.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 7, 2023

👋 Welcome back stefank! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 7, 2023
@openjdk
Copy link

openjdk bot commented Jun 7, 2023

@stefank The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Jun 7, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 7, 2023

Webrevs

Copy link
Contributor

@fisk fisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@openjdk
Copy link

openjdk bot commented Jun 7, 2023

@stefank This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8306841: Generational ZGC: NMT reports Java heap size larger than max heap size

Reviewed-by: eosterlund, stuefe

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 10 new commits pushed to the master branch:

  • 5b147eb: 8308288: Fix xlc17 clang warnings and build errors in hotspot
  • 89f5bac: 8309225: Fix xlc17 clang 15 warnings in security and servicability
  • 6eddbe2: 8309219: Fix xlc17 clang 15 warnings in java.base
  • 177e832: 8307153: JVMTI GetThreadState on carrier should return STATE_WAITING
  • f0236ed: 8309543: Micro-optimize x86 assembler UseCondCardMark
  • 9d7bf53: 8280982: [Wayland] [XWayland] java.awt.Robot taking screenshots
  • a1ab377: 8309550: jdk.jfr.internal.Utils::formatDataAmount method should gracefully handle amounts equal to Long.MIN_VALUE
  • c49129f: 8308445: Linker should check that capture state segment is big enough
  • fa79111: 8308031: Linkers should reject unpromoted variadic parameters
  • 16ebf47: 8309594: Cleanup naming in JavacParser related to unnamed classes

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 7, 2023
Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Question: why is this limited to generational ZGC? Just a decision not to fix old ZGC, or does it not happen with old ZGC?

FWIW, given that NMT and ZGC doesn't agree about how memory is committed, we have to fake the virtual memory addresses reported to NMT. This could probably be noticed if you look for the Java heap addresses in the NMT details output, but I don't see why anyone should be looking for those address for the Java heap in NMT.

We do, but it is not such an important use case: in hs_err file "unknown pointer" printing, I use NMT to make sense of an otherwise unknown address.

//
// When this function is called we don't know where in the virtual memory
// this physical memory will be mapped. So we fake that the virtual memory
// address is the heap base + the given offset.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question of a casual ZGC source reader: when you talk about physical vs virtual here, you are not talking about the real physical vs virtual, right? You are talking about offsets into the ZGC backing file vs attach points of said offsets in the virtual address space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but the backing file is backed by physical memory and that's where the name comes from. The backing file is just the way for us to get hold of physical memory, which we can map into the virtual address space. I hope that makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, thank you.

@stefank
Copy link
Member Author

stefank commented Jun 8, 2023

Question: why is this limited to generational ZGC? Just a decision not to fix old ZGC, or does it not happen with old ZGC?

It's a little bit of both. We are mainly focusing on improving Generational ZGC, but I actually did create a Bug for the Singlegen ZGC (JDK-8309607) for this. The fix in this PR was actually an old patch for Generational ZGC that I had laying around that I had already tested. We can probably still fix this for Singlegen ZGC, but it needs a little bit more care since we have yet another layer with the multi-mapping.

@stefank
Copy link
Member Author

stefank commented Jun 8, 2023

We do, but it is not such an important use case: in hs_err file "unknown pointer" printing, I use NMT to make sense of an otherwise unknown address.

OK. I didn't think about that newish feature. However, if those pointers were actually into the Java Heap they wouldn't be "unknown pointers" but instead reported as uncolored ZGC pointers by the code in ZCollectedHeap::print_location (IIUC). Though I see your point, and maybe there's a way to rewrite NMT in the future.

@stefank
Copy link
Member Author

stefank commented Jun 8, 2023

Thanks for the reviews!
/integrate

@openjdk
Copy link

openjdk bot commented Jun 8, 2023

Going to push as commit bb377b2.
Since your change was applied there have been 30 commits pushed to the master branch:

  • ac3ce2b: 8304425: ClassHierarchyResolver from Reflection
  • 79a4ac7: 8309235: Unnamed Variables (_) can't be used in JShell
  • 9d64a9d: 8306431: File.listRoots method description should be re-examined
  • 5af9d2a: 8309602: update JVMTI history table for jdk 21
  • 6646272: 8308764: Reporting errors from create_vm may crash
  • 73dd03c: 8308152: PropertyDescriptor should work with overridden generic getter method
  • 760cb04: 8309569: sun/security/pkcs11/Signature/TestRSAKeyLength.java fails after JDK-8301553
  • e8a5984: 8309630: Clean up tests that reference deploy modules
  • 90027ff: 8309515: Stale cached data from Matcher.namedGroups() after Matcher.usePattern()
  • ea41907: 8297923: java.awt.ScrollPane broken after multiple scroll up/down
  • ... and 20 more: https://git.openjdk.org/jdk/compare/5722903d53e90e36b284967aeb60d2f8b65a744c...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 8, 2023
@openjdk openjdk bot closed this Jun 8, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 8, 2023
@openjdk
Copy link

openjdk bot commented Jun 8, 2023

@stefank Pushed as commit bb377b2.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
3 participants