1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-17 15:27:36 +00:00

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.

Reviewed by:	Saso Kiselkov <skiselkov.ml@gmail.com>
This commit is contained in:
Alexander Motin 2013-11-14 15:54:54 +00:00
parent 3d271aaab0
commit e5056f9882
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=258137
3 changed files with 28 additions and 2 deletions

View File

@ -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
}

View File

@ -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();

View File

@ -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,