+ /*
+ * Add in memory requirements of higher-level indirects.
+ * This assumes a worst-possible scenario for dn_nlevels and a
+ * worst-possible distribution of l1-blocks over the region to free.
+ */
+ {
+ uint64_t blkcnt = 1 + ((l0span >> epbs) >> epbs);
+ int level = 2;
+ /*
+ * Here we don't use DN_MAX_LEVEL, but calculate it with the
+ * given datablkshift and indblkshift. This makes the
+ * difference between 19 and 8 on large files.
+ */
+ int maxlevel = 2 + (DN_MAX_OFFSET_SHIFT - dn->dn_datablkshift) /
+ (dn->dn_indblkshift - SPA_BLKPTRSHIFT);
+
+ while (level++ < maxlevel) {
+ txh->txh_memory_tohold += MAX(MIN(blkcnt, nl1blks), 1)
+ << dn->dn_indblkshift;
+ blkcnt = 1 + (blkcnt >> epbs);
+ }
+ }
+