Skip to content

Commit 7cef5a5

Browse files
committed
8286198: [linux] Fix process-memory information
Backport-of: 9e320d9ab1813eda705d7318ef964092c50d1ade
1 parent f9a6e0c commit 7cef5a5

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
@@ -2232,23 +2232,26 @@ void os::Linux::print_process_memory_info(outputStream* st) {
22322232
// - Print glibc tunables
22332233
#ifdef __GLIBC__
22342234
size_t total_allocated = 0;
2235+
size_t free_retained = 0;
22352236
bool might_have_wrapped = false;
22362237
if (_mallinfo2 != NULL) {
22372238
struct glibc_mallinfo2 mi = _mallinfo2();
2238-
total_allocated = mi.uordblks;
2239+
total_allocated = mi.uordblks + mi.hblkhd;
2240+
free_retained = mi.fordblks;
22392241
} else if (_mallinfo != NULL) {
22402242
// mallinfo is an old API. Member names mean next to nothing and, beyond that, are 32-bit signed.
22412243
// So for larger footprints the values may have wrapped around. We try to detect this here: if the
22422244
// process whole resident set size is smaller than 4G, malloc footprint has to be less than that
22432245
// and the numbers are reliable.
22442246
struct glibc_mallinfo mi = _mallinfo();
2245-
total_allocated = (size_t)(unsigned)mi.uordblks;
2247+
total_allocated = (size_t)(unsigned)mi.uordblks + (size_t)(unsigned)mi.hblkhd;
2248+
free_retained = (size_t)(unsigned)mi.fordblks;
22462249
// Since mallinfo members are int, glibc values may have wrapped. Warn about this.
22472250
might_have_wrapped = (info.vmrss * K) > UINT_MAX && (info.vmrss * K) > (total_allocated + UINT_MAX);
22482251
}
22492252
if (_mallinfo2 != NULL || _mallinfo != NULL) {
2250-
st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K%s",
2251-
total_allocated / K,
2253+
st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K, retained: " SIZE_FORMAT "K%s",
2254+
total_allocated / K, free_retained / K,
22522255
might_have_wrapped ? " (may have wrapped)" : "");
22532256
}
22542257
// Tunables

0 commit comments

Comments
 (0)