Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Oct 2019 08:01:41 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org
Subject:   svn commit: r353630 - vendor-sys/illumos/dist/uts/common/fs/zfs vendor-sys/illumos/dist/uts/common/fs/zfs/sys vendor-sys/illumos/dist/uts/common/sys vendor/illumos/dist/lib/libzfs/common vendor/ill...
Message-ID:  <201910160801.x9G81f0e032531@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Wed Oct 16 08:01:36 2019
New Revision: 353630
URL: https://svnweb.freebsd.org/changeset/base/353630

Log:
  10809 Performance optimization of AVL tree comparator functions
  
  illumos/illumos-gate@c4ab0d3f46036e85ad0700125c5a83cc139f55a3
  https://github.com/illumos/illumos-gate/commit/c4ab0d3f46036e85ad0700125c5a83cc139f55a3
  
  https://www.illumos.org/issues/10809
    Port ZoL ee36c709c3d Performance optimization of AVL tree comparator functions
    From the ZoL commit msg:
        perf: 2.75x faster ddt_entry_compare()
        First 256bits of ddt_key_t is a block checksum, which are expected
        to be close to random data. Hence, on average, comparison only needs to
        look at first few bytes of the keys. To reduce number of conditional
        jump instructions, the result is computed as: sign(memcmp(k1, k2)).
  
        Sign of an integer 'a' can be obtained as: `(0 < a) - (a < 0)` := {-1, 0, 1},
        which is computed efficiently.  Synthetic performance evaluation
        of original and new algorithm over 1G random keys on 2.6GHz
        Intel(R) Xeon(R) CPU E5-2660 v3:
        old     6.85789 s
        new     2.49089 s
  
        perf: 2.8x faster vdev_queue_offset_compare() and vdev_queue_timestamp_compare()
            Compute the result directly instead of using conditionals
  
        perf: zfs_range_compare()
            Speedup between 1.1x - 2.5x, depending on compiler version and
            optimization level.
  
        perf: spa_error_entry_compare()
            `bcmp()` is not suitable for comparator use. Use `memcmp()` instead.
  
        perf: 2.8x faster metaslab_compare() and metaslab_rangesize_compare()
        perf: 2.8x faster zil_bp_compare()
  
  Portions contributed by: Jerry Jelinek <jerry.jelinek@joyent.com>
  Author: Gvozden Neskovic <neskovic@gmail.com>

Modified:
  vendor/illumos/dist/lib/libzfs/common/libzfs_dataset.c
  vendor/illumos/dist/lib/libzfs/common/libzfs_iter.c
  vendor/illumos/dist/lib/libzfs/common/libzfs_sendrecv.c
  vendor/illumos/dist/lib/libzpool/common/sys/zfs_context.h

Changes in other areas also in this revision:
Modified:
  vendor-sys/illumos/dist/uts/common/fs/zfs/ddt.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/dnode.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/dsl_deadlist.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/dsl_deleg.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/lz4.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/metaslab.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/range_tree.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/sa.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/spa.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/spa_misc.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/space_reftree.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/sys/zfs_context.h
  vendor-sys/illumos/dist/uts/common/fs/zfs/unique.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/vdev_cache.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/vdev_label.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/vdev_queue.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/zap_micro.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_fuid.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_rlock.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/zil.c
  vendor-sys/illumos/dist/uts/common/sys/avl.h

Modified: vendor/illumos/dist/lib/libzfs/common/libzfs_dataset.c
==============================================================================
--- vendor/illumos/dist/lib/libzfs/common/libzfs_dataset.c	Wed Oct 16 07:57:58 2019	(r353629)
+++ vendor/illumos/dist/lib/libzfs/common/libzfs_dataset.c	Wed Oct 16 08:01:36 2019	(r353630)
@@ -772,15 +772,13 @@ typedef struct mnttab_node {
 static int
 libzfs_mnttab_cache_compare(const void *arg1, const void *arg2)
 {
-	const mnttab_node_t *mtn1 = arg1;
-	const mnttab_node_t *mtn2 = arg2;
+	const mnttab_node_t *mtn1 = (const mnttab_node_t *)arg1;
+	const mnttab_node_t *mtn2 = (const mnttab_node_t *)arg2;
 	int rv;
 
 	rv = strcmp(mtn1->mtn_mt.mnt_special, mtn2->mtn_mt.mnt_special);
 
-	if (rv == 0)
-		return (0);
-	return (rv > 0 ? 1 : -1);
+	return (AVL_ISIGN(rv));
 }
 
 void

Modified: vendor/illumos/dist/lib/libzfs/common/libzfs_iter.c
==============================================================================
--- vendor/illumos/dist/lib/libzfs/common/libzfs_iter.c	Wed Oct 16 07:57:58 2019	(r353629)
+++ vendor/illumos/dist/lib/libzfs/common/libzfs_iter.c	Wed Oct 16 08:01:36 2019	(r353630)
@@ -272,12 +272,7 @@ zfs_snapshot_compare(const void *larg, const void *rar
 	lcreate = zfs_prop_get_int(l, ZFS_PROP_CREATETXG);
 	rcreate = zfs_prop_get_int(r, ZFS_PROP_CREATETXG);
 
-	if (lcreate < rcreate)
-		return (-1);
-	else if (lcreate > rcreate)
-		return (+1);
-	else
-		return (0);
+	return (AVL_CMP(lcreate, rcreate));
 }
 
 int

Modified: vendor/illumos/dist/lib/libzfs/common/libzfs_sendrecv.c
==============================================================================
--- vendor/illumos/dist/lib/libzfs/common/libzfs_sendrecv.c	Wed Oct 16 07:57:58 2019	(r353629)
+++ vendor/illumos/dist/lib/libzfs/common/libzfs_sendrecv.c	Wed Oct 16 08:01:36 2019	(r353630)
@@ -482,15 +482,10 @@ typedef struct fsavl_node {
 static int
 fsavl_compare(const void *arg1, const void *arg2)
 {
-	const fsavl_node_t *fn1 = arg1;
-	const fsavl_node_t *fn2 = arg2;
+	const fsavl_node_t *fn1 = (const fsavl_node_t *)arg1;
+	const fsavl_node_t *fn2 = (const fsavl_node_t *)arg2;
 
-	if (fn1->fn_guid > fn2->fn_guid)
-		return (+1);
-	else if (fn1->fn_guid < fn2->fn_guid)
-		return (-1);
-	else
-		return (0);
+	return (AVL_CMP(fn1->fn_guid, fn2->fn_guid));
 }
 
 /*

Modified: vendor/illumos/dist/lib/libzpool/common/sys/zfs_context.h
==============================================================================
--- vendor/illumos/dist/lib/libzpool/common/sys/zfs_context.h	Wed Oct 16 07:57:58 2019	(r353629)
+++ vendor/illumos/dist/lib/libzpool/common/sys/zfs_context.h	Wed Oct 16 08:01:36 2019	(r353630)
@@ -285,6 +285,14 @@ extern vnode_t *rootdir;
 #define	minclsyspri	60
 #define	maxclsyspri	99
 
+#if (GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__)
+#define	_zfs_expect(expr, value)    (__builtin_expect((expr), (value)))
+#else
+#define	_zfs_expect(expr, value)    (expr)
+#endif
+
+#define	likely(x)	_zfs_expect((x) != 0, 1)
+
 #define	CPU_SEQID	(thr_self() & (max_ncpus - 1))
 
 extern void kernel_init(int);



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