Skip to content

Commit 9e320d9

Browse files
committed
8286198: [linux] Fix process-memory information
Reviewed-by: dholmes, mbaesken
1 parent 65f5067 commit 9e320d9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/hotspot/os/linux/os_linux.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -2152,23 +2152,26 @@ void os::Linux::print_process_memory_info(outputStream* st) {
21522152
// - Print glibc tunables
21532153
#ifdef __GLIBC__
21542154
size_t total_allocated = 0;
2155+
size_t free_retained = 0;
21552156
bool might_have_wrapped = false;
21562157
if (_mallinfo2 != NULL) {
21572158
struct glibc_mallinfo2 mi = _mallinfo2();
2158-
total_allocated = mi.uordblks;
2159+
total_allocated = mi.uordblks + mi.hblkhd;
2160+
free_retained = mi.fordblks;
21592161
} else if (_mallinfo != NULL) {
21602162
// mallinfo is an old API. Member names mean next to nothing and, beyond that, are 32-bit signed.
21612163
// So for larger footprints the values may have wrapped around. We try to detect this here: if the
21622164
// process whole resident set size is smaller than 4G, malloc footprint has to be less than that
21632165
// and the numbers are reliable.
21642166
struct glibc_mallinfo mi = _mallinfo();
2165-
total_allocated = (size_t)(unsigned)mi.uordblks;
2167+
total_allocated = (size_t)(unsigned)mi.uordblks + (size_t)(unsigned)mi.hblkhd;
2168+
free_retained = (size_t)(unsigned)mi.fordblks;
21662169
// Since mallinfo members are int, glibc values may have wrapped. Warn about this.
21672170
might_have_wrapped = (info.vmrss * K) > UINT_MAX && (info.vmrss * K) > (total_allocated + UINT_MAX);
21682171
}
21692172
if (_mallinfo2 != NULL || _mallinfo != NULL) {
2170-
st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K%s",
2171-
total_allocated / K,
2173+
st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K, retained: " SIZE_FORMAT "K%s",
2174+
total_allocated / K, free_retained / K,
21722175
might_have_wrapped ? " (may have wrapped)" : "");
21732176
}
21742177
// Tunables

0 commit comments

Comments
 (0)