-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8257901: ZGC: Take virtual memory usage into account when sizing heap #1696
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
Conversation
👋 Welcome back pliden! A progress list of the required criteria for merging this PR into |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functionality seems fine. However, the naming of things are very misleading. Arguments::limit_by_allocatable_memory has no indication that this can only be used to limit the heap memory. The non-ZGC GCs use MaxVirtMemFraction, which doesn't sound like something that has to do with the heap size. But, if you read the description of that flag it's apparent that it's about the max heap size. The added ZGC implementation also highly depend on the fact that max_virtual_memory_fraction() means the "max fraction of virtual memory that can be used by the heap". I think it would be good to name max_virtual_memory_fraction to something that indicates this. Maybe max_heap_to_virtual_memory_fraction() (maybe there's a more succinct name, that still covers what it does?) And limit_by_allocatable_memory should also be changed, before anyone starts to use it as generic function that can be used by the rest of the JVM.
If you agree maybe update the names in this PR, or create a separate RFE?
@pliden 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:
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 53 new commits pushed to the
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 |
@stefank Pushed an update to adjust the names. Also fixed copyrights. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
@@ -46,6 +47,6 @@ size_t ZAddressSpaceLimit::mark_stack() { | |||
|
|||
size_t ZAddressSpaceLimit::heap_view() { | |||
// Allow all heap views to occupy 50% of the address space |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "50%" description is inaccurate, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's still correct.
// Used by heap size heuristics to determine max amount | ||
// of address space to use for the heap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this explanation moved to the hpp file? Then some IDEs will automatically pick it up. I'd expect a comments to the implementation, i.e. of the value 1 here instead of a generic explanation of what the method does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll move the comment.
@@ -1655,11 +1655,12 @@ jint Arguments::set_ergonomics_flags() { | |||
return JNI_OK; | |||
} | |||
|
|||
julong Arguments::limit_by_allocatable_memory(julong limit) { | |||
julong Arguments::limit_heap_by_allocatable_memory(julong limit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are already messing with the name in this change, would it be possible to change return value and parameter to size_t
? I'm good with moving this change of the parameter types to a different issue, but as mentioned, since we are already changing stuff around here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to handle that as a separate issue, since such a change would propagate into os::has_allocatable_memory_limit()
and affect all os:es.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay.
@@ -365,7 +365,7 @@ class Arguments : AllStatic { | |||
static jint set_shared_spaces_flags_and_archive_paths(); | |||
// limits the given memory size by the maximum amount of memory this process is | |||
// currently allowed to allocate or reserve. | |||
static julong limit_by_allocatable_memory(julong size); | |||
static julong limit_heap_by_allocatable_memory(julong size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please clarify the documentation of this method also according to the results of this discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix.
Pushed an update which addresses @tschatzl's comments. |
Latest update looks good. |
Thanks all for reviewing! /integrate |
@pliden Since your change was applied there have been 54 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 0a0691e. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
MaxVirtMemFraction limits the amount of address space the GC should use for the heap. This is used by the heuristics in Arguments::set_heap_size() to select an appropriate default max heap size. However, that heuristic can select a max heap size that will not fit with ZGC, since ZGC uses additional address space (for multi-mapping and the virtual-to-physical ratio). As a result, if the address space is limited, and -Xmx is not specified, then ZGC might refuse to start with the error:
"Failed to reserve enough address space for Java heap"
I propose we abstract MaxVirtMemFraction to make it configurable for each GC, so that the heuristics in Arguments::set_heap_size() will pick a default max heap size that also works for ZGC.
Testing: Manual testing using different ulimit -v sizes.
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/1696/head:pull/1696
$ git checkout pull/1696