Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk18u Public archive

Commit 0b9bee7

Browse files
committed
8286198: [linux] Fix process-memory information
Backport-of: 9e320d9ab1813eda705d7318ef964092c50d1ade
1 parent 3b7473c commit 0b9bee7

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
@@ -2118,22 +2118,25 @@ void os::Linux::print_process_memory_info(outputStream* st) {
21182118
// (note: there is no implementation of mallinfo for muslc)
21192119
#ifdef __GLIBC__
21202120
size_t total_allocated = 0;
2121+
size_t free_retained = 0;
21212122
bool might_have_wrapped = false;
21222123
if (_mallinfo2 != NULL) {
21232124
struct glibc_mallinfo2 mi = _mallinfo2();
2124-
total_allocated = mi.uordblks;
2125+
total_allocated = mi.uordblks + mi.hblkhd;
2126+
free_retained = mi.fordblks;
21252127
} else if (_mallinfo != NULL) {
21262128
// mallinfo is an old API. Member names mean next to nothing and, beyond that, are int.
21272129
// So values may have wrapped around. Still useful enough to see how much glibc thinks
21282130
// we allocated.
21292131
struct glibc_mallinfo mi = _mallinfo();
2130-
total_allocated = (size_t)(unsigned)mi.uordblks;
2132+
total_allocated = (size_t)(unsigned)mi.uordblks + (size_t)(unsigned)mi.hblkhd;
2133+
free_retained = (size_t)(unsigned)mi.fordblks;
21312134
// Since mallinfo members are int, glibc values may have wrapped. Warn about this.
21322135
might_have_wrapped = (info.vmrss * K) > UINT_MAX && (info.vmrss * K) > (total_allocated + UINT_MAX);
21332136
}
21342137
if (_mallinfo2 != NULL || _mallinfo != NULL) {
2135-
st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K%s",
2136-
total_allocated / K,
2138+
st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K, retained: " SIZE_FORMAT "K%s",
2139+
total_allocated / K, free_retained / K,
21372140
might_have_wrapped ? " (may have wrapped)" : "");
21382141
}
21392142
#endif // __GLIBC__

0 commit comments

Comments
 (0)