From b174694493a893a24166f557592d2160eb3e611d Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 11 Oct 2016 18:17:41 -0400 Subject: [PATCH] mempool: make num_shards a power of 2 Signed-off-by: Sage Weil --- src/include/mempool.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/include/mempool.h b/src/include/mempool.h index 8b4c07c7063..522753a933e 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -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 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]; }