Skip to content

Commit 1ac378d

Browse files
committed
mempool: only enable cpu local storage in crimson
Signed-off-by: Yingxin Cheng <[email protected]>
1 parent 8146f83 commit 1ac378d

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/common/mempool.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#include "include/mempool.h"
1616
#include "include/demangle.h"
1717

18-
#ifndef _GNU_SOURCE
18+
#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
19+
#else
1920
// Thread local variables should save index, not &shard[index],
2021
// because shard[] is defined in the class
2122
static thread_local size_t thread_shard_index = mempool::num_shards;
@@ -97,18 +98,18 @@ size_t mempool::pool_t::allocated_items() const
9798

9899
void mempool::pool_t::adjust_count(ssize_t items, ssize_t bytes)
99100
{
100-
#ifndef _GNU_SOURCE
101+
#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
102+
// the expected path: we alway pick the shard for a cpu core
103+
// a thread is executing on.
104+
const size_t shard_index = pick_a_shard_int();
105+
#else
101106
// fallback for lack of sched_getcpu()
102107
const size_t shard_index = []() {
103108
if (thread_shard_index == num_shards) {
104109
thread_shard_index = pick_a_shard_int();
105110
}
106111
return thread_shard_index;
107112
}();
108-
#else
109-
// the expected path: we alway pick the shard for a cpu core
110-
// a thread is executing on.
111-
const size_t shard_index = pick_a_shard_int();
112113
#endif
113114
shard[shard_index].items += items;
114115
shard[shard_index].bytes += bytes;

src/include/mempool.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <boost/container/flat_set.hpp>
2727
#include <boost/container/flat_map.hpp>
2828

29-
#ifdef _GNU_SOURCE
29+
#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
3030
# include <sched.h>
3131
#endif
3232

@@ -206,20 +206,20 @@ enum {
206206
};
207207

208208
static size_t pick_a_shard_int() {
209-
#ifndef _GNU_SOURCE
210-
// Dirt cheap, see:
211-
// https://fossies.org/dox/glibc-2.32/pthread__self_8c_source.html
212-
size_t me = (size_t)pthread_self();
213-
size_t i = (me >> CEPH_PAGE_SHIFT) & ((1 << num_shard_bits) - 1);
214-
return i;
215-
#else
209+
#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
216210
// a thread local storage is actually just an approximation;
217211
// what we truly want is a _cpu local storage_.
218212
//
219213
// on the architectures we care about sched_getcpu() is
220214
// a syscall-handled-in-userspace (vdso!). it grabs the cpu
221215
// id kernel exposes to a task on context switch.
222216
return sched_getcpu() & ((1 << num_shard_bits) - 1);
217+
#else
218+
// Dirt cheap, see:
219+
// https://fossies.org/dox/glibc-2.32/pthread__self_8c_source.html
220+
size_t me = (size_t)pthread_self();
221+
size_t i = (me >> CEPH_PAGE_SHIFT) & ((1 << num_shard_bits) - 1);
222+
return i;
223223
#endif
224224
}
225225

0 commit comments

Comments
 (0)