Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Aug 2013 19:40:43 +0000 (UTC)
From:      "Justin T. Gibbs" <gibbs@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r254608 - in head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys
Message-ID:  <201308211940.r7LJehIe048484@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gibbs
Date: Wed Aug 21 19:40:43 2013
New Revision: 254608
URL: http://svnweb.freebsd.org/changeset/base/254608

Log:
  Add kstat entries for ZFS compression statistics.
  
  sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h:
  sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c:
  	Add module lifetime functions to allocate and teardown
  	state data.
  
  	Report:
  		- Compression attempts.
  		- Buffers found to be empty.
  		- Compression calls that are skipped because
  		  the data length is already less than or
  		  equal to the minimum block length.
  		- Compression attempts that fail to yield a 12.5%
  		  compression ratio.
  
  sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c:
  	Add calls to the zio_compress.c module's init and fini
  	functions.
  
  Sponosred by:	Spectra Logic Corporation
  MFC after:	2 weeks

Modified:
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c	Wed Aug 21 19:30:07 2013	(r254607)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c	Wed Aug 21 19:40:43 2013	(r254608)
@@ -1832,6 +1832,7 @@ dmu_init(void)
 	dnode_init();
 	dbuf_init();
 	zfetch_init();
+	zio_compress_init();
 	l2arc_init();
 	arc_init();
 }
@@ -1842,6 +1843,7 @@ dmu_fini(void)
 	arc_fini(); /* arc depends on l2arc, so arc must go first */
 	l2arc_fini();
 	zfetch_fini();
+	zio_compress_fini();
 	dbuf_fini();
 	dnode_fini();
 	dmu_objset_fini();

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h	Wed Aug 21 19:30:07 2013	(r254607)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h	Wed Aug 21 19:40:43 2013	(r254608)
@@ -83,6 +83,12 @@ extern size_t zio_compress_data(enum zio
 extern int zio_decompress_data(enum zio_compress c, void *src, void *dst,
     size_t s_len, size_t d_len);
 
+/*
+ * Module lifetime management.
+ */
+extern void zio_compress_init(void);
+extern void zio_compress_fini(void);
+
 #ifdef	__cplusplus
 }
 #endif

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c	Wed Aug 21 19:30:07 2013	(r254607)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c	Wed Aug 21 19:40:43 2013	(r254608)
@@ -33,10 +33,32 @@
 
 #include <sys/zfs_context.h>
 #include <sys/compress.h>
+#include <sys/kstat.h>
 #include <sys/spa.h>
 #include <sys/zio.h>
 #include <sys/zio_compress.h>
 
+typedef struct zcomp_stats {
+	kstat_named_t zcompstat_attempts;
+	kstat_named_t zcompstat_empty;
+	kstat_named_t zcompstat_skipped_minblocksize;
+	kstat_named_t zcompstat_skipped_insufficient_gain;
+} zcomp_stats_t;
+
+static zcomp_stats_t zcomp_stats = {
+	{ "attempts",			KSTAT_DATA_UINT64 },
+	{ "empty",			KSTAT_DATA_UINT64 },
+	{ "skipped_minblocksize",	KSTAT_DATA_UINT64 },
+	{ "skipped_insufficient_gain",	KSTAT_DATA_UINT64 }
+};
+
+#define	ZCOMPSTAT_INCR(stat, val) \
+	atomic_add_64(&zcomp_stats.stat.value.ui64, (val));
+
+#define	ZCOMPSTAT_BUMP(stat)		ZCOMPSTAT_INCR(stat, 1);
+
+kstat_t		*zcomp_ksp;
+
 /*
  * Compression vectors.
  */
@@ -87,6 +109,8 @@ zio_compress_data(enum zio_compress c, v
 	ASSERT((uint_t)c < ZIO_COMPRESS_FUNCTIONS);
 	ASSERT((uint_t)c == ZIO_COMPRESS_EMPTY || ci->ci_compress != NULL);
 
+	ZCOMPSTAT_BUMP(zcompstat_attempts);
+
 	/*
 	 * If the data is all zeroes, we don't even need to allocate
 	 * a block for it.  We indicate this by returning zero size.
@@ -96,21 +120,27 @@ zio_compress_data(enum zio_compress c, v
 		if (*word != 0)
 			break;
 
-	if (word == word_end)
-		return (0);
+	if (word == word_end) {
+		ZCOMPSTAT_BUMP(zcompstat_empty);
+ 		return (0);
+	}
 
 	if (c == ZIO_COMPRESS_EMPTY)
 		return (s_len);
 
 	/* Compress at least 12.5% */
 	d_len = P2ALIGN(s_len - (s_len >> 3), minblocksize);
-	if (d_len == 0)
+	if (d_len == 0) {
+		ZCOMPSTAT_BUMP(zcompstat_skipped_minblocksize);
 		return (s_len);
+	}
 
 	c_len = ci->ci_compress(src, dst, s_len, d_len, ci->ci_level);
 
-	if (c_len > d_len)
+	if (c_len > d_len) {
+		ZCOMPSTAT_BUMP(zcompstat_skipped_insufficient_gain);
 		return (s_len);
+	}
 
 	/*
 	 * Cool.  We compressed at least as much as we were hoping to.
@@ -139,3 +169,26 @@ zio_decompress_data(enum zio_compress c,
 
 	return (ci->ci_decompress(src, dst, s_len, d_len, ci->ci_level));
 }
+
+void
+zio_compress_init(void)
+{
+
+	zcomp_ksp = kstat_create("zfs", 0, "zcompstats", "misc",
+	    KSTAT_TYPE_NAMED, sizeof (zcomp_stats) / sizeof (kstat_named_t),
+	    KSTAT_FLAG_VIRTUAL);
+
+	if (zcomp_ksp != NULL) {
+		zcomp_ksp->ks_data = &zcomp_stats;
+		kstat_install(zcomp_ksp);
+	}
+}
+
+void
+zio_compress_fini(void)
+{
+	if (zcomp_ksp != NULL) {
+		kstat_delete(zcomp_ksp);
+		zcomp_ksp = NULL;
+	}
+}



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