From: Yingxin Cheng Date: Mon, 23 Oct 2023 07:28:05 +0000 (+0800) Subject: mempool: only enable cpu local storage in crimson X-Git-Tag: v19.3.0~407^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1ac378defc98c4a610a2ce532452cc278248439b;p=ceph.git mempool: only enable cpu local storage in crimson Signed-off-by: Yingxin Cheng --- diff --git a/src/common/mempool.cc b/src/common/mempool.cc index 5aa1bda4e54a..128a3d1a16cc 100644 --- a/src/common/mempool.cc +++ b/src/common/mempool.cc @@ -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; diff --git a/src/include/mempool.h b/src/include/mempool.h index 6b633c64d6fc..1091268e8554 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -26,7 +26,7 @@ #include #include -#ifdef _GNU_SOURCE +#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN) # include #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 }