From 0b9bee7169a497cbb7891bc2f5a7ba1daa434e9a Mon Sep 17 00:00:00 2001 From: Thomas Stuefe Date: Sun, 15 May 2022 16:24:09 +0000 Subject: [PATCH] 8286198: [linux] Fix process-memory information Backport-of: 9e320d9ab1813eda705d7318ef964092c50d1ade --- src/hotspot/os/linux/os_linux.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 9d829e0aa99..87eb645c4df 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -2118,22 +2118,25 @@ void os::Linux::print_process_memory_info(outputStream* st) { // (note: there is no implementation of mallinfo for muslc) #ifdef __GLIBC__ size_t total_allocated = 0; + size_t free_retained = 0; bool might_have_wrapped = false; if (_mallinfo2 != NULL) { struct glibc_mallinfo2 mi = _mallinfo2(); - total_allocated = mi.uordblks; + total_allocated = mi.uordblks + mi.hblkhd; + free_retained = mi.fordblks; } else if (_mallinfo != NULL) { // mallinfo is an old API. Member names mean next to nothing and, beyond that, are int. // So values may have wrapped around. Still useful enough to see how much glibc thinks // we allocated. struct glibc_mallinfo mi = _mallinfo(); - total_allocated = (size_t)(unsigned)mi.uordblks; + total_allocated = (size_t)(unsigned)mi.uordblks + (size_t)(unsigned)mi.hblkhd; + free_retained = (size_t)(unsigned)mi.fordblks; // Since mallinfo members are int, glibc values may have wrapped. Warn about this. might_have_wrapped = (info.vmrss * K) > UINT_MAX && (info.vmrss * K) > (total_allocated + UINT_MAX); } if (_mallinfo2 != NULL || _mallinfo != NULL) { - st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K%s", - total_allocated / K, + st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K, retained: " SIZE_FORMAT "K%s", + total_allocated / K, free_retained / K, might_have_wrapped ? " (may have wrapped)" : ""); } #endif // __GLIBC__