8221325: Add information about swap space to print_memory_info() on MacOS
authorrschmelter
Tue, 26 Mar 2019 01:46:06 -0700
changeset 54420 724b9e361cb6
parent 54419 5c7418757bad
child 54421 a7df0de0835a
8221325: Add information about swap space to print_memory_info() on MacOS Reviewed-by: stuefe, dholmes
src/hotspot/os/bsd/os_bsd.cpp
--- a/src/hotspot/os/bsd/os_bsd.cpp	Wed Apr 03 20:39:19 2019 -0400
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Tue Mar 26 01:46:06 2019 -0700
@@ -1598,6 +1598,8 @@
 }
 
 void os::print_memory_info(outputStream* st) {
+  xsw_usage swap_usage;
+  size_t size = sizeof(swap_usage);
 
   st->print("Memory:");
   st->print(" %dk page", os::vm_page_size()>>10);
@@ -1606,6 +1608,16 @@
             os::physical_memory() >> 10);
   st->print("(" UINT64_FORMAT "k free)",
             os::available_memory() >> 10);
+
+  if((sysctlbyname("vm.swapusage", &swap_usage, &size, NULL, 0) == 0) || (errno == ENOMEM)) {
+    if (size >= offset_of(xsw_usage, xsu_used)) {
+      st->print(", swap " UINT64_FORMAT "k",
+                ((julong) swap_usage.xsu_total) >> 10);
+      st->print("(" UINT64_FORMAT "k free)",
+                ((julong) swap_usage.xsu_avail) >> 10);
+    }
+  }
+
   st->cr();
 }