aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ceph/crush/mapper.c
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2009-11-07 23:18:22 -0500
committerSage Weil <sage@newdream.net>2009-11-07 23:18:22 -0500
commitfb690390e305ea51e1883b105c7d3c52d7100ba5 (patch)
treec099a71133225b1d22bba976e93dc6ab92a08986 /fs/ceph/crush/mapper.c
parent1654dd0cf5ee1827322aca156af7d96d757201c7 (diff)
ceph: make CRUSH hash function a bucket property
Make the integer hash function a property of the bucket it is used on. This allows us to gracefully add support for new hash functions without starting from scatch. Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/crush/mapper.c')
-rw-r--r--fs/ceph/crush/mapper.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/fs/ceph/crush/mapper.c b/fs/ceph/crush/mapper.c
index 54f3f402af60..2523d448445c 100644
--- a/fs/ceph/crush/mapper.c
+++ b/fs/ceph/crush/mapper.c
@@ -78,7 +78,7 @@ static int bucket_perm_choose(struct crush_bucket *bucket,
78 78
79 /* optimize common r=0 case */ 79 /* optimize common r=0 case */
80 if (pr == 0) { 80 if (pr == 0) {
81 s = crush_hash32_3(x, bucket->id, 0) % 81 s = crush_hash32_3(bucket->hash, x, bucket->id, 0) %
82 bucket->size; 82 bucket->size;
83 bucket->perm[0] = s; 83 bucket->perm[0] = s;
84 bucket->perm_n = 0xffff; /* magic value, see below */ 84 bucket->perm_n = 0xffff; /* magic value, see below */
@@ -103,7 +103,7 @@ static int bucket_perm_choose(struct crush_bucket *bucket,
103 unsigned p = bucket->perm_n; 103 unsigned p = bucket->perm_n;
104 /* no point in swapping the final entry */ 104 /* no point in swapping the final entry */
105 if (p < bucket->size - 1) { 105 if (p < bucket->size - 1) {
106 i = crush_hash32_3(x, bucket->id, p) % 106 i = crush_hash32_3(bucket->hash, x, bucket->id, p) %
107 (bucket->size - p); 107 (bucket->size - p);
108 if (i) { 108 if (i) {
109 unsigned t = bucket->perm[p + i]; 109 unsigned t = bucket->perm[p + i];
@@ -138,8 +138,8 @@ static int bucket_list_choose(struct crush_bucket_list *bucket,
138 int i; 138 int i;
139 139
140 for (i = bucket->h.size-1; i >= 0; i--) { 140 for (i = bucket->h.size-1; i >= 0; i--) {
141 __u64 w = crush_hash32_4(x, bucket->h.items[i], r, 141 __u64 w = crush_hash32_4(bucket->h.hash,x, bucket->h.items[i],
142 bucket->h.id); 142 r, bucket->h.id);
143 w &= 0xffff; 143 w &= 0xffff;
144 dprintk("list_choose i=%d x=%d r=%d item %d weight %x " 144 dprintk("list_choose i=%d x=%d r=%d item %d weight %x "
145 "sw %x rand %llx", 145 "sw %x rand %llx",
@@ -198,7 +198,8 @@ static int bucket_tree_choose(struct crush_bucket_tree *bucket,
198 while (!terminal(n)) { 198 while (!terminal(n)) {
199 /* pick point in [0, w) */ 199 /* pick point in [0, w) */
200 w = bucket->node_weights[n]; 200 w = bucket->node_weights[n];
201 t = (__u64)crush_hash32_4(x, n, r, bucket->h.id) * (__u64)w; 201 t = (__u64)crush_hash32_4(bucket->h.hash, x, n, r,
202 bucket->h.id) * (__u64)w;
202 t = t >> 32; 203 t = t >> 32;
203 204
204 /* descend to the left or right? */ 205 /* descend to the left or right? */
@@ -224,7 +225,7 @@ static int bucket_straw_choose(struct crush_bucket_straw *bucket,
224 __u64 draw; 225 __u64 draw;
225 226
226 for (i = 0; i < bucket->h.size; i++) { 227 for (i = 0; i < bucket->h.size; i++) {
227 draw = crush_hash32_3(x, bucket->h.items[i], r); 228 draw = crush_hash32_3(bucket->h.hash, x, bucket->h.items[i], r);
228 draw &= 0xffff; 229 draw &= 0xffff;
229 draw *= bucket->straws[i]; 230 draw *= bucket->straws[i];
230 if (i == 0 || draw > high_draw) { 231 if (i == 0 || draw > high_draw) {
@@ -267,7 +268,8 @@ static int is_out(struct crush_map *map, __u32 *weight, int item, int x)
267 return 0; 268 return 0;
268 if (weight[item] == 0) 269 if (weight[item] == 0)
269 return 1; 270 return 1;
270 if ((crush_hash32_2(x, item) & 0xffff) < weight[item]) 271 if ((crush_hash32_2(CRUSH_HASH_RJENKINS1, x, item) & 0xffff)
272 < weight[item])
271 return 0; 273 return 0;
272 return 1; 274 return 1;
273} 275}