FreeBSD/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/space_reftree.c
/*
 * Space reference trees.
 *
 * A range tree is a collection of integers.  Every integer is either
 * in the tree, or it's not.  A space reference tree generalizes
 * the idea: it allows its members to have arbitrary reference counts,
 * as opposed to the implicit reference count of 0 or 1 in a range tree.
 * This representation comes in handy when computing the union or
 * intersection of multiple space maps.  For example, the union of
 * N range trees is the subset of the reference tree with refcnt >= 1.
 * The intersection of N range trees is the subset with refcnt >= N.
 *
 * [It's very much like a Fourier transform.  Unions and intersections
 * are hard to perform in the 'range tree domain', so we convert the trees
 * into the 'reference count domain', where it's trivial, then invert.]
 *
 * vdev_dtl_reassess() uses computations of this form to determine
 * DTL_MISSING and DTL_OUTAGE for interior vdevs -- e.g. a RAID-Z vdev
 * has an outage wherever refcnt >= vdev_nparity + 1, and a mirror vdev
 * has an outage wherever refcnt >= vdev_children.
 */
Space reference trees.
A range tree is a collection of integers.  Every integer is either
in the tree, or it's not.  A space reference tree generalizes
the idea: it allows its members to have arbitrary reference counts,
as opposed to the implicit reference count of 0 or 1 in a range tree.
This representation comes in handy when computing the union or
intersection of multiple space maps.  For example, the union of
N range trees is the subset of the reference tree with refcnt >= 1.
The intersection of N range trees is the subset with refcnt >= N.

[It's very much like a Fourier transform.

vdev_dtl_reassess() uses computations of this form to determine
DTL_MISSING and DTL_OUTAGE for interior vdevs -- e.g. a RAID-Z vdev
has an outage wherever refcnt >= vdev_nparity + 1, and a mirror vdev
has an outage wherever refcnt >= vdev_children.
Space reference trees . A range tree is a collection of integers . Every integer is either in the tree or it ' s not . A space reference tree generalizes the idea : it allows its members to have arbitrary reference counts as opposed to the implicit reference count of 0 or 1 in a range tree . This representation comes in handy when computing the union or intersection of multiple space maps . For example the union of N range trees is the subset of the reference tree with refcnt > = 1 . The intersection of N range trees is the subset with refcnt > = N . [ It ' s very much like a Fourier transform . vdev_dtl_reassess () uses computations of this form to determine DTL_MISSING and DTL_OUTAGE for interior vdevs -- e . g . a RAID - Z vdev has an outage wherever refcnt > = vdev_nparity + 1 and a mirror vdev has an outage wherever refcnt > = vdev_children .
static int
space_reftree_compare(const void *x1, const void *x2)
{
	const space_ref_t *sr1 = x1;
	const space_ref_t *sr2 = x2;
	if (sr1->sr_offset < sr2->sr_offset)
		return (-1);
	if (sr1->sr_offset > sr2->sr_offset)
		return (1);
	if (sr1 < sr2)
		return (-1);
	if (sr1 > sr2)
		return (1);
	return (0);
}
static int space_reftree_compare ( const void * x1 , const void * x2 ) { const space_ref_t * sr1 = x1 ; const space_ref_t * sr2 = x2 ; if ( sr1 -> sr_offset < sr2 -> sr_offset ) return ( -1 ) ; if ( sr1 -> sr_offset > sr2 -> sr_offset ) return ( 1 ) ; if ( sr1 < sr2 ) return ( -1 ) ; if ( sr1 > sr2 ) return ( 1 ) ; return ( 0 ) ; }
Space reference trees.
Space reference trees .