summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c2
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h6
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c61
3 files changed, 65 insertions, 4 deletions
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c
index fd0464e..f344f6a 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c
@@ -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();
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h
index 14e5c6a..85b8a99 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h
+++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h
@@ -83,6 +83,12 @@ extern size_t zio_compress_data(enum zio_compress c, void *src, void *dst,
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
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c
index 04eac7b..30994a4 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c
@@ -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, void *src, void *dst, size_t s_len,
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, void *src, void *dst, size_t s_len,
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, void *src, void *dst,
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;
+ }
+}
OpenPOWER on IntegriCloud