diff options
author | Sebastian Gottschall <[email protected]> | 2020-09-30 22:22:34 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2020-09-30 13:22:34 -0700 |
commit | 8a171ccd9258c9528af413562b5bd6b994cf9c2e (patch) | |
tree | 9d1c0c93409f18190bcbfa9747e490ccc832eba5 /module/zstd/zfs_zstd.c | |
parent | c0bd2e0fe206791242d467b6f84789bf08c3a118 (diff) |
do a cyclic seek for unused memory objects in pool
In non regular use cases allocated memory might stay persistent in memory
pool. This small patch checks every minute if there are old objects which
can be released from memory pool.
Right now with regular use, the pool is checked for old objects on each
allocation attempt from this pool. so basically polling by its use. Now
consider what happens if someone writes a lot of files and stops use of
the volume or even unmounts it. So the code will no longer check if
objects can be released from the pool. Already allocated objects will
still stay in pool cache. this is no big issue for common use. But
someone discovered this issue while doing tests. personally i know this
behavior and I'm aware of it. Its no big issue. just a enhancement
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Kjeld Schouten-Lebbing <[email protected]>
Signed-off-by: Sebastian Gottschall <[email protected]>
Closes #10938
Closes #10969
Diffstat (limited to 'module/zstd/zfs_zstd.c')
-rw-r--r-- | module/zstd/zfs_zstd.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/module/zstd/zfs_zstd.c b/module/zstd/zfs_zstd.c index c10b7a84d..34c56b7a7 100644 --- a/module/zstd/zfs_zstd.c +++ b/module/zstd/zfs_zstd.c @@ -238,7 +238,7 @@ zstd_mempool_alloc(struct zstd_pool *zstd_mempool, size_t size) * Check if objects fits the size, if so we take it and * update the timestamp. */ - if (!mem && pool->mem && size <= pool->size) { + if (size && !mem && pool->mem && size <= pool->size) { pool->timeout = gethrestime_sec() + ZSTD_POOL_TIMEOUT; mem = pool->mem; @@ -257,7 +257,7 @@ zstd_mempool_alloc(struct zstd_pool *zstd_mempool, size_t size) } } - if (mem) { + if (!size || mem) { return (mem); } @@ -688,6 +688,19 @@ zstd_mempool_deinit(void) zstd_mempool_cctx = NULL; } +/* release unused memory from pool */ + +void +zfs_zstd_cache_reap_now(void) +{ + /* + * calling alloc with zero size seeks + * and releases old unused objects + */ + zstd_mempool_alloc(zstd_mempool_cctx, 0); + zstd_mempool_alloc(zstd_mempool_dctx, 0); +} + extern int __init zstd_init(void) { @@ -735,4 +748,5 @@ ZFS_MODULE_VERSION(ZSTD_VERSION_STRING); EXPORT_SYMBOL(zfs_zstd_compress); EXPORT_SYMBOL(zfs_zstd_decompress_level); EXPORT_SYMBOL(zfs_zstd_decompress); +EXPORT_SYMBOL(zfs_zstd_cache_reap_now); #endif |