]>
Commit | Line | Data |
---|---|---|
5cd068c2 SW |
1 | #ifndef CEPH_CRUSH_CRUSH_H |
2 | #define CEPH_CRUSH_CRUSH_H | |
5ecc0a0f SW |
3 | |
4 | #include <linux/types.h> | |
5 | ||
6 | /* | |
7 | * CRUSH is a pseudo-random data distribution algorithm that | |
8 | * efficiently distributes input values (typically, data objects) | |
9 | * across a heterogeneous, structured storage cluster. | |
10 | * | |
11 | * The algorithm was originally described in detail in this paper | |
12 | * (although the algorithm has evolved somewhat since then): | |
13 | * | |
14 | * http://www.ssrc.ucsc.edu/Papers/weil-sc06.pdf | |
15 | * | |
16 | * LGPL2 | |
17 | */ | |
18 | ||
19 | ||
20 | #define CRUSH_MAGIC 0x00010000ul /* for detecting algorithm revisions */ | |
21 | ||
5ecc0a0f | 22 | #define CRUSH_MAX_DEPTH 10 /* max crush hierarchy depth */ |
5ecc0a0f SW |
23 | |
24 | ||
9a3b490a ID |
25 | #define CRUSH_ITEM_UNDEF 0x7ffffffe /* undefined result (internal use only) */ |
26 | #define CRUSH_ITEM_NONE 0x7fffffff /* no result */ | |
c6d98a60 | 27 | |
5ecc0a0f SW |
28 | /* |
29 | * CRUSH uses user-defined "rules" to describe how inputs should be | |
30 | * mapped to devices. A rule consists of sequence of steps to perform | |
31 | * to generate the set of output devices. | |
32 | */ | |
33 | struct crush_rule_step { | |
34 | __u32 op; | |
35 | __s32 arg1; | |
36 | __s32 arg2; | |
37 | }; | |
38 | ||
39 | /* step op codes */ | |
40 | enum { | |
41 | CRUSH_RULE_NOOP = 0, | |
42 | CRUSH_RULE_TAKE = 1, /* arg1 = value to start with */ | |
43 | CRUSH_RULE_CHOOSE_FIRSTN = 2, /* arg1 = num items to pick */ | |
44 | /* arg2 = type */ | |
45 | CRUSH_RULE_CHOOSE_INDEP = 3, /* same */ | |
46 | CRUSH_RULE_EMIT = 4, /* no args */ | |
47 | CRUSH_RULE_CHOOSE_LEAF_FIRSTN = 6, | |
48 | CRUSH_RULE_CHOOSE_LEAF_INDEP = 7, | |
be3226ac ID |
49 | |
50 | CRUSH_RULE_SET_CHOOSE_LEAF_TRIES = 9, | |
5ecc0a0f SW |
51 | }; |
52 | ||
53 | /* | |
54 | * for specifying choose num (arg1) relative to the max parameter | |
55 | * passed to do_rule | |
56 | */ | |
57 | #define CRUSH_CHOOSE_N 0 | |
58 | #define CRUSH_CHOOSE_N_MINUS(x) (-(x)) | |
59 | ||
60 | /* | |
61 | * The rule mask is used to describe what the rule is intended for. | |
62 | * Given a ruleset and size of output set, we search through the | |
63 | * rule list for a matching rule_mask. | |
64 | */ | |
65 | struct crush_rule_mask { | |
66 | __u8 ruleset; | |
67 | __u8 type; | |
68 | __u8 min_size; | |
69 | __u8 max_size; | |
70 | }; | |
71 | ||
72 | struct crush_rule { | |
73 | __u32 len; | |
74 | struct crush_rule_mask mask; | |
75 | struct crush_rule_step steps[0]; | |
76 | }; | |
77 | ||
78 | #define crush_rule_size(len) (sizeof(struct crush_rule) + \ | |
79 | (len)*sizeof(struct crush_rule_step)) | |
80 | ||
81 | ||
82 | ||
83 | /* | |
84 | * A bucket is a named container of other items (either devices or | |
85 | * other buckets). Items within a bucket are chosen using one of a | |
86 | * few different algorithms. The table summarizes how the speed of | |
87 | * each option measures up against mapping stability when items are | |
88 | * added or removed. | |
89 | * | |
90 | * Bucket Alg Speed Additions Removals | |
91 | * ------------------------------------------------ | |
92 | * uniform O(1) poor poor | |
93 | * list O(n) optimal poor | |
94 | * tree O(log n) good good | |
95 | * straw O(n) optimal optimal | |
96 | */ | |
97 | enum { | |
98 | CRUSH_BUCKET_UNIFORM = 1, | |
99 | CRUSH_BUCKET_LIST = 2, | |
100 | CRUSH_BUCKET_TREE = 3, | |
101 | CRUSH_BUCKET_STRAW = 4 | |
102 | }; | |
c6cf7263 | 103 | extern const char *crush_bucket_alg_name(int alg); |
5ecc0a0f SW |
104 | |
105 | struct crush_bucket { | |
106 | __s32 id; /* this'll be negative */ | |
107 | __u16 type; /* non-zero; type=0 is reserved for devices */ | |
fb690390 SW |
108 | __u8 alg; /* one of CRUSH_BUCKET_* */ |
109 | __u8 hash; /* which hash function to use, CRUSH_HASH_* */ | |
5ecc0a0f SW |
110 | __u32 weight; /* 16-bit fixed point */ |
111 | __u32 size; /* num items */ | |
112 | __s32 *items; | |
113 | ||
114 | /* | |
115 | * cached random permutation: used for uniform bucket and for | |
116 | * the linear search fallback for the other bucket types. | |
117 | */ | |
118 | __u32 perm_x; /* @x for which *perm is defined */ | |
119 | __u32 perm_n; /* num elements of *perm that are permuted/defined */ | |
120 | __u32 *perm; | |
121 | }; | |
122 | ||
123 | struct crush_bucket_uniform { | |
124 | struct crush_bucket h; | |
125 | __u32 item_weight; /* 16-bit fixed point; all items equally weighted */ | |
126 | }; | |
127 | ||
128 | struct crush_bucket_list { | |
129 | struct crush_bucket h; | |
130 | __u32 *item_weights; /* 16-bit fixed point */ | |
131 | __u32 *sum_weights; /* 16-bit fixed point. element i is sum | |
132 | of weights 0..i, inclusive */ | |
133 | }; | |
134 | ||
135 | struct crush_bucket_tree { | |
136 | struct crush_bucket h; /* note: h.size is _tree_ size, not number of | |
137 | actual items */ | |
138 | __u8 num_nodes; | |
139 | __u32 *node_weights; | |
140 | }; | |
141 | ||
142 | struct crush_bucket_straw { | |
143 | struct crush_bucket h; | |
144 | __u32 *item_weights; /* 16-bit fixed point */ | |
145 | __u32 *straws; /* 16-bit fixed point */ | |
146 | }; | |
147 | ||
148 | ||
149 | ||
150 | /* | |
151 | * CRUSH map includes all buckets, rules, etc. | |
152 | */ | |
153 | struct crush_map { | |
154 | struct crush_bucket **buckets; | |
155 | struct crush_rule **rules; | |
156 | ||
5ecc0a0f SW |
157 | __s32 max_buckets; |
158 | __u32 max_rules; | |
159 | __s32 max_devices; | |
546f04ef SW |
160 | |
161 | /* choose local retries before re-descent */ | |
162 | __u32 choose_local_tries; | |
163 | /* choose local attempts using a fallback permutation before | |
164 | * re-descent */ | |
165 | __u32 choose_local_fallback_tries; | |
166 | /* choose attempts before giving up */ | |
167 | __u32 choose_total_tries; | |
1604f488 JS |
168 | /* attempt chooseleaf inner descent once; on failure retry outer descent */ |
169 | __u32 chooseleaf_descend_once; | |
5ecc0a0f SW |
170 | }; |
171 | ||
172 | ||
173 | /* crush.c */ | |
8b12d47b | 174 | extern int crush_get_bucket_item_weight(const struct crush_bucket *b, int pos); |
5ecc0a0f SW |
175 | extern void crush_destroy_bucket_uniform(struct crush_bucket_uniform *b); |
176 | extern void crush_destroy_bucket_list(struct crush_bucket_list *b); | |
177 | extern void crush_destroy_bucket_tree(struct crush_bucket_tree *b); | |
178 | extern void crush_destroy_bucket_straw(struct crush_bucket_straw *b); | |
179 | extern void crush_destroy_bucket(struct crush_bucket *b); | |
bfb16d7d | 180 | extern void crush_destroy_rule(struct crush_rule *r); |
5ecc0a0f SW |
181 | extern void crush_destroy(struct crush_map *map); |
182 | ||
f671d4cd SW |
183 | static inline int crush_calc_tree_node(int i) |
184 | { | |
185 | return ((i+1) << 1)-1; | |
186 | } | |
187 | ||
5ecc0a0f | 188 | #endif |