Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8251255: [linux] Add process-memory information to hs-err and VM.info
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, mdoerr
  • Loading branch information
tstuefe committed Aug 10, 2020
1 parent ff76801 commit fc913d4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
67 changes: 65 additions & 2 deletions src/hotspot/os/linux/os_linux.cpp
Expand Up @@ -110,6 +110,9 @@
# include <inttypes.h>
# include <sys/ioctl.h>
# include <linux/elf-em.h>
#ifdef __GLIBC__
# include <malloc.h>
#endif

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
Expand Down Expand Up @@ -2156,7 +2159,10 @@ void os::print_os_info(outputStream* st) {
os::Posix::print_load_average(st);
st->cr();

os::Linux::print_full_memory_info(st);
os::Linux::print_system_memory_info(st);
st->cr();

os::Linux::print_process_memory_info(st);
st->cr();

os::Linux::print_proc_sys_info(st);
Expand Down Expand Up @@ -2314,7 +2320,7 @@ void os::Linux::print_proc_sys_info(outputStream* st) {
"/proc/sys/kernel/pid_max", st);
}

void os::Linux::print_full_memory_info(outputStream* st) {
void os::Linux::print_system_memory_info(outputStream* st) {
_print_ascii_file_h("/proc/meminfo", "/proc/meminfo", st, false);
st->cr();

Expand All @@ -2326,6 +2332,63 @@ void os::Linux::print_full_memory_info(outputStream* st) {
"/sys/kernel/mm/transparent_hugepage/defrag", st);
}

void os::Linux::print_process_memory_info(outputStream* st) {

st->print_cr("Process Memory:");

// Print virtual and resident set size; peak values; swap; and for
// rss its components if the kernel is recent enough.
ssize_t vmsize = -1, vmpeak = -1, vmswap = -1,
vmrss = -1, vmhwm = -1, rssanon = -1, rssfile = -1, rssshmem = -1;
const int num_values = 8;
int num_found = 0;
FILE* f = ::fopen("/proc/self/status", "r");
char buf[256];
while (::fgets(buf, sizeof(buf), f) != NULL && num_found < num_values) {
if ( (vmsize == -1 && sscanf(buf, "VmSize: " SSIZE_FORMAT " kB", &vmsize) == 1) ||
(vmpeak == -1 && sscanf(buf, "VmPeak: " SSIZE_FORMAT " kB", &vmpeak) == 1) ||
(vmswap == -1 && sscanf(buf, "VmSwap: " SSIZE_FORMAT " kB", &vmswap) == 1) ||
(vmhwm == -1 && sscanf(buf, "VmHWM: " SSIZE_FORMAT " kB", &vmhwm) == 1) ||
(vmrss == -1 && sscanf(buf, "VmRSS: " SSIZE_FORMAT " kB", &vmrss) == 1) ||
(rssanon == -1 && sscanf(buf, "RssAnon: " SSIZE_FORMAT " kB", &rssanon) == 1) ||
(rssfile == -1 && sscanf(buf, "RssFile: " SSIZE_FORMAT " kB", &rssfile) == 1) ||
(rssshmem == -1 && sscanf(buf, "RssShmem: " SSIZE_FORMAT " kB", &rssshmem) == 1)
)
{
num_found ++;
}
}
st->print_cr("Virtual Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", vmsize, vmpeak);
st->print("Resident Set Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", vmrss, vmhwm);
if (rssanon != -1) { // requires kernel >= 4.5
st->print(" (anon: " SSIZE_FORMAT "K, file: " SSIZE_FORMAT "K, shmem: " SSIZE_FORMAT "K)",
rssanon, rssfile, rssshmem);
}
st->cr();
if (vmswap != -1) { // requires kernel >= 2.6.34
st->print_cr("Swapped out: " SSIZE_FORMAT "K", vmswap);
}

// Print glibc outstanding allocations.
// (note: there is no implementation of mallinfo for muslc)
#ifdef __GLIBC__
struct mallinfo mi = ::mallinfo();

// 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.
const size_t total_allocated = (size_t)(unsigned)mi.uordblks;
st->print("C-Heap outstanding allocations: " SIZE_FORMAT "K", total_allocated / K);
// Since mallinfo members are int, glibc values may have wrapped. Warn about this.
if ((vmrss * K) > UINT_MAX && (vmrss * K) > (total_allocated + UINT_MAX)) {
st->print(" (may have wrapped)");
}
st->cr();

#endif // __GLIBC__

}

bool os::Linux::print_ld_preload_file(outputStream* st) {
return _print_ascii_file("/etc/ld.so.preload", st, "/etc/ld.so.preload:");
}
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/os/linux/os_linux.hpp
Expand Up @@ -101,7 +101,8 @@ class Linux {
static bool release_memory_special_shm(char* base, size_t bytes);
static bool release_memory_special_huge_tlbfs(char* base, size_t bytes);

static void print_full_memory_info(outputStream* st);
static void print_process_memory_info(outputStream* st);
static void print_system_memory_info(outputStream* st);
static bool print_container_info(outputStream* st);
static void print_steal_info(outputStream* st);
static void print_distro_info(outputStream* st);
Expand Down

0 comments on commit fc913d4

Please sign in to comment.