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
This commit is contained in:
gibbs 2013-08-21 19:40:43 +00:00
parent d8dc6ade5b
commit 785cc185f4
3 changed files with 65 additions and 4 deletions

View File

@ -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();

View File

@ -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

View File

@ -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;
}
}