jdk
jdk copied to clipboard
8312132: Add tracking of multiple address spaces in NMT
Hi,
This PR introduces a new abstraction to NMT, named MemoryFileTracker
. Today, NMT does not track any memory outside of the virtual memory address space. This means that if you allocated memory in something such as a memory-backed file and use mmap
to map into that memory, then you'll have trouble reporting this to NMT. This is the situation that ZGC is in, and that is what this patch attempts to fix.
MemoryFileTracker
The MemoryFileTracker
adds the ability of adding new virtual memory address spaces to NMT and committing memory to these, the basic API is:
static MemoryFile* make_device(const char* descriptive_name);
static void free_device(MemoryFile* device);
static void allocate_memory(MemoryFile* device, size_t offset, size_t size,
MEMFLAGS flag, const NativeCallStack& stack);
static void free_memory(MemoryFile* device, size_t offset, size_t size);
It is easiest to see how this is used by looking at what ZGC's ZNMT
class does:
void ZNMT::reserve(zaddress_unsafe start, size_t size) {
MemTracker::record_virtual_memory_reserve((address)start, size, CALLER_PC, mtJavaHeap);
}
void ZNMT::commit(zoffset offset, size_t size) {
MemTracker::allocate_memory_in(ZNMT::_device, static_cast<size_t>(offset), size, mtJavaHeap, CALLER_PC);
}
void ZNMT::uncommit(zoffset offset, size_t size) {
MemTracker::free_memory_in(ZNMT::_device, (size_t)offset, size);
}
void ZNMT::map(zaddress_unsafe addr, size_t size, zoffset offset) {
// NMT doesn't track mappings at the moment.
}
void ZNMT::unmap(zaddress_unsafe addr, size_t size) {
// NMT doesn't track mappings at the moment.
}
As you can see, any mapping between reserved regions and device-allocated memory is not recorded in NMT. This means that in detailed mode you only get reserved regions printed for the reserved memory, the device-allocated memory is reported separately. When performing summary reporting any memory allocated via these devices is added to the corresponding MEMFLAGS
as committed
memory.
This patch is also acting as a base on which we deploy multiple new backend ideas to NMT. These ideas are:
- Implement VMA tracking using a balanced binary tree approach. Today's
VirtualMemoryTracker
's usage of linked lists is slow and brittle, we'd like to move away from it. Our Treap-based approach in this patch gives a performance boost such that we see 25x better performance in a benchmark. The idea and draft of this is due to Thomas Stüfe, kudos to him. My approach uses a few recursive functions which aren't in tail-call position, these reaches a call-stack depth equivalent to the depth of the tree. With a tree of 20 million nodes we will have a depth oflog2(20 * 10**6) = 25
, which is perfectly fine. - Separate storage of the
NativeCallStack
s in a closed addressing hashtable. NCS:s are large and there are relatively few of them occurring many times, so caching them makes sense.NCS
:s are never deleted and the bucket array is never resized.
Example detailed output
We add a section Memory file details
when producing a detailed report.
Memory file details
Memory map of ZGC heap backing file
[0x0000000000000000 - 0x0000000065200000] allocated 1696595968 for Java Heap
[0x00007f3ecbdb8aea]ZPhysicalMemoryManager::commit(ZPhysicalMemory&)+0x9a
[0x00007f3ecbdb211b]ZPageAllocator::commit_page(ZPage*)+0x33
[0x00007f3ecbdb2ad5]ZPageAllocator::alloc_page_finalize(ZPageAllocation*)+0x7b
[0x00007f3ecbdb2c1b]ZPageAllocator::alloc_page(ZPageType, unsigned long, ZAllocationFlags, ZPageAge)+0xc7
Missing features
There is no detailed diffing of this data.
Progress
- [x] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
- [x] Change must not contain extraneous whitespace
- [x] Commit message must refer to an issue
Issue
- JDK-8312132: Add tracking of multiple address spaces in NMT (Enhancement - P4)
Reviewers
- Stefan Karlsson (@stefank - Reviewer) ⚠️ Review applies to 1f0e0265
Contributors
- Thomas Stuefe
<[email protected]>
Reviewing
Using git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18289/head:pull/18289
$ git checkout pull/18289
Update a local copy of the PR:
$ git checkout pull/18289
$ git pull https://git.openjdk.org/jdk.git pull/18289/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18289
View PR using the GUI difftool:
$ git pr show -t 18289
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18289.diff
Webrev
:wave: Welcome back jsjolen! 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.
@jdksjolen 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:
8312132: Add tracking of multiple address spaces in NMT
Co-authored-by: Thomas Stuefe <[email protected]>
Reviewed-by: stefank, 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 100 new commits pushed to the master
branch:
- 244f6ac222fa98fba4fb99bf5bccd36e3e6c5de1: 8307824: Clean up Finalizable.java and finalize terminology in vmTestbase/nsk/share
- a706e35b12addff987b489059be8f240c60fae75: 8332039: Cannot invoke "com.sun.source.util.DocTreePath.getTreePath()" because "path" is null
- 612b6896d28cebf61ef024709ff3afb5e3ee0dde: 8043226: Better diagnostics for non-applicable type annotations
- dce97031555dcf689fecda16e444e7e8e9d5b270: 8333226: Regressions 2-3% in Compress ZGC after 8331253
- b101dcb609eae00b406f387cd90e58487d5868df: 8333312: Incorrect since tags on new ClassReader and ConstantPool methods
- e0bab786402d70e9a74d1816c029c772ea01f697: 8326951: since-checker - missing @ since tags
- 31f70391e5f22ff5803d16b52c1e1248b6253d8c: 8316131: runtime/cds/appcds/TestParallelGCWithCDS.java fails with JNI error
- 4a1cdd5ba947ffc88c1100966e68826eb35ed441: 8333486: Parallel: Remove unused methods in psParallelCompact
- 664c993c41753843293388a6ff1481a94a5b4c22: 8331731: ubsan: relocInfo.cpp:155:30: runtime error: applying non-zero offset to null pointer
- 8d3de45f4dfd60dc4e2f210cb0c085fcf6efb8e2: 8325168: JShell should support Markdown comments
- ... and 90 more: https://git.openjdk.org/jdk/compare/43a2f17342af8f5bf1f5823df9fa0bf0bdfdfce2...master
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.
@jdksjolen 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.
Webrevs
- 125: Full - Incremental (8fd26a38)
- 124: Full - Incremental (f1dd3096)
- 123: Full - Incremental (482144be)
- 122: Full - Incremental (ee8c7da3)
- 121: Full - Incremental (ae73fda8)
- 120: Full - Incremental (fd165407)
- 119: Full - Incremental (cebd8759)
- 118: Full - Incremental (c8b90112)
- 117: Full - Incremental (924bce04)
- 116: Full - Incremental (ed1e1f21)
- 115: Full - Incremental (e401a7a4)
- 114: Full (9c37beeb)
- 113: Full - Incremental (885bc480)
- 112: Full - Incremental (90b6f6ae)
- 111: Full - Incremental (58766b5b)
- 110: Full - Incremental (16826181)
- 109: Full - Incremental (67626aca)
- 108: Full - Incremental (164996b9)
- 107: Full - Incremental (c1938adf)
- 106: Full - Incremental (4aaa0927)
- 105: Full - Incremental (f99190f0)
- 104: Full - Incremental (80605766)
- 103: Full - Incremental (75db7249)
- 102: Full - Incremental (252350c2)
- 101: Full - Incremental (8cf973af)
- 100: Full - Incremental (5c8d384a)
- 99: Full - Incremental (9f85a797)
- 98: Full - Incremental (2de1de20)
- 97: Full - Incremental (8e4f8bec)
- 96: Full - Incremental (549a9393)
- 95: Full - Incremental (0dababc3)
- 94: Full - Incremental (4a68e141)
- 93: Full - Incremental (95fc3ba2)
- 92: Full (1c3fb154)
- 91: Full - Incremental (75fcefbc)
- 90: Full - Incremental (9d2e6768)
- 89: Full - Incremental (59254f47)
- 88: Full - Incremental (d546e26c)
- 87: Full - Incremental (961d89ca)
- 86: Full - Incremental (5e453a99)
- 85: Full - Incremental (24134209)
- 84: Full - Incremental (8168b388)
- 83: Full - Incremental (fd953805)
- 82: Full - Incremental (86da2444)
- 81: Full - Incremental (d7ab6001)
- 80: Full - Incremental (57ce5254)
- 79: Full - Incremental (fb42fb0d)
- 78: Full - Incremental (e8f33dfa)
- 77: Full - Incremental (115f7e57)
- 76: Full - Incremental (327094bc)
- 75: Full - Incremental (6e30331a)
- 74: Full - Incremental (622fe067)
- 73: Full - Incremental (137af84f)
- 72: Full - Incremental (80d408d0)
- 71: Full - Incremental (3b9bb9fa)
- 70: Full - Incremental (a843a9e4)
- 69: Full - Incremental (150d17cd)
- 68: Full - Incremental (3d8875df)
- 67: Full - Incremental (693423ed)
- 66: Full - Incremental (78b75213)
- 65: Full - Incremental (510d7a3c)
- 64: Full - Incremental (daba4b5d)
- 63: Full - Incremental (91b8b44e)
- 62: Full - Incremental (50f42e8c)
- 61: Full - Incremental (53695f81)
- 60: Full - Incremental (101fbf72)
- 59: Full - Incremental (fc674b56)
- 58: Full - Incremental (c70203db)
- 57: Full - Incremental (32263c94)
- 56: Full (45bcdaba)
- 55: Full - Incremental (dba53897)
- 54: Full - Incremental (dc987443)
- 53: Full - Incremental (ed01d703)
- 52: Full - Incremental (be2f03a9)
- 51: Full - Incremental (34307e11)
- 50: Full - Incremental (cbe00a31)
- 49: Full - Incremental (dc9741ec)
- 48: Full - Incremental (c0ddb9ff)
- 47: Full - Incremental (66d5c4f4)
- 46: Full - Incremental (76c3bcfa)
- 45: Full - Incremental (e7f2af9e)
- 44: Full - Incremental (e668b569)
- 43: Full - Incremental (0175c0e6)
- 42: Full - Incremental (29375550)
- 41: Full - Incremental (0c0bfbfa)
- 40: Full - Incremental (4b51328c)
- 39: Full - Incremental (6e1b4915)
- 38: Full - Incremental (b66ba2ca)
- 37: Full - Incremental (8e3fd751)
- 36: Full - Incremental (d29d4dc0)
- 35: Full - Incremental (70ee8362)
- 34: Full - Incremental (141a38c3)
- 33: Full - Incremental (2707ee86)
- 32: Full - Incremental (3a7c4ac1)
- 31: Full - Incremental (5a3e6dd6)
- 30: Full - Incremental (b97d3282)
- 29: Full - Incremental (3793046e)
- 28: Full - Incremental (1f0e0265)
- 27: Full - Incremental (42d58f7f)
- 26: Full - Incremental (ec6d2788)
- 25: Full - Incremental (b1c569c5)
- 24: Full - Incremental (a4a8828c)
- 23: Full - Incremental (262b4ca4)
- 22: Full - Incremental (1a3b8a22)
- 21: Full - Incremental (294320cf)
- 20: Full - Incremental (fb4b7d68)
- 19: Full - Incremental (7ac1ae1e)
- 18: Full - Incremental (e87cc076)
- 17: Full - Incremental (414d0f17)
- 16: Full - Incremental (56de7bb9)
- 15: Full - Incremental (a7096782)
- 14: Full - Incremental (4478a783)
- 13: Full - Incremental (3cbe181b)
- 12: Full - Incremental (10c862ac)
- 11: Full - Incremental (13dee67a)
- 10: Full - Incremental (d0983708)
- 09: Full - Incremental (63e894bd)
- 08: Full - Incremental (d332066f)
- 07: Full - Incremental (63e2c1a1)
- 06: Full - Incremental (8e1437ca)
- 05: Full - Incremental (466ddc6e)
- 04: Full - Incremental (1928b9da)
- 03: Full - Incremental (599f2ce8)
- 02: Full - Incremental (4f761352)
- 01: Full - Incremental (2751ba89)
- 00: Full (08446455)
/contributor add tstuefe
@jdksjolen tstuefe
was not found in the census.
Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]
. For example:
-
/contributor add @openjdk-bot
-
/contributor add duke
-
/contributor add J. Duke <[email protected]>
User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address.
/contributor add @tstuefe
Or maybe /contributor add @stuefe
@jdksjolen
Contributor Thomas Stuefe <[email protected]>
successfully added.
@jdksjolen @stuefe
was not found in the census.
Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]
. For example:
-
/contributor add @openjdk-bot
-
/contributor add duke
-
/contributor add J. Duke <[email protected]>
User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address.
@stefank, thank you for the style change suggestions. They've now been applied.
⚠️ @jdksjolen This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch>
where <project>
is the name of another project in the OpenJDK organization (for example Merge jdk:master
).
OK, now it should be fixed. Sorry about that.
I've updated the code to have data on both sides, but now a bunch of my tests are failing. So, I'll have to do a bunch of work to understand why those are now failing. I'm still performing merging, however.
Right, so the tests pass again but it's not clear to me that having the metadata state in both directions really can be considered necessary/more elegant. The merging is cleaned up a bit.
I had a go at removing VMATree as a friend class of the Treap, which unfortunately made the build break. Still working on that. I need to regain some clarity on the necessity of merging. I think that we can change os::commit_memory()
such that it requires a MEMFLAGS
, in which case we can get rid of this merging. That will be some work. I could change the PR such that the API requires a MEMFLAGS
for all operations.
Thoughts?
I'm off on Easter vacation, will be back on Tuesday.
Right, the refactoring to remove the friend
declaration has completely fumbled the code. I'll probably force a revert on this to the state before that or do a git bisect to find the bugs. Right now the code is basically borked.
Last good hash: 7445999ee296872320f91146e1004026ba1133c7
Right, the refactoring to remove the
friend
declaration has completely fumbled the code. I'll probably force a revert on this to the state before that or do a git bisect to find the bugs. Right now the code is basically borked.Last good hash: 7445999
God, sorry. Do as you think is best.
I plan to look at this PR, but probably it will not be this week.
Love your commit messages btw.
Right, the refactoring to remove the
friend
declaration has completely fumbled the code. I'll probably force a revert on this to the state before that or do a git bisect to find the bugs. Right now the code is basically borked. Last good hash: 7445999God, sorry. Do as you think is best.
I plan to look at this PR, but probably it will not be this week.
Love your commit messages btw.
Nah, it's alright. It was literally that my getter right()
returned _left
, this was of course impossible for me to see after staring at the code for too long. Fixing that did lead to a good commit message, I'm happy you appreciate them :-).
I decided on the more generic IntervalChange
, IntervalState
and StateType
names. This is naming, I'm perfectly fine switching it to something else.
I've removed the merge()
functionality as I'm expecting Afshin's PR to get approved which will render adapting flags unnecessary. I did the most obvious size optimization such that each in/out state only takes 16 bytes instead of 24.
@tstuefe ,
I'll ping you (like I just did) in the comments when I've got a new version for the Treap stuff.
@jdksjolen Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.
Windows debug builds failing with following linker errors:
=== Output from failing command(s) repeated here ===
* For target hotspot_variant-server_libjvm_gtest_objs_BUILD_GTEST_LIBJVM_link:
Creating library d:\a\jdk\jdk\build\windows-aarch64\hotspot\variant-server\libjvm\gtest\objs\jvm.lib and object d:\a\jdk\jdk\build\windows-aarch64\hotspot\variant-server\libjvm\gtest\objs\jvm.exp
jvm.exp : error LNK2001: unresolved external symbol "const GrowableArrayCHeap<struct `public: struct VMATree::SummaryDiff __cdecl VMATree::register_mapping(unsigned __int64,unsigned __int64,enum VMATree::StateType,struct VMATree::Metadata &)'::`2'::AddressState,12>::`vftable'" (??_7?$GrowableArrayCHeap@UAddressState@?1??register_mapping@VMATree@@QEAA?AUSummaryDiff@3@_K0W4StateType@3@AEAUMetadata@3@@Z@$0M@@@6B@)
jvm.exp : error LNK2001: unresolved external symbol "const GrowableArrayView<struct `public: struct VMATree::SummaryDiff __cdecl VMATree::register_mapping(unsigned __int64,unsigned __int64,enum VMATree::StateType,struct VMATree::Metadata &)'::`2'::AddressState>::`vftable'" (??_7?$GrowableArrayView@UAddressState@?1??register_mapping@VMATree@@QEAA?AUSummaryDiff@3@_K0W4StateType@3@AEAUMetadata@3@@Z@@@6B@)
jvm.exp : error LNK2001: unresolved external symbol "const GrowableArrayWithAllocator<struct `public: struct VMATree::SummaryDiff __cdecl VMATree::register_mapping(unsigned __int64,unsigned __int64,enum VMATree::StateType,struct VMATree::Metadata &)'::`2'::AddressState,class GrowableArrayCHeap<struct `public: struct VMATree::SummaryDiff __cdecl VMATree::register_mapping(unsigned __int64,unsigned __int64,enum VMATree::StateType,struct VMATree::Metadata &)'::`2'::AddressState,12> >::`vftable'" (??_7?$GrowableArrayWithAllocator@UAddressState@?1??register_mapping@VMATree@@QEAA?AUSummaryDiff@3@_K0W4StateType@3@AEAUMetadata@3@@Z@V?$GrowableArrayCHeap@UAddressState@?1??register_mapping@VMATree@@QEAA?AUSummaryDiff@3@_K0W4StateType@3@AEAUMetadata@3@@Z@$0M@@@@@6B@)
d:\a\jdk\jdk\build\windows-aarch64\hotspot\variant-server\libjvm\gtest\jvm.dll : fatal error LNK1120: 3 unresolved externals
* For target hotspot_variant-server_libjvm_objs_BUILD_LIBJVM_link:
Creating library d:\a\jdk\jdk\build\windows-aarch64\hotspot\variant-server\libjvm\objs\jvm.lib and object d:\a\jdk\jdk\build\windows-aarch64\hotspot\variant-server\libjvm\objs\jvm.exp
jvm.exp : error LNK2001: unresolved external symbol "const GrowableArrayCHeap<struct `public: struct VMATree::SummaryDiff __cdecl VMATree::register_mapping(unsigned __int64,unsigned __int64,enum VMATree::StateType,struct VMATree::Metadata &)'::`2'::AddressState,12>::`vftable'" (??_7?$GrowableArrayCHeap@UAddressState@?1??register_mapping@VMATree@@QEAA?AUSummaryDiff@3@_K0W4StateType@3@AEAUMetadata@3@@Z@$0M@@@6B@)
jvm.exp : error LNK2001: unresolved external symbol "const GrowableArrayView<struct `public: struct VMATree::SummaryDiff __cdecl VMATree::register_mapping(unsigned __int64,unsigned __int64,enum VMATree::StateType,struct VMATree::Metadata &)'::`2'::AddressState>::`vftable'" (??_7?$GrowableArrayView@UAddressState@?1??register_mapping@VMATree@@QEAA?AUSummaryDiff@3@_K0W4StateType@3@AEAUMetadata@3@@Z@@@6B@)
jvm.exp : error LNK2001: unresolved external symbol "const GrowableArrayWithAllocator<struct `public: struct VMATree::SummaryDiff __cdecl VMATree::register_mapping(unsigned __int64,unsigned __int64,enum VMATree::StateType,struct VMATree::Metadata &)'::`2'::AddressState,class GrowableArrayCHeap<struct `public: struct VMATree::SummaryDiff __cdecl VMATree::register_mapping(unsigned __int64,unsigned __int64,enum VMATree::StateType,struct VMATree::Metadata &)'::`2'::AddressState,12> >::`vftable'" (??_7?$GrowableArrayWithAllocator@UAddressState@?1??register_mapping@VMATree@@QEAA?AUSummaryDiff@3@_K0W4StateType@3@AEAUMetadata@3@@Z@V?$GrowableArrayCHeap@UAddressState@?1??register_mapping@VMATree@@QEAA?AUSummaryDiff@3@_K0W4StateType@3@AEAUMetadata@3@@Z@$0M@@@@@6B@)
d:\a\jdk\jdk\build\windows-aarch64\support\modules_libs\java.base\server\jvm.dll : fatal error LNK1120: 3 unresolved externals
Fixed a bug that Afshin found w.r.t. summary accounting. The double-arrow thing really helped out there, so I'm happy with keeping that.
Taking a look...
Hi @tstuefe,
Cleaned up Treap significantly, it looks way better now! Thanks for the ideas.
Good. Will try to take a look on Thursday or Friday.
@jdksjolen Are you going to update the code in response to Afshin feedback sometime soon?
I find it a bit hard to look at the code tagged with so many comments, so if you are thinking about updating it sometime soon, I'd prefer to wait reviewing it.
First pass through working through the most of Afshin's comments. Thanks!
@jdksjolen Are you going to update the code in response to Afshin feedback sometime soon?
I find it a bit hard to look at the code tagged with so many comments, so if you are thinking about updating it sometime soon, I'd prefer to wait reviewing it.
Hi Gerard,
Go to "Files changed", scroll to a comment and press "i", all comments should now be hidden.
I will take a closer look later today, and also clean out some of my obsolete comments. GH interface is really not made for complex patches.