From 8bf73688df7c46a542d4cf22215447ea0ac3fb85 Mon Sep 17 00:00:00 2001 From: jhb Date: Mon, 27 Aug 2012 19:55:31 +0000 Subject: [PATCH] MFC 237646,237656,238020: - Add a new line to top that provides a brief summary of the ZFS ARC memory usage on hosts using ZFS. The new line displays the total amount of RAM used by the ARC along with the size of MFU, MRU, anonymous (in flight), headers, and other (miscellaneous) sub-categories. The line is not displayed on systems that are not using ZFS. - Clarify that the cached file data pages included in the "Wired" count in top are the BIO-level cached data (i.e. "Buf"), since the previous phrase was a bit ambiguous with the "Cache" count. git-svn-id: svn://svn.freebsd.org/base/stable/8@239751 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- contrib/top/display.c | 45 ++++++++++++++++++++++ contrib/top/layout.h | 2 + contrib/top/machine.h | 2 + contrib/top/top.c | 6 +++ usr.bin/top/machine.c | 84 ++++++++++++++++++++++++++++++----------- usr.bin/top/top.local.1 | 25 +++++++++++- 6 files changed, 142 insertions(+), 22 deletions(-) diff --git a/contrib/top/display.c b/contrib/top/display.c index 89795c05e..e65ae24f5 100644 --- a/contrib/top/display.c +++ b/contrib/top/display.c @@ -66,6 +66,7 @@ char *screenbuf = NULL; static char **procstate_names; static char **cpustate_names; static char **memory_names; +static char **arc_names; static char **swap_names; static int num_procstates; @@ -100,6 +101,8 @@ int x_brkdn = 15; int y_brkdn = 1; int x_mem = 5; int y_mem = 3; +int x_arc = 5; +int y_arc = 4; int x_swap = 6; int y_swap = 4; int y_message = 5; @@ -216,6 +219,8 @@ struct statics *statics; num_memory = string_count(memory_names); lmemory = (int *)malloc(num_memory * sizeof(int)); + arc_names = statics->arc_names; + /* calculate starting columns where needed */ cpustate_total_length = 0; pp = cpustate_names; @@ -626,6 +631,46 @@ int *stats; line_update(memory_buffer, new, x_mem, y_mem); } +/* + * *_arc(stats) - print "ARC: " followed by the ARC summary string + * + * Assumptions: cursor is on "lastline" + * for i_arc ONLY: cursor is on the previous line + */ +char arc_buffer[MAX_COLS]; + +i_arc(stats) + +int *stats; + +{ + if (arc_names == NULL) + return (0); + + fputs("\nARC: ", stdout); + lastline++; + + /* format and print the memory summary */ + summary_format(arc_buffer, stats, arc_names); + fputs(arc_buffer, stdout); +} + +u_arc(stats) + +int *stats; + +{ + static char new[MAX_COLS]; + + if (arc_names == NULL) + return (0); + + /* format the new line */ + summary_format(new, stats, arc_names); + line_update(arc_buffer, new, x_arc, y_arc); +} + + /* * *_swap(stats) - print "Swap: " followed by the swap summary string * diff --git a/contrib/top/layout.h b/contrib/top/layout.h index 1b2564e0a..a04fce215 100644 --- a/contrib/top/layout.h +++ b/contrib/top/layout.h @@ -19,6 +19,8 @@ extern int x_brkdn; /* 15 */ extern int y_brkdn; /* 1 */ extern int x_mem; /* 5 */ extern int y_mem; /* 3 */ +extern int x_arc; /* 5 */ +extern int y_arc; /* 4 */ extern int x_swap; /* 6 */ extern int y_swap; /* 4 */ extern int y_message; /* 5 */ diff --git a/contrib/top/machine.h b/contrib/top/machine.h index 3e1af1609..699c7554d 100644 --- a/contrib/top/machine.h +++ b/contrib/top/machine.h @@ -16,6 +16,7 @@ struct statics char **procstate_names; char **cpustate_names; char **memory_names; + char **arc_names; char **swap_names; #ifdef ORDER char **order_names; @@ -42,6 +43,7 @@ struct system_info int *procstates; int *cpustates; int *memory; + int *arc; int *swap; struct timeval boottime; int ncpus; diff --git a/contrib/top/top.c b/contrib/top/top.c index 7086dd6f9..963051b58 100644 --- a/contrib/top/top.c +++ b/contrib/top/top.c @@ -121,6 +121,8 @@ int i_cpustates(); int u_cpustates(); int i_memory(); int u_memory(); +int i_arc(); +int u_arc(); int i_swap(); int u_swap(); int i_message(); @@ -135,6 +137,7 @@ int (*d_loadave)() = i_loadave; int (*d_procstates)() = i_procstates; int (*d_cpustates)() = i_cpustates; int (*d_memory)() = i_memory; +int (*d_arc)() = i_arc; int (*d_swap)() = i_swap; int (*d_message)() = i_message; int (*d_header)() = i_header; @@ -647,6 +650,7 @@ restart: /* display memory stats */ (*d_memory)(system_info.memory); + (*d_arc)(system_info.arc); /* display swap stats */ (*d_swap)(system_info.swap); @@ -712,6 +716,7 @@ restart: d_procstates = u_procstates; d_cpustates = u_cpustates; d_memory = u_memory; + d_arc = u_arc; d_swap = u_swap; d_message = u_message; d_header = u_header; @@ -1129,6 +1134,7 @@ reset_display() d_procstates = i_procstates; d_cpustates = i_cpustates; d_memory = i_memory; + d_arc = i_arc; d_swap = i_swap; d_message = i_message; d_header = i_header; diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index c7f43bf06..66f47f4d8 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -176,6 +176,12 @@ char *memorynames[] = { "K Free", NULL }; +int arc_stats[7]; +char *arcnames[] = { + "K Total, ", "K MRU, ", "K MFU, ", "K Anon, ", "K Header, ", "K Other", + NULL +}; + int swap_stats[7]; char *swapnames[] = { "K Total, ", "K Used, ", "K Free, ", "% Inuse, ", "K In, ", "K Out", @@ -194,6 +200,7 @@ static struct kinfo_proc *previous_procs; static struct kinfo_proc **previous_pref; static int previous_proc_count = 0; static int previous_proc_count_max = 0; +static int arc_enabled; /* total number of io operations */ static long total_inblock; @@ -238,6 +245,7 @@ static int compare_pid(const void *a, const void *b); static const char *format_nice(const struct kinfo_proc *pp); static void getsysctl(const char *name, void *ptr, size_t len); static int swapmode(int *retavail, int *retfree); +static void update_layout(void); void toggle_pcpustats(void) @@ -245,24 +253,32 @@ toggle_pcpustats(void) if (ncpus == 1) return; + update_layout(); +} + +/* Adjust display based on ncpus and the ARC state. */ +static void +update_layout(void) +{ + + y_mem = 3; + y_arc = 4; + y_swap = 4 + arc_enabled; + y_idlecursor = 5 + arc_enabled; + y_message = 5 + arc_enabled; + y_header = 6 + arc_enabled; + y_procs = 7 + arc_enabled; + Header_lines = 7 + arc_enabled; - /* Adjust display based on ncpus */ if (pcpu_stats) { - y_mem += ncpus - 1; /* 3 */ - y_swap += ncpus - 1; /* 4 */ - y_idlecursor += ncpus - 1; /* 5 */ - y_message += ncpus - 1; /* 5 */ - y_header += ncpus - 1; /* 6 */ - y_procs += ncpus - 1; /* 7 */ - Header_lines += ncpus - 1; /* 7 */ - } else { - y_mem = 3; - y_swap = 4; - y_idlecursor = 5; - y_message = 5; - y_header = 6; - y_procs = 7; - Header_lines = 7; + y_mem += ncpus - 1; + y_arc += ncpus - 1; + y_swap += ncpus - 1; + y_idlecursor += ncpus - 1; + y_message += ncpus - 1; + y_header += ncpus - 1; + y_procs += ncpus - 1; + Header_lines += ncpus - 1; } } @@ -270,6 +286,7 @@ int machine_init(struct statics *statics, char do_unames) { int i, j, empty, pagesize; + uint64_t arc_size; size_t size; struct passwd *pw; @@ -281,6 +298,11 @@ machine_init(struct statics *statics, char do_unames) size != sizeof(smpmode)) smpmode = 0; + size = sizeof(arc_size); + if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arc_size, &size, + NULL, 0) == 0 && arc_size != 0) + arc_enabled = 1; + if (do_unames) { while ((pw = getpwent()) != NULL) { if (strlen(pw->pw_name) > namelength) @@ -321,6 +343,10 @@ machine_init(struct statics *statics, char do_unames) statics->procstate_names = procstatenames; statics->cpustate_names = cpustatenames; statics->memory_names = memorynames; + if (arc_enabled) + statics->arc_names = arcnames; + else + statics->arc_names = NULL; statics->swap_names = swapnames; #ifdef ORDER statics->order_names = ordernames; @@ -355,8 +381,7 @@ machine_init(struct statics *statics, char do_unames) pcpu_cpu_states = calloc(1, size); statics->ncpus = ncpus; - if (pcpu_stats) - toggle_pcpustats(); + update_layout(); /* all done! */ return (0); @@ -407,7 +432,7 @@ get_system_info(struct system_info *si) struct loadavg sysload; int mib[2]; struct timeval boottime; - size_t bt_size; + uint64_t arc_stat, arc_stat2; int i, j; size_t size; @@ -486,6 +511,23 @@ get_system_info(struct system_info *si) swap_stats[6] = -1; } + if (arc_enabled) { + GETSYSCTL("kstat.zfs.misc.arcstats.size", arc_stat); + arc_stats[0] = arc_stat >> 10; + GETSYSCTL("vfs.zfs.mfu_size", arc_stat); + arc_stats[1] = arc_stat >> 10; + GETSYSCTL("vfs.zfs.mru_size", arc_stat); + arc_stats[2] = arc_stat >> 10; + GETSYSCTL("vfs.zfs.anon_size", arc_stat); + arc_stats[3] = arc_stat >> 10; + GETSYSCTL("kstat.zfs.misc.arcstats.hdr_size", arc_stat); + GETSYSCTL("kstat.zfs.misc.arcstats.l2_hdr_size", arc_stat2); + arc_stats[4] = arc_stat + arc_stat2 >> 10; + GETSYSCTL("kstat.zfs.misc.arcstats.other_size", arc_stat); + arc_stats[5] = arc_stat >> 10; + si->arc = arc_stats; + } + /* set arrays and strings */ if (pcpu_stats) { si->cpustates = pcpu_cpu_states; @@ -510,8 +552,8 @@ get_system_info(struct system_info *si) */ mib[0] = CTL_KERN; mib[1] = KERN_BOOTTIME; - bt_size = sizeof(boottime); - if (sysctl(mib, 2, &boottime, &bt_size, NULL, 0) != -1 && + size = sizeof(boottime); + if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0) { si->boottime = boottime; } else { diff --git a/usr.bin/top/top.local.1 b/usr.bin/top/top.local.1 index 015b969b7..4602a9dff 100644 --- a/usr.bin/top/top.local.1 +++ b/usr.bin/top/top.local.1 @@ -3,6 +3,7 @@ .SH DESCRIPTION OF MEMORY Mem: 9220K Active, 1M Inact, 3284K Wired, 1M Cache, 2M Buf, 1320K Free +ARC: 2048K Total, 342K MRU, 760K MFU, 272K Anon, 232K Header, 442K Other Swap: 91M Total, 79M Free, 13% Inuse, 80K In, 104K Out .TP .B K: @@ -16,6 +17,7 @@ Gigabyte .TP .B %: 1/100 +.SS Physical Memory Stats .TP .B Active: number of bytes active @@ -24,7 +26,7 @@ number of bytes active number of bytes inactive .TP .B Wired: -number of bytes wired down, including cached file data pages +number of bytes wired down, including BIO-level cached file data pages .TP .B Cache: number of clean bytes caching data that are available for @@ -35,8 +37,29 @@ number of bytes used for BIO-level disk caching .TP .B Free: number of bytes free +.SS ZFS ARC Stats +These stats are only displayed when the ARC is in use. .TP .B Total: +number of wired bytes used for the ZFS ARC +.TP +.B MRU: +number of ARC bytes holding most recently used data +.TP +.B MFU: +number of ARC bytes holding most frequently used data +.TP +.B Anon: +number of ARC bytes holding in flight data +.TP +.B Header: +number of ARC bytes holding headers +.TP +.B Other +miscellaneous ARC bytes +.SS Swap Stats +.TP +.B Total: total available swap usage .TP .B Free: -- 2.45.0