Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 May 2017 13:19:07 +0000 (UTC)
From:      Allan Jude <allanjude@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r318449 - in stable/11: contrib/top usr.bin/top
Message-ID:  <201705181319.v4IDJ74T029775@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: allanjude
Date: Thu May 18 13:19:07 2017
New Revision: 318449
URL: https://svnweb.freebsd.org/changeset/base/318449

Log:
  MFC r315435:
  	Add ZFS compressed ARC stats to top(1)
  
  MFC r316314:
  	top(1) read the wrong amount of data from sysctl
  
  MFC r318448:
  	Explain the new fields in top(1) related to ZFS compressed ARC
  
  Remove the laundry field during the merge, does not exist in stable/11

Modified:
  stable/11/contrib/top/display.c
  stable/11/contrib/top/display.h
  stable/11/contrib/top/layout.h
  stable/11/contrib/top/machine.h
  stable/11/contrib/top/top.c
  stable/11/usr.bin/top/machine.c
  stable/11/usr.bin/top/top.local.1
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/contrib/top/display.c
==============================================================================
--- stable/11/contrib/top/display.c	Thu May 18 12:55:07 2017	(r318448)
+++ stable/11/contrib/top/display.c	Thu May 18 13:19:07 2017	(r318449)
@@ -69,6 +69,7 @@ static char **procstate_names;
 static char **cpustate_names;
 static char **memory_names;
 static char **arc_names;
+static char **carc_names;
 static char **swap_names;
 
 static int num_procstates;
@@ -105,6 +106,8 @@ int  x_mem =		5;
 int  y_mem =		3;
 int  x_arc =		5;
 int  y_arc =		4;
+int  x_carc =		5;
+int  y_carc =		5;
 int  x_swap =		6;
 int  y_swap =		4;
 int  y_message =	5;
@@ -222,6 +225,7 @@ struct statics *statics;
 	lmemory = (int *)malloc(num_memory * sizeof(int));
 
 	arc_names = statics->arc_names;
+	carc_names = statics->carc_names;
 	
 	/* calculate starting columns where needed */
 	cpustate_total_length = 0;
@@ -684,6 +688,47 @@ int *stats;
     line_update(arc_buffer, new, x_arc, y_arc);
 }
 
+
+/*
+ *  *_carc(stats) - print "Compressed ARC: " followed by the summary string
+ *
+ *  Assumptions:  cursor is on "lastline"
+ *                for i_carc ONLY: cursor is on the previous line
+ */
+char carc_buffer[MAX_COLS];
+
+void
+i_carc(stats)
+
+int *stats;
+
+{
+    if (carc_names == NULL)
+	return;
+
+    fputs("\n     ", stdout);
+    lastline++;
+
+    /* format and print the memory summary */
+    summary_format(carc_buffer, stats, carc_names);
+    fputs(carc_buffer, stdout);
+}
+
+void
+u_carc(stats)
+
+int *stats;
+
+{
+    static char new[MAX_COLS];
+
+    if (carc_names == NULL)
+	return;
+
+    /* format the new line */
+    summary_format(new, stats, carc_names);
+    line_update(carc_buffer, new, x_carc, y_carc);
+}
  
 /*
  *  *_swap(stats) - print "Swap: " followed by the swap summary string
@@ -1174,6 +1219,7 @@ register char **names;
     register int num;
     register char *thisname;
     register int useM = No;
+    char rbuf[6];
 
     /* format each number followed by its string */
     p = str;
@@ -1194,6 +1240,14 @@ register char **names;
 		/* skip over the K, since it was included by format_k */
 		p = strecpy(p, thisname+1);
 	    }
