From owner-svn-src-all@freebsd.org Sat Oct 31 19:07:33 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6B7274538E3; Sat, 31 Oct 2020 19:07:33 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CNpb92Jyhz3ZNf; Sat, 31 Oct 2020 19:07:33 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1BA99C175; Sat, 31 Oct 2020 19:07:33 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09VJ7WOh036326; Sat, 31 Oct 2020 19:07:32 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09VJ7WcY036325; Sat, 31 Oct 2020 19:07:32 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202010311907.09VJ7WcY036325@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sat, 31 Oct 2020 19:07:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367229 - in head/sys/contrib/openzfs: include/sys/zstd module/zstd X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys/contrib/openzfs: include/sys/zstd module/zstd X-SVN-Commit-Revision: 367229 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2020 19:07:33 -0000 Author: mjg Date: Sat Oct 31 19:07:32 2020 New Revision: 367229 URL: https://svnweb.freebsd.org/changeset/base/367229 Log: zfs: zstd: track allocator statistics This applies: commit c4ede65bdfca11b532403620bbf0d6e33f0c1c1d Author: Mateusz Guzik 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 Modified: head/sys/contrib/openzfs/include/sys/zstd/zstd.h head/sys/contrib/openzfs/module/zstd/zfs_zstd.c Modified: head/sys/contrib/openzfs/include/sys/zstd/zstd.h ============================================================================== --- head/sys/contrib/openzfs/include/sys/zstd/zstd.h Sat Oct 31 18:42:03 2020 (r367228) +++ head/sys/contrib/openzfs/include/sys/zstd/zstd.h Sat Oct 31 19:07:32 2020 (r367229) @@ -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); Modified: head/sys/contrib/openzfs/module/zstd/zfs_zstd.c ============================================================================== --- head/sys/contrib/openzfs/module/zstd/zfs_zstd.c Sat Oct 31 18:42:03 2020 (r367228) +++ head/sys/contrib/openzfs/module/zstd/zfs_zstd.c Sat Oct 31 19:07:32 2020 (r367229) @@ -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, siz /* 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, siz /* 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; }