]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mempool: only enable cpu local storage in crimson
authorYingxin Cheng <yingxin.cheng@intel.com>
Mon, 23 Oct 2023 07:28:05 +0000 (15:28 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Thu, 23 Nov 2023 01:53:06 +0000 (09:53 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/common/mempool.cc
src/include/mempool.h

index 5aa1bda4e54a9184be432110b500546217b561d1..128a3d1a16ccc54d24f51edac2215b4bc294359f 100644 (file)
@@ -15,7 +15,8 @@
 #include "include/mempool.h"
 #include "include/demangle.h"
 
-#ifndef _GNU_SOURCE
+#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
+#else
 // 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;
@@ -97,7 +98,11 @@ size_t mempool::pool_t::allocated_items() const
 
 void mempool::pool_t::adjust_count(ssize_t items, ssize_t bytes)
 {
-#ifndef _GNU_SOURCE
+#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
+  // the expected path: we alway pick the shard for a cpu core
+  // a thread is executing on.
+  const size_t shard_index = pick_a_shard_int();
+#else
   // fallback for lack of sched_getcpu()
   const size_t shard_index = []() {
     if (thread_shard_index == num_shards) {
@@ -105,10 +110,6 @@ void mempool::pool_t::adjust_count(ssize_t items, ssize_t bytes)
     }
     return thread_shard_index;
   }();
-#else
-  // the expected path: we alway pick the shard for a cpu core
-  // a thread is executing on.
-  const size_t shard_index = pick_a_shard_int();
 #endif
   shard[shard_index].items += items;
   shard[shard_index].bytes += bytes;
index 6b633c64d6fc9e9a84e6ea6d629f20f6950dd7ca..1091268e8554b09c51a8118ee3eed98005e1f865 100644 (file)
@@ -26,7 +26,7 @@
 #include <boost/container/flat_set.hpp>
 #include <boost/container/flat_map.hpp>
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
 #  include <sched.h>
 #endif
 
@@ -206,13 +206,7 @@ enum {
 };
 
 static size_t pick_a_shard_int() {
-#ifndef _GNU_SOURCE
-  // 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 >> CEPH_PAGE_SHIFT) & ((1 << num_shard_bits) - 1);
-  return i;
-#else
+#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
   // a thread local storage is actually just an approximation;
   // what we truly want is a _cpu local storage_.
   //
@@ -220,6 +214,12 @@ static size_t pick_a_shard_int() {
   // a syscall-handled-in-userspace (vdso!). it grabs the cpu
   // id kernel exposes to a task on context switch.
   return sched_getcpu() & ((1 << num_shard_bits) - 1);
+#else
+  // 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 >> CEPH_PAGE_SHIFT) & ((1 << num_shard_bits) - 1);
+  return i;
 #endif
 }