+	    /* is this number a ratio? */
+	    else if (thisname[0] == ':')
+	    {
+		(void) snprintf(rbuf, sizeof(rbuf), "%.2f", 
+		    (float)*(numbers - 2) / (float)num);
+		p = strecpy(p, rbuf);
+		p = strecpy(p, thisname);
+	    }
 	    else
 	    {
 		p = strecpy(p, itoa(num));

Modified: stable/11/contrib/top/display.h
==============================================================================
--- stable/11/contrib/top/display.h	Thu May 18 12:55:07 2017	(r318448)
+++ stable/11/contrib/top/display.h	Thu May 18 13:19:07 2017	(r318449)
@@ -16,6 +16,7 @@ char	*cpustates_tag(void);
 void	 display_header(int t);
 int		 display_init(struct statics *statics);
 void	 i_arc(int *stats);
+void	 i_carc(int *stats);
 void	 i_cpustates(int *states);
 void	 i_loadave(int mpid, double *avenrun);
 void	 i_memory(int *stats);
@@ -29,6 +30,7 @@ void	 new_message();
 int		 readline(char *buffer, int size, int numeric);
 char	*trim_header(char *text);
 void	 u_arc(int *stats);
+void	 u_carc(int *stats);
 void	 u_cpustates(int *states);
 void	 u_endscreen(int hi);
 void	 u_header(char *text);

Modified: stable/11/contrib/top/layout.h
==============================================================================
--- stable/11/contrib/top/layout.h	Thu May 18 12:55:07 2017	(r318448)
+++ stable/11/contrib/top/layout.h	Thu May 18 13:19:07 2017	(r318449)
@@ -21,6 +21,8 @@ extern int  x_mem;		/* 5 */
 extern int  y_mem;		/* 3 */
 extern int  x_arc;		/* 5 */
 extern int  y_arc;		/* 4 */
+extern int  x_carc;		/* 5 */
+extern int  y_carc;		/* 5 */
 extern int  x_swap;		/* 6 */
 extern int  y_swap;		/* 4 */
 extern int  y_message;		/* 5 */

Modified: stable/11/contrib/top/machine.h
==============================================================================
--- stable/11/contrib/top/machine.h	Thu May 18 12:55:07 2017	(r318448)
+++ stable/11/contrib/top/machine.h	Thu May 18 13:19:07 2017	(r318449)
@@ -21,6 +21,7 @@ struct statics
     char **cpustate_names;
     char **memory_names;
     char **arc_names;
+    char **carc_names;
     char **swap_names;
 #ifdef ORDER
     char **order_names;
@@ -48,6 +49,7 @@ struct system_info
     int    *cpustates;
     int    *memory;
     int    *arc;
+    int    *carc;
     int    *swap;
     struct timeval boottime;
     int    ncpus;

Modified: stable/11/contrib/top/top.c
==============================================================================
--- stable/11/contrib/top/top.c	Thu May 18 12:55:07 2017	(r318448)
+++ stable/11/contrib/top/top.c	Thu May 18 13:19:07 2017	(r318449)
@@ -125,6 +125,7 @@ void (*d_procstates)() = i_procstates;
 void (*d_cpustates)() = i_cpustates;
 void (*d_memory)() = i_memory;
 void (*d_arc)() = i_arc;
+void (*d_carc)() = i_carc;
 void (*d_swap)() = i_swap;
 void (*d_message)() = i_message;
 void (*d_header)() = i_header;
@@ -658,6 +659,7 @@ restart:
 	/* display memory stats */
 	(*d_memory)(system_info.memory);
 	(*d_arc)(system_info.arc);
+	(*d_carc)(system_info.carc);
 
 	/* display swap stats */
 	(*d_swap)(system_info.swap);
@@ -724,6 +726,7 @@ restart:
 		    d_cpustates = u_cpustates;
 		    d_memory = u_memory;
 		    d_arc = u_arc;
+		    d_carc = u_carc;
 		    d_swap = u_swap;
 		    d_message = u_message;
 		    d_header = u_header;
@@ -1190,6 +1193,7 @@ reset_display()
     d_cpustates  = i_cpustates;
     d_memory     = i_memory;
     d_arc        = i_arc;
+    d_carc       = i_carc;
     d_swap       = i_swap;
     d_message	 = i_message;
     d_header	 = i_header;

Modified: stable/11/usr.bin/top/machine.c
==============================================================================
--- stable/11/usr.bin/top/machine.c	Thu May 18 12:55:07 2017	(r318448)
+++ stable/11/usr.bin/top/machine.c	Thu May 18 13:19:07 2017	(r318449)
@@ -188,6 +188,12 @@ char *arcnames[] = {
 	NULL
 };
 
+int carc_stats[5];
+char *carcnames[] = {
+	"K Compressed, ", "K Uncompressed, ", ":1 Ratio, ", "K Overhead",
+	NULL
+};
+
 int swap_stats[7];
 char *swapnames[] = {
 	"K Total, ", "K Used, ", "K Free, ", "% Inuse, ", "K In, ", "K Out",
@@ -223,6 +229,7 @@ static long total_majflt;
 /* these are for getting the memory statistics */
 
 static int arc_enabled;
+static int carc_enabled;
 static int pageshift;		/* log base 2 of the pagesize */
 
 /* define pagetok in terms of pageshift */
@@ -283,16 +290,18 @@ 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;
+	y_carc = 5;
+	y_swap = 4 + arc_enabled + carc_enabled;
+	y_idlecursor = 5 + arc_enabled + carc_enabled;
+	y_message = 5 + arc_enabled + carc_enabled;
+	y_header = 6 + arc_enabled + carc_enabled;
+	y_procs = 7 + arc_enabled + carc_enabled;
+	Header_lines = 7 + arc_enabled + carc_enabled;
 
 	if (pcpu_stats) {
 		y_mem += ncpus - 1;
 		y_arc += ncpus - 1;
+		y_carc += ncpus - 1;
 		y_swap += ncpus - 1;
 		y_idlecursor += ncpus - 1;
 		y_message += ncpus - 1;
@@ -307,6 +316,7 @@ machine_init(struct statics *statics, ch
 {
 	int i, j, empty, pagesize;
 	uint64_t arc_size;
+	boolean_t carc_en;
 	size_t size;
 	struct passwd *pw;
 
@@ -318,6 +328,10 @@ machine_init(struct statics *statics, ch
 	    size != sizeof(smpmode))
 		smpmode = 0;
 
+	size = sizeof(carc_en);
+	if (sysctlbyname("vfs.zfs.compressed_arc_enabled", &carc_en, &size,
+	    NULL, 0) == 0 && carc_en == 1)
+		carc_enabled = 1;
 	size = sizeof(arc_size);
 	if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arc_size, &size,
 	    NULL, 0) == 0 && arc_size != 0)
@@ -368,6 +382,10 @@ machine_init(struct statics *statics, ch
 		statics->arc_names = arcnames;
 	else
 		statics->arc_names = NULL;
+	if (carc_enabled)
+		statics->carc_names = carcnames;
+	else
+		statics->carc_names = NULL;
 	statics->swap_names = swapnames;
 #ifdef ORDER
 	statics->order_names = ordernames;
@@ -559,6 +577,16 @@ get_system_info(struct system_info *si)
 		arc_stats[5] = arc_stat >> 10;
 		si->arc = arc_stats;
 	}
+	if (carc_enabled) {
+		GETSYSCTL("kstat.zfs.misc.arcstats.compressed_size", arc_stat);
+		carc_stats[0] = arc_stat >> 10;
+		GETSYSCTL("kstat.zfs.misc.arcstats.uncompressed_size", arc_stat);
+		carc_stats[1] = arc_stat >> 10;
+		carc_stats[2] = arc_stats[0]; /* ARC Total */
+		GETSYSCTL("kstat.zfs.misc.arcstats.overhead_size", arc_stat);
+		carc_stats[3] = arc_stat >> 10;
+		si->carc = carc_stats;
+	}
 
 	/* set arrays and strings */
 	if (pcpu_stats) {

Modified: stable/11/usr.bin/top/top.local.1
==============================================================================
--- stable/11/usr.bin/top/top.local.1	Thu May 18 12:55:07 2017	(r318448)
+++ stable/11/usr.bin/top/top.local.1	Thu May 18 13:19:07 2017	(r318449)
@@ -2,9 +2,10 @@
 .SH "FreeBSD NOTES"
 
 .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
+Mem: 61M Active, 86M Inact, 22G Wired, 1M Cache, 2M Buf, 102G Free
+ARC: 15G Total, 9303M MFU, 6155M MRU, 1464K Anon, 98M Header, 35M Other
+     15G Compressed, 27G Uncompressed, 1.75:1 Ratio, 174M Overhead
+Swap: 4096M Total, 532M Free, 13% Inuse, 80K In, 104K Out
 .TP
 .B K:
 Kilobyte
@@ -55,8 +56,20 @@ number of ARC bytes holding in flight da
 .B Header:
 number of ARC bytes holding headers
 .TP
-.B Other
+.B Other:
 miscellaneous ARC bytes
+.TP
+.B Compressed:
+bytes of memory used by ARC caches
+.TP
+.B Uncompressed:
+bytes of data stored in ARC caches before compression
+.TP
+.B Ratio:
+ratio of uncompressed data to total ARC size
+.TP
+.B Overhead:
+amount of overhead from ARC compression
 .SS Swap Stats
 .TP
 .B Total:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705181319.v4IDJ74T029775>