Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Feb 2014 14:50:31 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r262164 - in stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys
Message-ID:  <201402181450.s1IEoV87092723@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Tue Feb 18 14:50:31 2014
New Revision: 262164
URL: http://svnweb.freebsd.org/changeset/base/262164

Log:
  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.

Modified:
  stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lz4.c
  stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c
  stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h
Directory Properties:
  stable/9/   (props changed)
  stable/9/sys/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)

Modified: stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lz4.c
==============================================================================
--- stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lz4.c	Tue Feb 18 14:46:39 2014	(r262163)
+++ stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lz4.c	Tue Feb 18 14:50:31 2014	(r262164)
@@ -44,6 +44,8 @@ static int LZ4_compressCtx(void *ctx, co
 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, ch
 	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 c
 	_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
+}

Modified: stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c
==============================================================================
--- stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c	Tue Feb 18 14:46:39 2014	(r262163)
+++ stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c	Tue Feb 18 14:50:31 2014	(r262164)
@@ -1766,6 +1766,7 @@ spa_init(int mode)
 	unique_init();
 	range_tree_init();
 	zio_init();
+	lz4_init();
 	dmu_init();
 	zil_init();
 	vdev_cache_stat_init();
@@ -1791,6 +1792,7 @@ spa_fini(void)
 	vdev_cache_stat_fini();
 	zil_fini();
 	dmu_fini();
+	lz4_fini();
 	zio_fini();
 	range_tree_fini();
 	unique_fini();

Modified: stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h
==============================================================================
--- stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h	Tue Feb 18 14:46:39 2014	(r262163)
+++ stable/9/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h	Tue Feb 18 14:50:31 2014	(r262164)
@@ -70,6 +70,8 @@ extern size_t zle_compress(void *src, vo
     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,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201402181450.s1IEoV87092723>