aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2020-10-31 19:07:32 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2020-10-31 19:07:32 +0000
commit4a58b4ab28f6b60086f93a35f3a1901c701d0454 (patch)
treee4f767c01d686e01c30cbf61af6e1c1b75c02362 /sys
parent7afa1a753ede68f5be972a710abfa61c2029a24c (diff)
downloadsrc-4a58b4ab28f6b60086f93a35f3a1901c701d0454.tar.gz
src-4a58b4ab28f6b60086f93a35f3a1901c701d0454.zip
zfs: zstd: track allocator statistics
This applies: commit c4ede65bdfca11b532403620bbf0d6e33f0c1c1d Author: Mateusz Guzik <mjguzik@gmail.com> Date: Fri Oct 30 23:26:10 2020 +0100 zstd: track allocator statistics Note that this only tracks sizes as requested by the caller. Actual allocated space will almost always be bigger (e.g., rounded up to the next power of 2 or page size). Additionally the allocated buffer may be holding other areas hostage. Nonetheless, this is a starting point for tracking memory usage in zstd. from openzfs
Notes
Notes: svn path=/head/; revision=367229
Diffstat (limited to 'sys')
-rw-r--r--sys/contrib/openzfs/include/sys/zstd/zstd.h6
-rw-r--r--sys/contrib/openzfs/module/zstd/zfs_zstd.c15
2 files changed, 15 insertions, 6 deletions
diff --git a/sys/contrib/openzfs/include/sys/zstd/zstd.h b/sys/contrib/openzfs/include/sys/zstd/zstd.h
index e42e44c236ab..8fe4a24828a5 100644
--- a/sys/contrib/openzfs/include/sys/zstd/zstd.h
+++ b/sys/contrib/openzfs/include/sys/zstd/zstd.h
@@ -75,9 +75,11 @@ typedef struct zfs_zstd_header {
* kstat helper macros
*/
#define ZSTDSTAT(stat) (zstd_stats.stat.value.ui64)
-#define ZSTDSTAT_INCR(stat, val) \
+#define ZSTDSTAT_ADD(stat, val) \
atomic_add_64(&zstd_stats.stat.value.ui64, (val))
-#define ZSTDSTAT_BUMP(stat) ZSTDSTAT_INCR(stat, 1)
+#define ZSTDSTAT_SUB(stat, val) \
+ atomic_sub_64(&zstd_stats.stat.value.ui64, (val))
+#define ZSTDSTAT_BUMP(stat) ZSTDSTAT_ADD(stat, 1)
/* (de)init for user space / kernel emulation */
int zstd_init(void);
diff --git a/sys/contrib/openzfs/module/zstd/zfs_zstd.c b/sys/contrib/openzfs/module/zstd/zfs_zstd.c
index 34c56b7a7fdf..5c896478f970 100644
--- a/sys/contrib/openzfs/module/zstd/zfs_zstd.c
+++ b/sys/contrib/openzfs/module/zstd/zfs_zstd.c
@@ -62,6 +62,8 @@ typedef struct zstd_stats {
kstat_named_t zstd_stat_dec_header_inval;
kstat_named_t zstd_stat_com_fail;
kstat_named_t zstd_stat_dec_fail;
+ kstat_named_t zstd_stat_buffers;
+ kstat_named_t zstd_stat_size;
} zstd_stats_t;
static zstd_stats_t zstd_stats = {
@@ -74,6 +76,8 @@ static zstd_stats_t zstd_stats = {
{ "decompress_header_invalid", KSTAT_DATA_UINT64 },
{ "compress_failed", KSTAT_DATA_UINT64 },
{ "decompress_failed", KSTAT_DATA_UINT64 },
+ { "buffers", KSTAT_DATA_UINT64 },
+ { "size", KSTAT_DATA_UINT64 },
};
/* Enums describing the allocator type specified by kmem_type in zstd_kmem */
@@ -248,6 +252,8 @@ zstd_mempool_alloc(struct zstd_pool *zstd_mempool, size_t size)
/* Free memory if unused object older than 2 minutes */
if (pool->mem && gethrestime_sec() > pool->timeout) {
vmem_free(pool->mem, pool->size);
+ ZSTDSTAT_SUB(zstd_stat_buffers, 1);
+ ZSTDSTAT_SUB(zstd_stat_size, pool->size);
pool->mem = NULL;
pool->size = 0;
pool->timeout = 0;
@@ -275,12 +281,13 @@ zstd_mempool_alloc(struct zstd_pool *zstd_mempool, size_t size)
/* Object is free, try to allocate new one */
if (!pool->mem) {
mem = vmem_alloc(size, KM_SLEEP);
- pool->mem = mem;
-
- if (pool->mem) {
+ if (mem) {
+ ZSTDSTAT_ADD(zstd_stat_buffers, 1);
+ ZSTDSTAT_ADD(zstd_stat_size, size);
+ pool->mem = mem;
+ pool->size = size;
/* Keep track for later release */
mem->pool = pool;
- pool->size = size;
mem->kmem_type = ZSTD_KMEM_POOL;
mem->kmem_size = size;
}