svn commit: r314912 - head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs

Andriy Gapon avg at FreeBSD.org
Wed Mar 8 13:48:28 UTC 2017


Author: avg
Date: Wed Mar  8 13:48:26 2017
New Revision: 314912
URL: https://svnweb.freebsd.org/changeset/base/314912

Log:
  MFV r314910: 7843 get_clones_stat() is suboptimal for lots of clones
  
  illumos/illumos-gate at c5bde7273ef861a8dc54cfb9abe48d56062177da
  https://github.com/illumos/illumos-gate/commit/c5bde7273ef861a8dc54cfb9abe48d56062177da
  
  https://www.illumos.org/issues/7843
    get_clones_stat() could be very slow if a snapshot has many (thousands) clones.
    Clone names are added to an nvlist that's created with NV_UNIQUE_NAME.
    So, each time a new name is appended to the list, the whole list is searched
    linearly to see if that name is not already in the list. That results in the
    quadratic complexity.
    That should be easy to fix as we know in advance that we should not get any
    duplicate names, so we can drop NV_UNIQUE_NAME when creating the list.
  
  Reviewed by: Pavel Zakharov <pavel.zakharov at delphix.com>
  Reviewed by: Matthew Ahrens <mahrens at delphix.com>
  Approved by: Dan McDonald <danmcd at omniti.com>
  Author: Andriy Gapon <avg at FreeBSD.org>
  
  MFC after:	1 week
  Sponsored by:	ClusterHQ

Modified:
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_dataset.c
Directory Properties:
  head/sys/cddl/contrib/opensolaris/   (props changed)

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_dataset.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_dataset.c	Wed Mar  8 13:40:24 2017	(r314911)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_dataset.c	Wed Mar  8 13:48:26 2017	(r314912)
@@ -1791,11 +1791,22 @@ get_clones_stat(dsl_dataset_t *ds, nvlis
 	zap_cursor_t zc;
 	zap_attribute_t za;
 	nvlist_t *propval = fnvlist_alloc();
-	nvlist_t *val = fnvlist_alloc();
+	nvlist_t *val;
 
 	ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool));
 
 	/*
+	 * We use nvlist_alloc() instead of fnvlist_alloc() because the
+	 * latter would allocate the list with NV_UNIQUE_NAME flag.
+	 * As a result, every time a clone name is appended to the list
+	 * it would be (linearly) searched for for a duplicate name.
+	 * We already know that all clone names must be unique and we
+	 * want avoid the quadratic complexity of double-checking that
+	 * because we can have a large number of clones.
+	 */
+	VERIFY0(nvlist_alloc(&val, 0, KM_SLEEP));
+
+	/*
 	 * There may be missing entries in ds_next_clones_obj
 	 * due to a bug in a previous version of the code.
 	 * Only trust it if it has the right number of entries.


More information about the svn-src-head mailing list