mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 01:54:47 +02:00
8268893: jcmd to trim the glibc heap
Reviewed-by: simonis, dholmes
This commit is contained in:
parent
c36755dedf
commit
6096dd9765
6 changed files with 239 additions and 26 deletions
|
@ -2148,44 +2148,51 @@ void os::Linux::print_system_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;
|
||||
bool os::Linux::query_process_memory_info(os::Linux::meminfo_t* info) {
|
||||
FILE* f = ::fopen("/proc/self/status", "r");
|
||||
const int num_values = sizeof(os::Linux::meminfo_t) / sizeof(size_t);
|
||||
int num_found = 0;
|
||||
char buf[256];
|
||||
info->vmsize = info->vmpeak = info->vmrss = info->vmhwm = info->vmswap =
|
||||
info->rssanon = info->rssfile = info->rssshmem = -1;
|
||||
if (f != NULL) {
|
||||
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)
|
||||
if ( (info->vmsize == -1 && sscanf(buf, "VmSize: " SSIZE_FORMAT " kB", &info->vmsize) == 1) ||
|
||||
(info->vmpeak == -1 && sscanf(buf, "VmPeak: " SSIZE_FORMAT " kB", &info->vmpeak) == 1) ||
|
||||
(info->vmswap == -1 && sscanf(buf, "VmSwap: " SSIZE_FORMAT " kB", &info->vmswap) == 1) ||
|
||||
(info->vmhwm == -1 && sscanf(buf, "VmHWM: " SSIZE_FORMAT " kB", &info->vmhwm) == 1) ||
|
||||
(info->vmrss == -1 && sscanf(buf, "VmRSS: " SSIZE_FORMAT " kB", &info->vmrss) == 1) ||
|
||||
(info->rssanon == -1 && sscanf(buf, "RssAnon: " SSIZE_FORMAT " kB", &info->rssanon) == 1) || // Needs Linux 4.5
|
||||
(info->rssfile == -1 && sscanf(buf, "RssFile: " SSIZE_FORMAT " kB", &info->rssfile) == 1) || // Needs Linux 4.5
|
||||
(info->rssshmem == -1 && sscanf(buf, "RssShmem: " SSIZE_FORMAT " kB", &info->rssshmem) == 1) // Needs Linux 4.5
|
||||
)
|
||||
{
|
||||
num_found ++;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
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.
|
||||
meminfo_t info;
|
||||
if (query_process_memory_info(&info)) {
|
||||
st->print_cr("Virtual Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", info.vmsize, info.vmpeak);
|
||||
st->print("Resident Set Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", info.vmrss, info.vmhwm);
|
||||
if (info.rssanon != -1) { // requires kernel >= 4.5
|
||||
st->print(" (anon: " SSIZE_FORMAT "K, file: " SSIZE_FORMAT "K, shmem: " SSIZE_FORMAT "K)",
|
||||
rssanon, rssfile, rssshmem);
|
||||
info.rssanon, info.rssfile, info.rssshmem);
|
||||
}
|
||||
st->cr();
|
||||
if (vmswap != -1) { // requires kernel >= 2.6.34
|
||||
st->print_cr("Swapped out: " SSIZE_FORMAT "K", vmswap);
|
||||
if (info.vmswap != -1) { // requires kernel >= 2.6.34
|
||||
st->print_cr("Swapped out: " SSIZE_FORMAT "K", info.vmswap);
|
||||
}
|
||||
} else {
|
||||
st->print_cr("Could not open /proc/self/status to get process memory related information");
|
||||
|
@ -2206,7 +2213,7 @@ void os::Linux::print_process_memory_info(outputStream* st) {
|
|||
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.
|
||||
might_have_wrapped = (vmrss * K) > UINT_MAX && (vmrss * K) > (total_allocated + UINT_MAX);
|
||||
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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue