summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2021-08-21 00:15:00 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2021-08-21 00:22:26 +0200
commitec06b6d64b99bf39dd7728787efc352db3c7cabc (patch)
treed15fef7a6a49f51e39eae6c6d3a555c461833fc5
parent4a704a0ad95973249544f3f95e30e328e701a871 (diff)
db: Add show vmstat command
with an output similar to the userland vmstat command * vm/vm_page.c (db_show_vmstat): New function. * vm/vm_page.h (db_show_vmstat): New prototype. * ddb/db_command.c (db_show_cmds): Add vmstat command.
-rw-r--r--ddb/db_command.c2
-rw-r--r--vm/vm_page.c43
-rw-r--r--vm/vm_page.h5
3 files changed, 50 insertions, 0 deletions
diff --git a/ddb/db_command.c b/ddb/db_command.c
index c9538c6a..1d4052cd 100644
--- a/ddb/db_command.c
+++ b/ddb/db_command.c
@@ -62,6 +62,7 @@
#include <ipc/ipc_port.h> /* 4proto */
#include <vm/vm_print.h>
+#include <vm/vm_page.h>
#include <ipc/ipc_print.h>
#include <ipc/mach_port.h>
#include <kern/lock.h>
@@ -330,6 +331,7 @@ struct db_command db_show_cmds[] = {
{ "msg", ipc_msg_print, 0, 0 },
{ "ipc_port", db_show_port_id, 0, 0 },
{ "slabinfo", db_show_slab_info, 0, 0 },
+ { "vmstat", db_show_vmstat, 0, 0 },
{ (char *)0, }
};
diff --git a/vm/vm_page.c b/vm/vm_page.c
index 9a7fa275..fa61af85 100644
--- a/vm/vm_page.c
+++ b/vm/vm_page.c
@@ -2086,3 +2086,46 @@ vm_page_wait(void (*continuation)(void))
thread_block((void (*)(void)) 0);
}
}
+
+#if MACH_KDB
+#include <ddb/db_output.h>
+#define PAGES_PER_MB ((1<<20) / PAGE_SIZE)
+void db_show_vmstat(void)
+{
+ integer_t free_count = vm_page_mem_free();
+
+ db_printf("%-20s %10uM\n", "size:",
+ (free_count + vm_page_active_count +
+ vm_page_inactive_count + vm_page_wire_count)
+ / PAGES_PER_MB);
+
+ db_printf("%-20s %10uM\n", "free:",
+ free_count / PAGES_PER_MB);
+ db_printf("%-20s %10uM\n", "active:",
+ vm_page_active_count / PAGES_PER_MB);
+ db_printf("%-20s %10uM\n", "inactive:",
+ vm_page_inactive_count / PAGES_PER_MB);
+ db_printf("%-20s %10uM\n", "wired:",
+ vm_page_wire_count / PAGES_PER_MB);
+
+ db_printf("%-20s %10uM\n", "zero filled:",
+ vm_stat.zero_fill_count / PAGES_PER_MB);
+ db_printf("%-20s %10uM\n", "reactivated:",
+ vm_stat.reactivations / PAGES_PER_MB);
+ db_printf("%-20s %10uM\n", "pageins:",
+ vm_stat.pageins / PAGES_PER_MB);
+ db_printf("%-20s %10uM\n", "pageouts:",
+ vm_stat.pageouts / PAGES_PER_MB);
+ db_printf("%-20s %10uM\n", "page faults:",
+ vm_stat.faults / PAGES_PER_MB);
+ db_printf("%-20s %10uM\n", "cow faults:",
+ vm_stat.cow_faults / PAGES_PER_MB);
+ db_printf("%-20s %10u%\n", "memobj hit ratio:",
+ (vm_stat.hits * 100) / vm_stat.lookups);
+
+ db_printf("%-20s %10u%\n", "cached_memobjs",
+ vm_object_external_count);
+ db_printf("%-20s %10uM\n", "cache",
+ vm_object_external_pages / PAGES_PER_MB);
+}
+#endif /* MACH_KDB */
diff --git a/vm/vm_page.h b/vm/vm_page.h
index 2a0ad2c2..d9af188c 100644
--- a/vm/vm_page.h
+++ b/vm/vm_page.h
@@ -532,4 +532,9 @@ boolean_t vm_page_evict(boolean_t *should_wait);
*/
void vm_page_refill_inactive(void);
+/*
+ * Print vmstat information
+ */
+void db_show_vmstat(void);
+
#endif /* _VM_VM_PAGE_H_ */