Skip to content

Commit 3e01aa2

Browse files
TCMalloc Teamcopybara-github
authored andcommitted
Roll back arbitrary transfer cache.
PiperOrigin-RevId: 319531352 Change-Id: I1695dd1be9b98d4eb7ed1028f79e989e8cb2a6bd
1 parent 893f21b commit 3e01aa2

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

tcmalloc/experiment_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace tcmalloc {
2323
enum class Experiment : int {
2424
TCMALLOC_TEMERAIRE,
2525
TCMALLOC_SANS_56_SIZECLASS,
26+
TCMALLOC_ARBITRARY_TRANSFER_CACHE,
2627
TCMALLOC_LARGE_NUM_TO_MOVE,
2728
TCMALLOC_4K_SIZE_CLASS,
2829
kMaxExperimentID,
@@ -37,6 +38,7 @@ struct ExperimentConfig {
3738
inline constexpr ExperimentConfig experiments[] = {
3839
{Experiment::TCMALLOC_TEMERAIRE, "TCMALLOC_TEMERAIRE"},
3940
{Experiment::TCMALLOC_SANS_56_SIZECLASS, "TCMALLOC_SANS_56_SIZECLASS"},
41+
{Experiment::TCMALLOC_ARBITRARY_TRANSFER_CACHE, "TCMALLOC_ARBITRARY_TRANSFER_CACHE"},
4042
{Experiment::TCMALLOC_LARGE_NUM_TO_MOVE, "TCMALLOC_LARGE_NUM_TO_MOVE"},
4143
{Experiment::TCMALLOC_4K_SIZE_CLASS, "TCMALLOC_4K_SIZE_CLASS"},
4244
};

tcmalloc/transfer_cache.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ void TransferCache::Init(size_t cl) {
6868
// We need at least 2 slots to store list head and tail.
6969
ASSERT(kMinObjectsToMove >= 2);
7070

71+
// Cache this value, for performance.
72+
arbitrary_transfer_ =
73+
IsExperimentActive(Experiment::TCMALLOC_ARBITRARY_TRANSFER_CACHE);
74+
7175
slots_ = nullptr;
7276
max_capacity_ = 0;
7377
SizeInfo info = {0, 0};
@@ -140,6 +144,7 @@ bool TransferCache::ShrinkCache() {
140144
absl::base_internal::SpinLockHolder h(&lock_);
141145
auto info = slot_info_.load(std::memory_order_relaxed);
142146
if (info.capacity == 0) return false;
147+
if (!arbitrary_transfer_ && info.capacity < N) return false;
143148

144149
N = std::min(N, info.capacity);
145150
int unused = info.capacity - info.used;
@@ -181,7 +186,7 @@ void TransferCache::InsertRange(absl::Span<void *> batch, int N) {
181186
tracking::Report(kTCInsertHit, size_class(), 1);
182187
return;
183188
}
184-
} else {
189+
} else if (arbitrary_transfer_) {
185190
absl::base_internal::SpinLockHolder h(&lock_);
186191
MakeCacheSpace(N);
187192
// MakeCacheSpace can drop the lock, so refetch
@@ -220,7 +225,6 @@ void TransferCache::InsertRange(absl::Span<void *> batch, int N) {
220225
}
221226
#endif
222227
}
223-
// We don't need to hold the lock here, so release it earlier.
224228
}
225229
tracking::Report(kTCInsertMiss, size_class(), 1);
226230
freelist().InsertRange(batch.data(), N);
@@ -243,7 +247,7 @@ int TransferCache::RemoveRange(void **batch, int N) {
243247
tracking::Report(kTCRemoveHit, size_class(), 1);
244248
return N;
245249
}
246-
} else if (info.used >= 0) {
250+
} else if (arbitrary_transfer_ && info.used >= 0) {
247251
absl::base_internal::SpinLockHolder h(&lock_);
248252
// Refetch with the lock
249253
info = slot_info_.load(std::memory_order_relaxed);
@@ -255,7 +259,6 @@ int TransferCache::RemoveRange(void **batch, int N) {
255259
memcpy(batch, entry, sizeof(void *) * fetch);
256260
tracking::Report(kTCRemoveHit, size_class(), 1);
257261
if (fetch == N) return N;
258-
// We don't need to hold the lock here, so release it earlier.
259262
}
260263
tracking::Report(kTCRemoveMiss, size_class(), 1);
261264
return freelist().RemoveRange(batch + fetch, N - fetch) + fetch;

tcmalloc/transfer_cache.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class TransferCache {
4747
max_capacity_(0),
4848
slot_info_{},
4949
slots_(nullptr),
50-
freelist_do_not_access_directly_() {}
50+
freelist_do_not_access_directly_(),
51+
arbitrary_transfer_(false) {}
5152
TransferCache(const TransferCache &) = delete;
5253
TransferCache &operator=(const TransferCache &) = delete;
5354

@@ -131,6 +132,9 @@ class TransferCache {
131132
}
132133

133134
CentralFreeList freelist_do_not_access_directly_;
135+
136+
// Cached value of IsExperimentActive(Experiment::TCMALLOC_ARBITRARY_TRANSFER)
137+
bool arbitrary_transfer_;
134138
} ABSL_CACHELINE_ALIGNED;
135139

136140
#else

0 commit comments

Comments
 (0)