]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mempool: make num_shards a power of 2
authorSage Weil <sage@redhat.com>
Tue, 11 Oct 2016 22:17:41 +0000 (18:17 -0400)
committerSage Weil <sage@redhat.com>
Wed, 2 Nov 2016 17:48:48 +0000 (13:48 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/include/mempool.h

index 8b4c07c70636db0c4e066b59982daaaf98d90b25..522753a933e9ef5c5a569e14ff37245c73ede31e 100644 (file)
@@ -213,7 +213,12 @@ struct list_member_t {
 
 // we shard pool stats across many shard_t's to reduce the amount
 // of cacheline ping pong.
-enum { num_shards = 64 };
+enum {
+  num_shard_bits = 5
+};
+enum {
+  num_shards = 1 << num_shard_bits
+};
 
 struct shard_t {
   std::atomic<size_t> bytes = {0};
@@ -277,7 +282,7 @@ public:
     // Dirt cheap, see:
     //   http://fossies.org/dox/glibc-2.24/pthread__self_8c_source.html
     size_t me = (size_t)pthread_self();
-    size_t i = (me >> 3) % num_shards;
+    size_t i = (me >> 3) & ((1 << num_shard_bits) - 1);
     return &shard[i];
   }