Skip to content

8350973: Add memory overhead counter to NMT #23921

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gerard-ziemski
Copy link

@gerard-ziemski gerard-ziemski commented Mar 5, 2025


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

Error

 ⚠️ The pull request body must not be empty.

Warnings

 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/BorderLayout-1.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/FlowLayout-1.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/GridBagLayout-1.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/GridBagLayout-2.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/GridLayout-1.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/GridLayout-2.gif)
 ⚠️ Patch contains a binary file (src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/glass.png)
 ⚠️ Patch contains a binary file (src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/x.png)
 ⚠️ Patch contains a binary file (test/hotspot/jtreg/runtime/ClassFile/JsrRewritingTestCase.jar)
 ⚠️ Patch contains a binary file (test/hotspot/jtreg/runtime/ClassFile/testcase.jar)

Issue

  • JDK-8350973: Add memory overhead counter to NMT (Enhancement - P4) ⚠️ Issue is not open.

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23921

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 5, 2025

👋 Welcome back gziemski! 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
Copy link

openjdk bot commented Mar 5, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Mar 5, 2025

@gerard-ziemski The following label will be automatically applied to this pull request:

  • hotspot-runtime

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
Copy link

openjdk bot commented Mar 7, 2025

@gerard-ziemski this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8350973
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Mar 7, 2025
@@ -282,7 +282,7 @@ void Arena::set_size_in_bytes(size_t size) {
if (_size_in_bytes != size) {
ssize_t delta = size - size_in_bytes();
_size_in_bytes = size;
MemTracker::record_arena_size_change(delta, _mem_tag);
MemTracker::record_arena_size_change(delta, 0, _mem_tag);
Copy link
Contributor

@afshin-zafari afshin-zafari Apr 1, 2025

Choose a reason for hiding this comment

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

Here the allocated param is passed as 0, which means that the allocated amount won't change whereas the requested amount will change. So the calculation of overhead in memReporter.cpp (size_t overhead = c->allocated() - c->requested();) results in a negative number and changed to unsigned and becomes a very large positive number. This may describe why the Aren overhead in NMT report is more than 100%. This also affects the total overhead reported at the beginning of the NMT report.

@@ -101,6 +101,9 @@ void MemReporterBase::print_malloc(const MemoryCounter* c, MemTag mem_tag) const
out->print(" (peak=%zu%s #%zu)",
amount_in_current_scale(pk_amount), scale, pk_count);
}
size_t overhead = c->allocated() - c->requested();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to have an assert(c->allocated() >= c->requested(), "should be");.

_malloc[chunk_idx].record_free(arena_size);
_all_mallocs.deallocate(arena_size);
_malloc[chunk_idx].record_free(arena_size, 0);
_all_mallocs.deallocate(arena_size, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here also the allocated param is passed as 0. This makes the accounting incorrect. The requested changes but allocated not.

* The counters are updated atomically.
*/
class MemoryCounter {
private:
volatile size_t _count;
volatile size_t _size;
volatile size_t _requested; // how much bytes we asked for
Copy link
Contributor

Choose a reason for hiding this comment

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

how much -> how many

}
}

inline size_t count() const { return Atomic::load(&_count); }
inline size_t size() const { return Atomic::load(&_size); }
inline size_t size() const { return Atomic::load(&_requested); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Since there is no _size anymore, it is better to remove size() as well.

}

inline void record_arena_size_change(ssize_t sz) {
_arena.resize(sz);
inline void record_arena_size_change(ssize_t requested, size_t allocated) {
Copy link
Contributor

Choose a reason for hiding this comment

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

allocated can also be negative since it is delta. So ssize_t for its type.

inline size_t malloc_overhead() const {
return _all_mallocs.count() * MallocHeader::malloc_overhead();
return _all_mallocs.allocated() - _all_mallocs.requested();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need an assert for negative amounts of the result?

@@ -141,7 +141,7 @@ class MemBaseline {
size_t malloc_tracking_overhead() const {
assert(baseline_type() != Not_baselined, "Not yet baselined");
MemBaseline* bl = const_cast<MemBaseline*>(this);
return bl->_malloc_memory_snapshot.malloc_overhead();
return bl->_malloc_memory_snapshot.nmt_overhead();
Copy link
Contributor

@afshin-zafari afshin-zafari Apr 1, 2025

Choose a reason for hiding this comment

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

Better name for nmt_overhead() would be malloc_tracking_overhead() to be similar to its caller as here.

const NativeCallStack& stack) {
assert(mem_base != nullptr, "caller should handle null");
if (enabled()) {
return MallocTracker::record_malloc(mem_base, size, mem_tag, stack);
//fprintf(stderr, "record_malloc:%p:%zu\n", mem_base, requested);
Copy link
Contributor

Choose a reason for hiding this comment

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

Dead code.

#elif defined(__APPLE__)
#include <malloc/malloc.h>
static size_t raw_malloc_size(void* ptr) { ALLOW_C_FUNCTION(::malloc_size, return ::malloc_size(ptr);) }
//static size_t raw_malloc_size(void* ptr) { size_t allocated = _raw_malloc_size(ptr); fprintf(stderr, "%p:%zu\n", ptr, allocated); return allocated; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Dead code.

@bridgekeeper
Copy link

bridgekeeper bot commented May 27, 2025

@gerard-ziemski This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime [email protected] merge-conflict Pull request has merge conflict with target branch
Development

Successfully merging this pull request may close these issues.

2 participants