MFC r258137:
Introduce allocation cache to store LZ4 compression contexts without kicking VM subsystem twice for every written record. Tests on 24-core system show double reduction of CPU time spent on copying single large well-compressed file. This patch is not really needed on illumos (while not harm either) since their memory allocator by default uses caching for all requests up to 128K.
This commit is contained in:
parent
1bba01828c
commit
fe82b61321
@ -44,6 +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_ctx_cache;
|
||||
|
||||
/*ARGSUSED*/
|
||||
size_t
|
||||
lz4_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
|
||||
@ -840,7 +842,7 @@ static int
|
||||
real_LZ4_compress(const char *source, char *dest, int isize, int osize)
|
||||
{
|
||||
#if HEAPMODE
|
||||
void *ctx = kmem_zalloc(sizeof (struct refTables), KM_NOSLEEP);
|
||||
void *ctx = kmem_cache_alloc(lz4_ctx_cache, KM_NOSLEEP);
|
||||
int result;
|
||||
|
||||
/*
|
||||
@ -850,12 +852,13 @@ real_LZ4_compress(const char *source, char *dest, int isize, int osize)
|
||||
if (ctx == NULL)
|
||||
return (0);
|
||||
|
||||
bzero(ctx, sizeof(struct refTables));
|
||||
if (isize < LZ4_64KLIMIT)
|
||||
result = LZ4_compress64kCtx(ctx, source, dest, isize, osize);
|
||||
else
|
||||
result = LZ4_compressCtx(ctx, source, dest, isize, osize);
|
||||
|
||||
kmem_free(ctx, sizeof (struct refTables));
|
||||
kmem_cache_free(lz4_ctx_cache, ctx);
|
||||
return (result);
|
||||
#else
|
||||
if (isize < (int)LZ4_64KLIMIT)
|
||||
@ -1001,3 +1004,22 @@ LZ4_uncompress_unknownOutputSize(const char *source, char *dest, int isize,
|
||||
_output_error:
|
||||
return (int)(-(((char *)ip) - source));
|
||||
}
|
||||
|
||||
extern void
|
||||
lz4_init(void)
|
||||
{
|
||||
|
||||
#if HEAPMODE
|
||||
lz4_ctx_cache = kmem_cache_create("lz4_ctx", sizeof(struct refTables),
|
||||
0, NULL, NULL, NULL, NULL, NULL, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void
|
||||
lz4_fini(void)
|
||||
{
|
||||
|
||||
#if HEAPMODE
|
||||
kmem_cache_destroy(lz4_ctx_cache);
|
||||
#endif
|
||||
}
|
||||
|
@ -1739,6 +1739,7 @@ spa_init(int mode)
|
||||
unique_init();
|
||||
space_map_init();
|
||||
zio_init();
|
||||
lz4_init();
|
||||
dmu_init();
|
||||
zil_init();
|
||||
vdev_cache_stat_init();
|
||||
@ -1764,6 +1765,7 @@ spa_fini(void)
|
||||
vdev_cache_stat_fini();
|
||||
zil_fini();
|
||||
dmu_fini();
|
||||
lz4_fini();
|
||||
zio_fini();
|
||||
space_map_fini();
|
||||
unique_fini();
|
||||
|
@ -70,6 +70,8 @@ extern size_t zle_compress(void *src, void *dst, size_t s_len, size_t d_len,
|
||||
int level);
|
||||
extern int zle_decompress(void *src, void *dst, size_t s_len, size_t d_len,
|
||||
int level);
|
||||
extern void lz4_init(void);
|
||||
extern void lz4_fini(void);
|
||||
extern size_t lz4_compress(void *src, void *dst, size_t s_len, size_t d_len,
|
||||
int level);
|
||||
extern int lz4_decompress(void *src, void *dst, size_t s_len, size_t d_len,
|
||||
|
Loading…
Reference in New Issue
Block a user