Skip to content

Commit 7921cc1

Browse files
committed
8286198: [linux] Fix process-memory information
Backport-of: 9e320d9ab1813eda705d7318ef964092c50d1ade
1 parent fa37935 commit 7921cc1

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
@@ -2404,23 +2404,26 @@ void os::Linux::print_process_memory_info(outputStream* st) {
24042404
// - Print glibc tunables
24052405
#ifdef __GLIBC__
24062406
size_t total_allocated = 0;
2407+
size_t free_retained = 0;
24072408
bool might_have_wrapped = false;
24082409
if (_mallinfo2 != NULL) {
24092410
struct glibc_mallinfo2 mi = _mallinfo2();
2410-
total_allocated = mi.uordblks;
2411+
total_allocated = mi.uordblks + mi.hblkhd;
2412+
free_retained = mi.fordblks;
24112413
} else if (_mallinfo != NULL) {
24122414
// mallinfo is an old API. Member names mean next to nothing and, beyond that, are 32-bit signed.
24132415
// So for larger footprints the values may have wrapped around. We try to detect this here: if the
24142416
// process whole resident set size is smaller than 4G, malloc footprint has to be less than that
24152417
// and the numbers are reliable.
24162418
struct glibc_mallinfo mi = _mallinfo();
2417-
total_allocated = (size_t)(unsigned)mi.uordblks;
2419+
total_allocated = (size_t)(unsigned)mi.uordblks + (size_t)(unsigned)mi.hblkhd;
2420+
free_retained = (size_t)(unsigned)mi.fordblks;
24182421
// Since mallinfo members are int, glibc values may have wrapped. Warn about this.
24192422
might_have_wrapped = (vmrss * K) > UINT_MAX && (vmrss * K) > (total_allocated + UINT_MAX);
24202423
}
24212424
if (_mallinfo2 != NULL || _mallinfo != NULL) {
2422-
st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K%s",
2423-
total_allocated / K,
2425+
st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K, retained: " SIZE_FORMAT "K%s",
2426+
total_allocated / K, free_retained / K,
24242427
might_have_wrapped ? " (may have wrapped)" : "");
24252428
}
24262429
// Tunables

0 commit comments

Comments
 (0)