Skip to content

Commit 4c55431

Browse files
TCMalloc Teamcopybara-github
authored andcommitted
Wire up userspace collapse heuristic experiment.
PiperOrigin-RevId: 831061743 Change-Id: Ie4e7374c192d18f5cdccc3bbbd06d3ac3daae3ec
1 parent f1276b9 commit 4c55431

File tree

5 files changed

+17
-47
lines changed

5 files changed

+17
-47
lines changed

tcmalloc/experiment_config.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ namespace tcmalloc {
2323
enum class Experiment : int {
2424
// clang-format off
2525
// go/keep-sorted start
26-
TCMALLOC_COLLAPSE_HEURISTICS, // TODO: b/456564608 - Complete experiment.
27-
TCMALLOC_EXTENDED_PRIORITY_LISTS_V1, // TODO: b/437412600 - Complete experiment.
26+
TCMALLOC_EXTENDED_PRIORITY_LISTS_V1, // TODO: b/437412600 - Complete experiment.
2827
TCMALLOC_RELEASE_FREE_SWAPPED, // TODO: b/438767733 - Complete experiment.
2928
TEST_ONLY_L3_AWARE, // TODO: b/239977380 - Complete experiment.
3029
TEST_ONLY_MM_VCPU, // TODO: b/245776120 - Complete experiment.
@@ -49,7 +48,6 @@ struct ExperimentConfig {
4948
// clang-format off
5049
inline constexpr ExperimentConfig experiments[] = {
5150
// go/keep-sorted start
52-
{Experiment::TCMALLOC_COLLAPSE_HEURISTICS, "TCMALLOC_COLLAPSE_HEURISTICS"},
5351
{Experiment::TCMALLOC_EXTENDED_PRIORITY_LISTS_V1, "TCMALLOC_EXTENDED_PRIORITY_LISTS_V1"},
5452
{Experiment::TCMALLOC_RELEASE_FREE_SWAPPED, "TCMALLOC_RELEASE_FREE_SWAPPED"},
5553
{Experiment::TEST_ONLY_L3_AWARE, "TEST_ONLY_L3_AWARE"},

tcmalloc/parameters.cc

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,8 @@ ABSL_CONST_INIT std::atomic<double>
200200
ABSL_CONST_INIT std::atomic<int64_t> Parameters::profile_sampling_interval_(
201201
kDefaultProfileSamplingInterval);
202202

203-
static std::atomic<bool>& use_userspace_collapse_heuristics_enabled() {
204-
ABSL_CONST_INIT static absl::once_flag flag;
205-
ABSL_CONST_INIT static std::atomic<bool> v{false};
206-
absl::base_internal::LowLevelCallOnce(&flag, [&]() {
207-
if (IsExperimentActive(Experiment::TCMALLOC_COLLAPSE_HEURISTICS)) {
208-
v.store(true, std::memory_order_relaxed);
209-
}
210-
});
211-
return v;
212-
}
203+
ABSL_CONST_INIT std::atomic<bool>
204+
Parameters::use_userspace_collapse_heuristics_(false);
213205

214206
static std::atomic<bool>& release_free_swapped_enabled() {
215207
ABSL_CONST_INIT static absl::once_flag flag;
@@ -255,11 +247,6 @@ bool Parameters::usermode_hugepage_collapse() {
255247
return usermode_hugepage_collapse_enabled_.load(std::memory_order_relaxed);
256248
}
257249

258-
bool Parameters::use_userspace_collapse_heuristics() {
259-
return use_userspace_collapse_heuristics_enabled().load(
260-
std::memory_order_relaxed);
261-
}
262-
263250
bool Parameters::release_free_swapped() {
264251
return release_free_swapped_enabled().load(std::memory_order_relaxed);
265252
}
@@ -286,6 +273,10 @@ int32_t Parameters::max_per_cpu_cache_size() {
286273
return tc_globals.cpu_cache().CacheLimit();
287274
}
288275

276+
bool TCMalloc_Internal_GetUseUserspaceCollapseHeuristics() {
277+
return Parameters::use_userspace_collapse_heuristics();
278+
}
279+
289280
int ABSL_ATTRIBUTE_WEAK default_want_disable_dynamic_slabs();
290281

291282
// TODO(b/271475288): remove the default_want_disable_dynamic_slabs opt-out
@@ -577,13 +568,9 @@ void TCMalloc_Internal_SetReleaseFreeSwapped(bool v) {
577568
v, std::memory_order_relaxed);
578569
}
579570

580-
bool TCMalloc_Internal_GetUseUserspaceCollapseHeuristics() {
581-
return Parameters::use_userspace_collapse_heuristics();
582-
}
583-
584571
void TCMalloc_Internal_SetUseUserspaceCollapseHeuristics(bool v) {
585-
tcmalloc::tcmalloc_internal::use_userspace_collapse_heuristics_enabled()
586-
.store(v, std::memory_order_relaxed);
572+
Parameters::use_userspace_collapse_heuristics_.store(
573+
v, std::memory_order_relaxed);
587574
}
588575

589576
} // extern "C"

tcmalloc/parameters.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ class Parameters {
9999

100100
static bool release_free_swapped();
101101

102-
static bool use_userspace_collapse_heuristics();
102+
static bool use_userspace_collapse_heuristics() {
103+
return use_userspace_collapse_heuristics_.load(std::memory_order_relaxed);
104+
}
103105

104106
static bool release_pages_from_huge_region() {
105107
return release_pages_from_huge_region_.load(std::memory_order_relaxed);
@@ -222,6 +224,7 @@ class Parameters {
222224
static std::atomic<double> per_cpu_caches_dynamic_slab_grow_threshold_;
223225
static std::atomic<double> per_cpu_caches_dynamic_slab_shrink_threshold_;
224226
static std::atomic<bool> usermode_hugepage_collapse_enabled_;
227+
static std::atomic<bool> use_userspace_collapse_heuristics_;
225228
};
226229

227230
} // namespace tcmalloc_internal

tcmalloc/testing/get_stats_test.cc

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ TEST_F(GetStatsTest, Pbtxt) {
133133
} else {
134134
EXPECT_THAT(buf, HasSubstr("release_free_swapped: false"));
135135
}
136-
if (IsExperimentActive(Experiment::TCMALLOC_COLLAPSE_HEURISTICS)) {
137-
EXPECT_THAT(buf, HasSubstr("use_userspace_collapse_heuristics: true"));
138-
} else {
139-
EXPECT_THAT(buf, HasSubstr("use_userspace_collapse_heuristics: false"));
140-
}
136+
EXPECT_THAT(buf, HasSubstr("use_userspace_collapse_heuristics: false"));
141137
if (IsExperimentActive(
142138
Experiment::TEST_ONLY_TCMALLOC_EXTENDED_PRIORITY_LISTS_V1) ||
143139
IsExperimentActive(Experiment::TCMALLOC_EXTENDED_PRIORITY_LISTS_V1)) {
@@ -223,17 +219,9 @@ TEST_F(GetStatsTest, Parameters) {
223219
EXPECT_THAT(buf,
224220
HasSubstr(R"(PARAMETER tcmalloc_release_free_swapped 0)"));
225221
}
226-
if (IsExperimentActive(Experiment::TCMALLOC_COLLAPSE_HEURISTICS)) {
227-
EXPECT_THAT(
228-
buf,
229-
HasSubstr(
230-
R"(PARAMETER tcmalloc_use_userspace_collapse_heuristics 1)"));
231-
} else {
232-
EXPECT_THAT(
233-
buf,
234-
HasSubstr(
235-
R"(PARAMETER tcmalloc_use_userspace_collapse_heuristics 0)"));
236-
}
222+
EXPECT_THAT(
223+
buf,
224+
HasSubstr(R"(PARAMETER tcmalloc_use_userspace_collapse_heuristics 0)"));
237225
if (IsExperimentActive(
238226
Experiment::TEST_ONLY_TCMALLOC_EXTENDED_PRIORITY_LISTS_V1) ||
239227
IsExperimentActive(Experiment::TCMALLOC_EXTENDED_PRIORITY_LISTS_V1)) {

tcmalloc/variants.bzl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,6 @@ test_variants = [
265265
"deps": ["//tcmalloc:common_8k_pages"],
266266
"env": {"BORG_EXPERIMENTS": "TEST_ONLY_TCMALLOC_EXTENDED_PRIORITY_LISTS_V1"},
267267
},
268-
{
269-
"name": "tcmalloc_collapse_heuristics",
270-
"malloc": "//tcmalloc",
271-
"deps": ["//tcmalloc:common_8k_pages"],
272-
"env": {"BORG_EXPERIMENTS": "TCMALLOC_COLLAPSE_HEURISTICS"},
273-
},
274268
{
275269
"name": "tcmalloc_release_free_swapped",
276270
"malloc": "//tcmalloc",

0 commit comments

Comments
 (0)