From fdb4a87d165a85210f4d5b1ae4a30c992555ed7d Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Wed, 20 Jul 2022 06:53:26 +0000 Subject: [PATCH] 8284758: [linux] improve print_container_info Reviewed-by: sgehwolf Backport-of: 6c6d5223dfaae268f968f4292356d4be89adb122 --- hotspot/src/os/linux/vm/os_linux.cpp | 57 +++++++++------------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/hotspot/src/os/linux/vm/os_linux.cpp b/hotspot/src/os/linux/vm/os_linux.cpp index 6aabeb1ef5..b6fd444a01 100644 --- a/hotspot/src/os/linux/vm/os_linux.cpp +++ b/hotspot/src/os/linux/vm/os_linux.cpp @@ -2292,6 +2292,19 @@ void os::Linux::print_full_memory_info(outputStream* st) { st->cr(); } +static void print_container_helper(outputStream* st, jlong j, const char* metrics) { + st->print("%s: ", metrics); + if (j > 0) { + if (j >= 1024) { + st->print_cr(UINT64_FORMAT " k", uint64_t(j) / 1024); + } else { + st->print_cr(UINT64_FORMAT, uint64_t(j)); + } + } else { + st->print_cr("%s", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); + } +} + void os::Linux::print_container_info(outputStream* st) { if (!OSContainer::is_containerized()) { return; @@ -2342,45 +2355,11 @@ void os::Linux::print_container_info(outputStream* st) { st->print("%s\n", i == OSCONTAINER_ERROR ? "not supported" : "no shares"); } - jlong j = OSContainer::memory_limit_in_bytes(); - st->print("memory_limit_in_bytes: "); - if (j > 0) { - st->print(JLONG_FORMAT "\n", j); - } else { - st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); - } - - j = OSContainer::memory_and_swap_limit_in_bytes(); - st->print("memory_and_swap_limit_in_bytes: "); - if (j > 0) { - st->print(JLONG_FORMAT "\n", j); - } else { - st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); - } - - j = OSContainer::memory_soft_limit_in_bytes(); - st->print("memory_soft_limit_in_bytes: "); - if (j > 0) { - st->print(JLONG_FORMAT "\n", j); - } else { - st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); - } - - j = OSContainer::OSContainer::memory_usage_in_bytes(); - st->print("memory_usage_in_bytes: "); - if (j > 0) { - st->print(JLONG_FORMAT "\n", j); - } else { - st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); - } - - j = OSContainer::OSContainer::memory_max_usage_in_bytes(); - st->print("memory_max_usage_in_bytes: "); - if (j > 0) { - st->print(JLONG_FORMAT "\n", j); - } else { - st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); - } + print_container_helper(st, OSContainer::memory_limit_in_bytes(), "memory_limit_in_bytes"); + print_container_helper(st, OSContainer::memory_and_swap_limit_in_bytes(), "memory_and_swap_limit_in_bytes"); + print_container_helper(st, OSContainer::memory_soft_limit_in_bytes(), "memory_soft_limit_in_bytes"); + print_container_helper(st, OSContainer::memory_usage_in_bytes(), "memory_usage_in_bytes"); + print_container_helper(st, OSContainer::memory_max_usage_in_bytes(), "memory_max_usage_in_bytes"); st->cr(); }