/*
* Choose based on a random permutation of the bucket.
+ *
+ * We used to use some prime number arithmetic to do this, but it
+ * wasn't very random, and had some other bad behaviors. Instead, we
+ * calculate an actual random permutation of the bucket members.
+ * Since this is expensive, we optimize for the r=0 case, which
+ * captures the vast majority of calls.
*/
static int bucket_perm_choose(struct crush_bucket *bucket,
- int x, int r)
+ int x, int r)
{
unsigned pr = r % bucket->size;
unsigned i, s;
s = crush_hash32_3(x, bucket->id, 0) %
bucket->size;
bucket->perm[0] = s;
- bucket->perm_n = 0xffff;
+ bucket->perm_n = 0xffff; /* magic value, see below */
goto out;
}
}
-/* tree */
+/* (binary) tree */
static int height(int n)
{
int h = 0;