]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/mempool: only fail tests if sharding is very bad 39978/head
authorsinguliere <singuliere@autistici.org>
Wed, 17 Mar 2021 06:35:04 +0000 (07:35 +0100)
committersinguliere <singuliere@autistici.org>
Fri, 2 Apr 2021 12:08:34 +0000 (14:08 +0200)
Fixes: https://tracker.ceph.com/issues/49781
Signed-off-by: singuliere <singuliere@autistici.org>
(cherry picked from commit db79769d6d557acc021a434ff285db2d69458d0a)

  Conflicts:
      src/include/mempool.h: 0fcf893e18057400bf9c7acc8471ff7eebc71331
      in master added #include <pthread> in Client.h, making it
      available in the tests. It needs to be added explicitly for octopus.

src/include/mempool.h
src/test/test_mempool.cc

index e9907c8258797f236844f2f81ad7a65fa41fb48c..e53104b177befbd5843cf572b7bec014bd6f758e 100644 (file)
@@ -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;
   }
 
index 99b87d11f265ae85b99e32bbff27e5ded7fc24f1..dfcf0c57ca417584f9692c61886a90eb139ec150 100644 (file)
@@ -22,6 +22,7 @@
 #include "gtest/gtest.h"
 #include "include/btree_map.h"
 #include "include/mempool.h"
+#include <thread>
 
 void check_usage(mempool::pool_index_t ix)
 {
@@ -404,7 +405,7 @@ TEST(mempool, btree_map_test)
 
 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<std::thread> workers;
   for (size_t i = 0; i < samples; i++) {
@@ -419,15 +420,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);
 }