Changeset View
Changeset View
Standalone View
Standalone View
sys/contrib/openzfs/module/zstd/zfs_zstd.c
Show All 35 Lines | |||||
* Copyright (c) 2020, The FreeBSD Foundation [1] | * Copyright (c) 2020, The FreeBSD Foundation [1] | ||||
* | * | ||||
* [1] Portions of this software were developed by Allan Jude | * [1] Portions of this software were developed by Allan Jude | ||||
* under sponsorship from the FreeBSD Foundation. | * under sponsorship from the FreeBSD Foundation. | ||||
*/ | */ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/sysmacros.h> | #include <sys/sysmacros.h> | ||||
#if !defined(_STANDALONE) | |||||
#include <sys/zfs_context.h> | #include <sys/zfs_context.h> | ||||
#include <sys/zio_compress.h> | #include <sys/zio_compress.h> | ||||
freqlabs: Is this order important or can the zio_compress.h include just be pulled out of the `if` and… | |||||
Done Inline ActionsUnsure. I'll try it. imp: Unsure. I'll try it. | |||||
#include <sys/spa.h> | #include <sys/spa.h> | ||||
#else | |||||
#include <sys/zio_compress.h> | |||||
#endif | |||||
#include <sys/zstd/zstd.h> | #include <sys/zstd/zstd.h> | ||||
#define ZSTD_STATIC_LINKING_ONLY | #define ZSTD_STATIC_LINKING_ONLY | ||||
#include "lib/zstd.h" | #include "lib/zstd.h" | ||||
#include "lib/zstd_errors.h" | #include "lib/zstd_errors.h" | ||||
#if !defined(_STANDALONE) | |||||
kstat_t *zstd_ksp = NULL; | kstat_t *zstd_ksp = NULL; | ||||
typedef struct zstd_stats { | typedef struct zstd_stats { | ||||
kstat_named_t zstd_stat_alloc_fail; | kstat_named_t zstd_stat_alloc_fail; | ||||
kstat_named_t zstd_stat_alloc_fallback; | kstat_named_t zstd_stat_alloc_fallback; | ||||
kstat_named_t zstd_stat_com_alloc_fail; | kstat_named_t zstd_stat_com_alloc_fail; | ||||
kstat_named_t zstd_stat_dec_alloc_fail; | kstat_named_t zstd_stat_dec_alloc_fail; | ||||
kstat_named_t zstd_stat_com_inval; | kstat_named_t zstd_stat_com_inval; | ||||
Show All 9 Lines | static zstd_stats_t zstd_stats = { | ||||
{ "compress_alloc_fail", KSTAT_DATA_UINT64 }, | { "compress_alloc_fail", KSTAT_DATA_UINT64 }, | ||||
{ "decompress_alloc_fail", KSTAT_DATA_UINT64 }, | { "decompress_alloc_fail", KSTAT_DATA_UINT64 }, | ||||
{ "compress_level_invalid", KSTAT_DATA_UINT64 }, | { "compress_level_invalid", KSTAT_DATA_UINT64 }, | ||||
{ "decompress_level_invalid", KSTAT_DATA_UINT64 }, | { "decompress_level_invalid", KSTAT_DATA_UINT64 }, | ||||
{ "decompress_header_invalid", KSTAT_DATA_UINT64 }, | { "decompress_header_invalid", KSTAT_DATA_UINT64 }, | ||||
{ "compress_failed", KSTAT_DATA_UINT64 }, | { "compress_failed", KSTAT_DATA_UINT64 }, | ||||
{ "decompress_failed", KSTAT_DATA_UINT64 }, | { "decompress_failed", KSTAT_DATA_UINT64 }, | ||||
}; | }; | ||||
#else | |||||
#undef ZSTDSTAT_BUMP | |||||
Not Done Inline ActionsThis seems like a weird place to do this. freqlabs: This seems like a weird place to do this. | |||||
Done Inline ActionsYea, I didn't want to get into the tangled mess of where it's defined, but that may be a fair bit of feedback. imp: Yea, I didn't want to get into the tangled mess of where it's defined, but that may be a fair… | |||||
#define ZSTDSTAT_BUMP(x) | |||||
#endif | |||||
/* Enums describing the allocator type specified by kmem_type in zstd_kmem */ | /* Enums describing the allocator type specified by kmem_type in zstd_kmem */ | ||||
enum zstd_kmem_type { | enum zstd_kmem_type { | ||||
ZSTD_KMEM_UNKNOWN = 0, | ZSTD_KMEM_UNKNOWN = 0, | ||||
/* Allocation type using kmem_vmalloc */ | /* Allocation type using kmem_vmalloc */ | ||||
ZSTD_KMEM_DEFAULT, | ZSTD_KMEM_DEFAULT, | ||||
/* Pool based allocation using mempool_alloc */ | /* Pool based allocation using mempool_alloc */ | ||||
ZSTD_KMEM_POOL, | ZSTD_KMEM_POOL, | ||||
▲ Show 20 Lines • Show All 604 Lines • ▼ Show 20 Lines | |||||
extern int __init | extern int __init | ||||
zstd_init(void) | zstd_init(void) | ||||
{ | { | ||||
/* Set pool size by using maximum sane thread count * 4 */ | /* Set pool size by using maximum sane thread count * 4 */ | ||||
pool_count = (boot_ncpus * 4); | pool_count = (boot_ncpus * 4); | ||||
zstd_meminit(); | zstd_meminit(); | ||||
#if !defined(_STANDALONE) | |||||
/* Initialize kstat */ | /* Initialize kstat */ | ||||
zstd_ksp = kstat_create("zfs", 0, "zstd", "misc", | zstd_ksp = kstat_create("zfs", 0, "zstd", "misc", | ||||
KSTAT_TYPE_NAMED, sizeof (zstd_stats) / sizeof (kstat_named_t), | KSTAT_TYPE_NAMED, sizeof (zstd_stats) / sizeof (kstat_named_t), | ||||
KSTAT_FLAG_VIRTUAL); | KSTAT_FLAG_VIRTUAL); | ||||
if (zstd_ksp != NULL) { | if (zstd_ksp != NULL) { | ||||
zstd_ksp->ks_data = &zstd_stats; | zstd_ksp->ks_data = &zstd_stats; | ||||
kstat_install(zstd_ksp); | kstat_install(zstd_ksp); | ||||
} | } | ||||
#endif | |||||
return (0); | return (0); | ||||
} | } | ||||
extern void __exit | extern void __exit | ||||
zstd_fini(void) | zstd_fini(void) | ||||
{ | { | ||||
#if !defined(_STANDALONE) | |||||
/* Deinitialize kstat */ | /* Deinitialize kstat */ | ||||
if (zstd_ksp != NULL) { | if (zstd_ksp != NULL) { | ||||
kstat_delete(zstd_ksp); | kstat_delete(zstd_ksp); | ||||
zstd_ksp = NULL; | zstd_ksp = NULL; | ||||
} | } | ||||
#endif | |||||
/* Release fallback memory */ | /* Release fallback memory */ | ||||
vmem_free(zstd_dctx_fallback.mem, zstd_dctx_fallback.mem_size); | vmem_free(zstd_dctx_fallback.mem, zstd_dctx_fallback.mem_size); | ||||
mutex_destroy(&zstd_dctx_fallback.barrier); | mutex_destroy(&zstd_dctx_fallback.barrier); | ||||
/* Deinit memory pool */ | /* Deinit memory pool */ | ||||
zstd_mempool_deinit(); | zstd_mempool_deinit(); | ||||
} | } | ||||
Show All 12 Lines |
Is this order important or can the zio_compress.h include just be pulled out of the if and avoid the else?