zfs: lz4: add optional kmem_alloc support
lz4 port from illumos to Linux added a 16KB per-CPU cache to accommodate for the missing 16KB malloc. FreeBSD supports this size, making the extra cache harmful as it can't share buckets.
This commit is contained in:
parent
3c50616fc1
commit
aebc96831f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=367360
@ -44,7 +44,8 @@ static int LZ4_compressCtx(void *ctx, const char *source, char *dest,
|
||||
static int LZ4_compress64kCtx(void *ctx, const char *source, char *dest,
|
||||
int isize, int osize);
|
||||
|
||||
static kmem_cache_t *lz4_cache;
|
||||
static void *lz4_alloc(int flags);
|
||||
static void lz4_free(void *ctx);
|
||||
|
||||
/*ARGSUSED*/
|
||||
size_t
|
||||
@ -838,8 +839,7 @@ real_LZ4_compress(const char *source, char *dest, int isize, int osize)
|
||||
void *ctx;
|
||||
int result;
|
||||
|
||||
ASSERT(lz4_cache != NULL);
|
||||
ctx = kmem_cache_alloc(lz4_cache, KM_SLEEP);
|
||||
ctx = lz4_alloc(KM_SLEEP);
|
||||
|
||||
/*
|
||||
* out of kernel memory, gently fall through - this will disable
|
||||
@ -855,7 +855,7 @@ real_LZ4_compress(const char *source, char *dest, int isize, int osize)
|
||||
else
|
||||
result = LZ4_compressCtx(ctx, source, dest, isize, osize);
|
||||
|
||||
kmem_cache_free(lz4_cache, ctx);
|
||||
lz4_free(ctx);
|
||||
return (result);
|
||||
}
|
||||
|
||||
@ -1014,6 +1014,23 @@ LZ4_uncompress_unknownOutputSize(const char *source, char *dest, int isize,
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
/*
|
||||
* FreeBSD has 4, 8 and 16 KB malloc zones which can be used here.
|
||||
* Should struct refTables get resized this may need to be revisited, hence
|
||||
* compiler-time asserts.
|
||||
*/
|
||||
_Static_assert(sizeof(struct refTables) <= 16384,
|
||||
"refTables too big for malloc");
|
||||
_Static_assert((sizeof(struct refTables) % 4096) == 0,
|
||||
"refTables not a multiple of page size");
|
||||
#else
|
||||
#define ZFS_LZ4_USE_CACHE
|
||||
#endif
|
||||
|
||||
#ifdef ZFS_LZ4_USE_CACHE
|
||||
static kmem_cache_t *lz4_cache;
|
||||
|
||||
void
|
||||
lz4_init(void)
|
||||
{
|
||||
@ -1029,3 +1046,39 @@ lz4_fini(void)
|
||||
lz4_cache = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void *
|
||||
lz4_alloc(int flags)
|
||||
{
|
||||
ASSERT(lz4_cache != NULL);
|
||||
return (kmem_cache_alloc(lz4_cache, flags));
|
||||
}
|
||||
|
||||
static void
|
||||
lz4_free(void *ctx)
|
||||
{
|
||||
kmem_cache_free(lz4_cache, ctx);
|
||||
}
|
||||
#else
|
||||
void
|
||||
lz4_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
lz4_fini(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void *
|
||||
lz4_alloc(int flags)
|
||||
{
|
||||
return (kmem_alloc(sizeof (struct refTables), flags));
|
||||
}
|
||||
|
||||
static void
|
||||
lz4_free(void *ctx)
|
||||
{
|
||||
kmem_free(ctx, sizeof (struct refTables));
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user