Print this page
5269 zfs: zpool import slow
While importing a pool all objsets are enumerated twice, once to check
the zil log chains and once to claim them. On pools with many datasets
this process might take a substantial amount of time.
Speed up the process by parallelizing it utilizing a taskq. The number
of parallel tasks is limited to 4 times the number of leaf vdevs.

@@ -170,10 +170,31 @@
                         return (mvd);
 
         return (NULL);
 }
 
+static int
+vdev_count_leaves_impl(vdev_t *vd)
+{
+        vdev_t *mvd;
+        int n = 0;
+
+        if (vd->vdev_children == 0)
+                return (1);
+
+        for (int c = 0; c < vd->vdev_children; c++)
+                n += vdev_count_leaves_impl(vd->vdev_child[c]);
+
+        return (n);
+}
+
+int
+vdev_count_leaves(spa_t *spa)
+{
+        return (vdev_count_leaves_impl(spa->spa_root_vdev));
+}
+
 void
 vdev_add_child(vdev_t *pvd, vdev_t *cvd)
 {
         size_t oldsize, newsize;
         uint64_t id = cvd->vdev_id;