Skip to content

Commit

Permalink
Change crush_ln to provide 32 more digits.
Browse files Browse the repository at this point in the history
32 more digits(more precision) were given by crush_ln, so we dont
 need to do left shift in bucket_straw2_choose now.

This change will slightly improve the quality of distribution.

expect                  169.664
osd     weight  count   adjusted
0       1       179     179
1       1.75    291     166
2       3.062   507     165
3       5.359   937     174
4       9.379   1581    168
5       16.41   2771    168
6       28.72   4847    168
7       50.27   8690    172
8       87.96   14924   169
9       153.9   26069   169
10      269.4   45706   169
11      471.4   79754   169
12      825     139847  169
13      1444    245707  170
14      2527    428190  169
std dev 12.4895
     vs 12.6005 (expected)

Signed-off-by: Xiaoxi Chen <[email protected]>
  • Loading branch information
xiaoxichen819 authored and liewegas committed Jan 22, 2015
1 parent 6289912 commit 35fcb04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/crush/crush_ln_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#define CEPH_CRUSH_LN_H


// RH_LH_tbl[2*k] = 2^48/(1.0+k/128.0)
// RH_LH_tbl[2*k+1] = 2^48*log2(1.0+k/128.0)

static int64_t __RH_LH_tbl[128*2+2] = {
0x0001000000000000ll, 0x0000000000000000ll, 0x0000fe03f80fe040ll, 0x000002dfca16dde1ll,
0x0000fc0fc0fc0fc1ll, 0x000005b9e5a170b4ll, 0x0000fa232cf25214ll, 0x0000088e68ea899all,
Expand Down
21 changes: 11 additions & 10 deletions src/crush/mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ static int bucket_straw_choose(struct crush_bucket_straw *bucket,
return bucket->h.items[high];
}

// compute 2^12*log2(input+1)
unsigned crush_ln(unsigned xin)
// compute 2^44*log2(input+1)
uint64_t crush_ln(unsigned xin)
{
unsigned x=xin, x1, result;
unsigned x=xin, x1;
int iexpon, index1, index2;
uint64_t RH, LH, LL, xl64;
uint64_t RH, LH, LL, xl64, result;

x++;

Expand All @@ -277,16 +277,17 @@ unsigned crush_ln(unsigned xin)
xl64 >>= 48;
x1 = xl64;

result = iexpon << 12;
result = iexpon;
result <<= (12 + 32);

index2 = x1 & 0xff;
// LL ~ 2^48*log2(1.0+index2/2^15)
LL = __LL_tbl[index2];

LH = LH + LL;

LH >>= (48-12);
result += (unsigned)LH;
LH >>= (48-12 - 32);
result += LH;

return result;
}
Expand Down Expand Up @@ -319,15 +320,15 @@ static int bucket_straw2_choose(struct crush_bucket_straw2 *bucket,
*
* the natural log lookup table maps [0,0xffff]
* (corresponding to real numbers [1/0x10000, 1] to
* [0, 0xffff] (corresponding to real numbers
* [0, 0xffffffffffff] (corresponding to real numbers
* [-11.090355,0]).
*/
ln = crush_ln(u) - 0x10000;
ln = crush_ln(u) - 0x1000000000000ll;

/*
* divide by 16.16 fixed-point weight
*/
draw = (ln << 32) / bucket->item_weights[i];
draw = ln / bucket->item_weights[i];

if (i == 0 || draw > high_draw) {
high = i;
Expand Down

0 comments on commit 35fcb04

Please sign in to comment.