From 50d07b8da558701731b08895c772e5584ec8f5be Mon Sep 17 00:00:00 2001 From: singuliere Date: Wed, 17 Mar 2021 07:35:04 +0100 Subject: [PATCH] common/mempool: only fail tests if sharding is very bad Fixes: https://tracker.ceph.com/issues/49781 Signed-off-by: singuliere (cherry picked from commit db79769d6d557acc021a434ff285db2d69458d0a) --- src/include/mempool.h | 2 +- src/test/test_mempool.cc | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/include/mempool.h b/src/include/mempool.h index 9cee38256ea..68b00e31b82 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -258,7 +258,7 @@ public: // Dirt cheap, see: // https://fossies.org/dox/glibc-2.32/pthread__self_8c_source.html size_t me = (size_t)pthread_self(); - size_t i = (me >> 12) & ((1 << num_shard_bits) - 1); + size_t i = (me >> CEPH_PAGE_SHIFT) & ((1 << num_shard_bits) - 1); return i; } diff --git a/src/test/test_mempool.cc b/src/test/test_mempool.cc index 3b575c952ba..6230dcceab8 100644 --- a/src/test/test_mempool.cc +++ b/src/test/test_mempool.cc @@ -385,7 +385,7 @@ TEST(mempool, bufferlist_c_str) TEST(mempool, check_shard_select) { - const size_t samples = 100; + const size_t samples = mempool::num_shards * 100; std::atomic_int shards[mempool::num_shards] = {0}; std::vector workers; for (size_t i = 0; i < samples; i++) { @@ -400,15 +400,16 @@ TEST(mempool, check_shard_select) } workers.clear(); - double EX = (double)samples / (double)mempool::num_shards; - double VarX = 0; + size_t missed = 0; for (size_t i = 0; i < mempool::num_shards; i++) { - VarX += (EX - shards[i]) * (EX - shards[i]); + if (shards[i] == 0) { + missed++; + } } - //random gives VarX below 200 - //when half slots are 0, we get ~300 - //when all samples go into one slot, we get ~9000 - EXPECT_LT(VarX, 200); + + // If more than half of the shards did not get anything, + // the distribution is bad enough to deserve a failure. + EXPECT_LT(missed, mempool::num_shards / 2); } TEST(mempool, btree_map_test) -- 2.47.3