8282382: Report glibc malloc tunables in error reports

Reviewed-by: zgu, dholmes
This commit is contained in:
Thomas Stuefe 2022-03-05 06:37:39 +00:00
parent 52278b80c4
commit bc42e7cbbf

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -2092,6 +2093,34 @@ bool os::Linux::query_process_memory_info(os::Linux::meminfo_t* info) {
return false;
}
#ifdef __GLIBC__
// For Glibc, print a one-liner with the malloc tunables.
// Most important and popular is MALLOC_ARENA_MAX, but we are
// thorough and print them all.
static void print_glibc_malloc_tunables(outputStream* st) {
static const char* var[] = {
// the new variant
"GLIBC_TUNABLES",
// legacy variants
"MALLOC_CHECK_", "MALLOC_TOP_PAD_", "MALLOC_PERTURB_",
"MALLOC_MMAP_THRESHOLD_", "MALLOC_TRIM_THRESHOLD_",
"MALLOC_MMAP_MAX_", "MALLOC_ARENA_TEST", "MALLOC_ARENA_MAX",
NULL};
st->print("glibc malloc tunables: ");
bool printed = false;
for (int i = 0; var[i] != NULL; i ++) {
const char* const val = ::getenv(var[i]);
if (val != NULL) {
st->print("%s%s=%s", (printed ? ", " : ""), var[i], val);
printed = true;
}
}
if (!printed) {
st->print("(default)");
}
}
#endif // __GLIBC__
void os::Linux::print_process_memory_info(outputStream* st) {
st->print_cr("Process Memory:");
@ -2114,8 +2143,9 @@ void os::Linux::print_process_memory_info(outputStream* st) {
st->print_cr("Could not open /proc/self/status to get process memory related information");
}
// Print glibc outstanding allocations.
// (note: there is no implementation of mallinfo for muslc)
// glibc only:
// - Print outstanding allocations using mallinfo
// - Print glibc tunables
#ifdef __GLIBC__
size_t total_allocated = 0;
bool might_have_wrapped = false;
@ -2123,9 +2153,10 @@ void os::Linux::print_process_memory_info(outputStream* st) {
struct glibc_mallinfo2 mi = _mallinfo2();
total_allocated = mi.uordblks;
} 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.
// mallinfo is an old API. Member names mean next to nothing and, beyond that, are 32-bit signed.
// So for larger footprints the values may have wrapped around. We try to detect this here: if the
// process whole resident set size is smaller than 4G, malloc footprint has to be less than that
// and the numbers are reliable.
struct glibc_mallinfo mi = _mallinfo();
total_allocated = (size_t)(unsigned)mi.uordblks;
// Since mallinfo members are int, glibc values may have wrapped. Warn about this.
@ -2136,8 +2167,10 @@ void os::Linux::print_process_memory_info(outputStream* st) {
total_allocated / K,
might_have_wrapped ? " (may have wrapped)" : "");
}
#endif // __GLIBC__
// Tunables
print_glibc_malloc_tunables(st);
st->cr();
#endif
}
bool os::Linux::print_ld_preload_file(outputStream* st) {