4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
30 #ifndef _SYS_RANGE_TREE_H
31 #define _SYS_RANGE_TREE_H
40 #define RANGE_TREE_HISTOGRAM_SIZE 64
42 typedef struct range_tree_ops range_tree_ops_t
;
45 * Note: the range_tree may not be accessed concurrently; consumers
46 * must provide external locking if required.
48 typedef struct range_tree
{
49 avl_tree_t rt_root
; /* offset-ordered segment AVL tree */
50 uint64_t rt_space
; /* sum of all segments in the map */
51 range_tree_ops_t
*rt_ops
;
55 * The rt_histogram maintains a histogram of ranges. Each bucket,
56 * rt_histogram[i], contains the number of ranges whose size is:
57 * 2^i <= size of range in bytes < 2^(i+1)
59 uint64_t rt_histogram
[RANGE_TREE_HISTOGRAM_SIZE
];
62 typedef struct range_seg
{
63 avl_node_t rs_node
; /* AVL node */
64 avl_node_t rs_pp_node
; /* AVL picker-private node */
65 uint64_t rs_start
; /* starting offset of this segment */
66 uint64_t rs_end
; /* ending offset (non-inclusive) */
69 struct range_tree_ops
{
70 void (*rtop_create
)(range_tree_t
*rt
, void *arg
);
71 void (*rtop_destroy
)(range_tree_t
*rt
, void *arg
);
72 void (*rtop_add
)(range_tree_t
*rt
, range_seg_t
*rs
, void *arg
);
73 void (*rtop_remove
)(range_tree_t
*rt
, range_seg_t
*rs
, void *arg
);
74 void (*rtop_vacate
)(range_tree_t
*rt
, void *arg
);
77 typedef void range_tree_func_t(void *arg
, uint64_t start
, uint64_t size
);
79 void range_tree_init(void);
80 void range_tree_fini(void);
81 range_tree_t
*range_tree_create(range_tree_ops_t
*ops
, void *arg
);
82 void range_tree_destroy(range_tree_t
*rt
);
83 boolean_t
range_tree_contains(range_tree_t
*rt
, uint64_t start
, uint64_t size
);
84 uint64_t range_tree_space(range_tree_t
*rt
);
85 void range_tree_verify(range_tree_t
*rt
, uint64_t start
, uint64_t size
);
86 void range_tree_swap(range_tree_t
**rtsrc
, range_tree_t
**rtdst
);
87 void range_tree_stat_verify(range_tree_t
*rt
);
89 void range_tree_add(void *arg
, uint64_t start
, uint64_t size
);
90 void range_tree_remove(void *arg
, uint64_t start
, uint64_t size
);
91 void range_tree_clear(range_tree_t
*rt
, uint64_t start
, uint64_t size
);
93 void range_tree_vacate(range_tree_t
*rt
, range_tree_func_t
*func
, void *arg
);
94 void range_tree_walk(range_tree_t
*rt
, range_tree_func_t
*func
, void *arg
);
100 #endif /* _SYS_RANGE_TREE_H */