From: Xiaoxi Chen Date: Fri, 16 Jan 2015 08:10:17 +0000 (+0800) Subject: Change crush_ln to provide 32 more digits. X-Git-Tag: v0.93~161^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=35fcb04e2945717cf5cfe150b9fa89cb3d2303a1;p=ceph.git Change crush_ln to provide 32 more digits. 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 --- diff --git a/src/crush/crush_ln_table.h b/src/crush/crush_ln_table.h index 5bbdf6e3f40e..80aeeb0ff7b2 100644 --- a/src/crush/crush_ln_table.h +++ b/src/crush/crush_ln_table.h @@ -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, diff --git a/src/crush/mapper.c b/src/crush/mapper.c index c409ca1262ba..b2e0bfd9266f 100644 --- a/src/crush/mapper.c +++ b/src/crush/mapper.c @@ -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++; @@ -277,7 +277,8 @@ 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) @@ -285,8 +286,8 @@ unsigned crush_ln(unsigned xin) LH = LH + LL; - LH >>= (48-12); - result += (unsigned)LH; + LH >>= (48-12 - 32); + result += LH; return result; } @@ -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;