-
Notifications
You must be signed in to change notification settings - Fork 6k
8337217: Port VirtualMemoryTracker to use VMATree #20425
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
8337217: Port VirtualMemoryTracker to use VMATree #20425
Conversation
👋 Welcome back azafari! A progress list of the required criteria for merging this PR into |
@afshin-zafari 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 1 new commit pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
@afshin-zafari The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
/label hotspot-runtime |
@afshin-zafari |
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.
Hi,
Great work! I'm slowly working through the code, let's take our time with this. My PR got too stressful for everyone involved :-/.
I've reviewed some of the code. Could you go a bit more in-depth on what the results of this work was? Did it improve performance, for example?
All tier1 tests pass except one that expects a 50% increase in committed memory but it does not happen.
I don't understand what this means, could you expand on this? Edit: Re-read it again now and I get it, which test is this?
Thanks!
src/hotspot/share/nmt/vmatree.hpp
Outdated
@@ -37,8 +37,9 @@ | |||
// For example, the state may go from released memory to committed memory, | |||
// or from committed memory of a certain MEMFLAGS to committed memory of a different MEMFLAGS. | |||
// The set of points is stored in a balanced binary tree for efficient querying and updating. | |||
class VMATree { | |||
class VMATree : public AnyObj { |
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.
Why is it AnyObj now?
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.
Mainly to be able to use new operator
. Changed to CheapObj<mtNMT>
.
}); | ||
} | ||
|
||
void VirtualMemoryTrackerWithTree::apply_summary_diff(VMATree::SummaryDiff diff) { |
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.
Applying a summary diff in the MemoryFileTracker is this:
for (int i = 0; i < mt_number_of_types; i++) {
VirtualMemory* summary = file->_summary.by_type(NMTUtil::index_to_flag(i));
summary->reserve_memory(diff.flag[i].commit);
summary->commit_memory(diff.flag[i].commit);
}
This is much simpler and doesn't require looking at signs and so on.
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.
In MemoryFileTracker
, the changes in commit/reserve are applied to a local VirtualMemorySnapshot
. Here we have to apply them to the global VirtualMemorySummary
.
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.
Yeah, that doesn't seem like a problem.
for (int i = 0; i < mt_number_of_types; i++) {
r = diff.flag[i].reserve;
c = diff.flag[i].commit;
flag = NMTUtil::index_to_flag(i);
VirtualMemory* mem = VirtualMemorySummary::as_snapshot()->by_type(flag);
reserved = mem->reserved();
committed = mem->committed();
mem->reserve_memory(r);
mem->commit_memory(c);
if ((size_t)-r > reserved) {
print_err("release");
}
if ((size_t)-c > reserved || (size_t)c > committed) {
print_err("uncommit");
}
}
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.
This applies the reserve/commit regardless of outcome, so slightly different.
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 main purpose of the if (...)
cases is to find if the request to apply the delta is valid or not. There are related assertions in VirtualMemory but not so informative. Also, using log_debug
lets the build proceed and just show the messages.
These messages help a lot when something goes wrong in terms of commit/uncommit/release failure.
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.
How does my example code not account for this? You can still get rid of the sign checking.
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.
Case of 'commit' error is missing from your suggestion. At commit time, c > reserved
is invalid too.
(size_t)-r
for positive r
is a large number and is greater than reserved
.
We have to find out the intent of the call first (by checking the sign of r
or c
) and then check if it is valid or not.
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 for your comments. They are replied or applied.
|
}); | ||
} | ||
|
||
void VirtualMemoryTrackerWithTree::apply_summary_diff(VMATree::SummaryDiff diff) { |
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.
Yeah, that doesn't seem like a problem.
for (int i = 0; i < mt_number_of_types; i++) {
r = diff.flag[i].reserve;
c = diff.flag[i].commit;
flag = NMTUtil::index_to_flag(i);
VirtualMemory* mem = VirtualMemorySummary::as_snapshot()->by_type(flag);
reserved = mem->reserved();
committed = mem->committed();
mem->reserve_memory(r);
mem->commit_memory(c);
if ((size_t)-r > reserved) {
print_err("release");
}
if ((size_t)-c > reserved || (size_t)c > committed) {
print_err("uncommit");
}
}
}); | ||
} | ||
|
||
void VirtualMemoryTrackerWithTree::apply_summary_diff(VMATree::SummaryDiff diff) { |
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.
This applies the reserve/commit regardless of outcome, so slightly different.
static RegionsTree* tree() { return _tree; } | ||
|
||
private: | ||
static RegionsTree* _tree; |
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 you do the instance/static pattern then you can switch this into a regular member, no pointer necessary.
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 _tree
ctor to be called in initialize
with a bool
depending the NMT_Level
. Existing VMT also uses a pointer to a SortedLinkList
.
I am not sure yet: What is the advantage of not-a-pointer member? How the instance/static helps this?
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.
More fixes and questions.
Performance test runs insert/remove operations for SortedLinkList (SLL in the code) and Treap and expects that Treap be faster. Both tests pass with a factor of 70+ faster for 10000 elements. |
…mance test compares VMT and VMA.
Are we keeping both the linked list based and VMATree based implementations just for the review process, and we will drop the linked list one, once we are done with the review, or are they both going to be checked in? |
Is there a concrete advantage here for using lambda expression when iterating committed regions? I'm asking because personally I find
simpler and more compact, hence easier to understand, than
|
Same here:
We are setting |
@afshin-zafari This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@afshin-zafari This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
/open |
@afshin-zafari This pull request is now open |
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.
LGTM!
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.
Small changes (copyright years) and one question, otherwise LGTM.
Nice!
RegionsTree* rtree = VirtualMemoryTracker::Instance::tree(); | ||
rtree->tree().remove_all(); |
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.
Why are we calling remove_all()
right after we create the tree?
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.
We are not creating the tree here. We just retrieve it from the Instance of VMT. Since the tree is also visible to other tests (it is static and not created per test), any changes in other tests will be visible here by this test. This is not as expected in the design of the tests (tests assume that tree is empty at the beginning of the test).
Thanks for reviews @gerard-ziemski and @jdksjolen. |
Going to push as commit 547ce03.
Your commit was automatically rebased without conflicts. |
@afshin-zafari Pushed as commit 547ce03. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
VMATree
is used instead ofSortedLinkList
in new classVirtualMemoryTracker
.RegionTree
is made around VMATree to make some calls easier.find_reserved_region()
is used in 4 cases, it will be removed in further PRs.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20425/head:pull/20425
$ git checkout pull/20425
Update a local copy of the PR:
$ git checkout pull/20425
$ git pull https://git.openjdk.org/jdk.git pull/20425/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20425
View PR using the GUI difftool:
$ git pr show -t 20425
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20425.diff
Using Webrev
Link to Webrev Comment