]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/mempool.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / common / mempool.cc
index e4ab5d4a10ad17aec05754ae236e07b77211a5ff..79354f70821617737d06beeaacaabe4a58bafb95 100644 (file)
@@ -15,6 +15,9 @@
 #include "include/mempool.h"
 #include "include/demangle.h"
 
+// Thread local variables should save index, not &shard[index],
+// because shard[] is defined in the class
+static thread_local size_t thread_shard_index = mempool::num_shards;
 
 // default to debug_mode off
 bool mempool::debug_mode = false;
@@ -92,9 +95,9 @@ size_t mempool::pool_t::allocated_items() const
 
 void mempool::pool_t::adjust_count(ssize_t items, ssize_t bytes)
 {
-  shard_t *shard = pick_a_shard();
-  shard->items += items;
-  shard->bytes += bytes;
+  thread_shard_index = (thread_shard_index == num_shards) ? pick_a_shard_int() : thread_shard_index;
+  shard[thread_shard_index].items += items;
+  shard[thread_shard_index].bytes += bytes;
 }
 
 void mempool::pool_t::get_stats(